Backup Restore
处理所有备份与恢复任务,覆盖四个层面:工作区(项目/数据库/代码)、用户数据(家目录/dotfiles/密钥)、操作系统(全量系统/磁盘镜像/LVM 快照)、阿里云快照(云盘快照/自动策略/跨地域复制/整机镜像)。适用于 RPM 包管理的 Linux 系统(如 Alibaba Cloud Linux)纯命令行环境,使用 yum 包管理器。当用户提到备份、恢复、快照、归档、回滚、克隆、迁移、容灾等任何涉及数据保存或恢复的请求时触发此技能,即使请求看起来很简单也应使用。
Get the complete skill folder, including its scripts and reference files.
When to use this skill
Use Backup Restore when an AI agent needs a reusable SKILL.md workflow for this job: 处理所有备份与恢复任务,覆盖四个层面:工作区(项目/数据库/代码)、用户数据(家目录/dotfiles/密钥)、操作系统(全量系统/磁盘镜像/LVM 快照)、阿里云快照(云盘快照/自动策略/跨地域复制/整机镜像)。适用于 RPM 包管理的 Linux 系统(如 Alibaba Cloud Linux)纯命令行环境,使用 yum 包管理器。当用户提到备份、恢复、快照、归档、回滚、克隆、迁移、容灾等任何涉及数据保存或恢复的请求时触发此技能,即使请求看起来很简单也应使用。
When not to use it
Skip Backup Restore when the task is outside the coding category, or when a more specific skill in this directory already covers the same workflow with clearer triggers.
How to install
Where will you use it?
mkdir -p ~/.claude/skills/backup-restore # Save SKILL.md to ~/.claude/skills/backup-restore/SKILL.md
- Claude Code personal install: place the skill and its bundled files at ~/.claude/skills/backup-restore/SKILL.md. For a shared project, commit the folder at .claude/skills/backup-restore/ instead.
- Current Claude Code detects SKILL.md changes in watched directories during the session. If you just created a top-level skills directory, run /reload-skills. Check that the skill is listed before testing its trigger.
- For Claude chat or Cowork in the Desktop app, manage uploaded skills in Customize > Skills; copying files into a local Claude Code folder is not a Desktop install. Other agents may use different install locations.
Full install guide for Claude, Cursor, and Codex →
Try a starter prompt
After installing the skill, paste this starter prompt into your agent to verify it triggers on a small task.
Use the Backup Restore skill for this task: Use Backup Restore when this documented workflow matches the task. Confirm any required inputs or files before making changes.
What supports this recommendation?
71/100 provisional content score. This measures documentation, practical detail and source signals. It is not a measured task success rate or a security certification.
- Documentation
- 77/100
- Practical detail
- 68/100
- Source evidence
- 63/100
- Source signals
- 72/100
Model compatibility evidence
- claudeuntested
No model-specific signal or recorded compatibility test was found.
- chatgptuntested
No model-specific signal or recorded compatibility test was found.
- geminiuntested
No model-specific signal or recorded compatibility test was found.
- copilotuntested
No model-specific signal or recorded compatibility test was found.
- llamauntested
No model-specific signal or recorded compatibility test was found.
- perplexityuntested
No model-specific signal or recorded compatibility test was found.
- mistraluntested
No model-specific signal or recorded compatibility test was found.
- grokuntested
No model-specific signal or recorded compatibility test was found.
Inferred compatibility is based on content signals. Check the app, its available tools and setup requirements before running a skill.
What this skill does
# 备份与恢复技能
本技能处理**四个层面**的备份与恢复操作。执行前务必先探测环境、识别场景,再选择合适的层面。
> 适用环境:Linux / 纯命令行 / yum 包管理器
---
## 第零步:环境探测
在读取任何 reference 文件之前,先运行以下命令了解当前环境,据此推荐方案:
```bash # 检测是否在阿里云 ECS 上 ECS_ID=$(curl -s --connect-timeout 2 http://100.100.100.200/latest/meta-data/instance-id 2>/dev/null) if [ -n "$ECS_ID" ]; then echo "环境:阿里云 ECS(实例 $ECS_ID)" else echo "环境:非 ECS 或无法访问元数据" fi
# 操作系统信息 cat /etc/os-release | grep -E '^(NAME|VERSION)='
# 是否有 LVM lvs 2>/dev/null && echo "LVM:可用" || echo "LVM:无"
# 磁盘空间与分区 df -h / lsblk ```
根据探测结果:
- 检测到 ECS → 优先推荐阿里云快照方案 - 有 LVM → OS 备份可用 LVM 快照 - 非 ECS 且无 LVM → 推荐 restic 或 tar
---
## 层面说明与包含关系
``` 阿里云快照(云盘块级,平台管理) └── 包含整个磁盘,含以下所有内容
操作系统备份(系统全量文件) └── 包含以下所有内容
用户备份(家目录、dotfiles、个人数据) └── 包含以下内容
工作区备份(项目文件、数据库) ```
> 高层面的备份天然包含低层面的数据。不要推荐冗余的备份组合——如果用户已经做了 OS 备份或阿里云快照,就不需要额外再做用户层或工作区层的备份。
---
## 层面选择
| 层面 | 管理主体 | 范围 | 常用工具 | | -------------------- | ---------- | --------------------------------------------- | ------------------------------------------------- | | **工作区** | 用户 | 项目文件、代码、数据库、工作目录 | `tar`、`rsync`、`mysqldump`、`git bundle` | | **用户** | 用户 | 家目录(`~`)、dotfiles、应用数据、SSH 密钥 | `rsync`、`tar` | | **操作系统** | 用户/root | 完整系统文件、磁盘镜像、系统状态 | `dd`、`restic`、`tar`、LVM 快照 | | **阿里云快照** | 阿里云平台 | 云盘块级快照,独立于 OS,可跨地域 | `aliyun-cli` |
---
## 场景识别与层面决策
在读取参考文件之前,先判断用户的**真实场景**,选择最合适的层面:
**场景一:服务器迁移 / 整机备份** → 选阿里云快照(整机镜像)或 OS 备份,二选一即可 → ECS 环境优先推荐阿里云整机镜像,更可靠且恢复更快
**场景二:系统崩溃防护 / 重大变更前保险** → 阿里云快照(最快,不影响系统运行)或 OS 备份
**场景三:仅保护某个项目 / 数据库** → 工作区备份即可,不必做全量 OS 备份
**场景四:换机器要带走个人配置(dotfiles/密钥)** → 用户备份,轻量且目标明确
**场景五:阿里云云盘快照 / 自动快照策略** → 阿里云快照层,需检测环境并获取用户授权
---
## 快速决策树
``` 用户说"备份 X" │ ├── 迁移服务器 / 整机备份 / 系统级保护 │ ├── 是 ECS?→ references/aliyun-snapshot.md │ └── 非 ECS?→ references/os.md │ ※ 两者都已包含用户和工作区数据,无需叠加 │ ├── X = 某个项目 / 文件夹 / 数据库 / 代码 │ └── → references/workspace.md │ ├── X = 家目录 / dotfiles / SSH 密钥 / 个人配置 │ └── → references/user.md │ ├── X = 整个系统 / 磁盘(非 ECS 或明确要求系统内备份) │ └── → references/os.md │ └── X = 云盘快照 / 阿里云快照 / ECS 平台级备份 └── → references/aliyun-snapshot.md ```
---
## 通用规则(适用于所有层面)
1. **备份前先检查空间** — 估算源数据大小(`du -sh`),检查目标剩余空间(`df -h`),空间不足时警告用户 2. **始终使用带时间戳的命名** — 绝不静默覆盖之前的备份 3. **脚本必须有错误处理** — 所有脚本开头加 `set -euo pipefail`,关键操作用 `trap` 捕获失败 4. **备份后立即验证** — 确认归档文件或快照可读后再宣布成功 5. **未确认备份前不删除源数据** 6. **恢复前发出警告** — 如果目标位置已有数据,明确告知用户将被覆盖 7. **阿里云操作前必须获得用户明确授权**(见 aliyun-snapshot.md) 8. **不推荐冗余备份** — 高层面已包含低层面时,主动告知用户无需重复 9. **密码和密钥不硬编码** — 使用密码文件(`--password-file`)或环境变量,不在脚本中写明文密码 10. **建议用户定期做恢复测试** — 备份完成后提醒用户验证恢复流程
---
## 输出格式
每次备份或恢复操作后,按此格式汇报:
``` [完成] 操作类型:备份 | 恢复 层面:工作区 | 用户 | 操作系统 | 阿里云快照 源路径/资源:/path/to/source 或 云盘 ID 备份位置/快照 ID:/path/to/backup_20240315_143022.tar.gz 或 s-xxxxxxxxxxxx 文件大小/快照容量:234 MB 完成时间:2024-03-15 14:30:22 ```
---
## 参考文件
详细命令和操作流程请读取对应文件:
- **`references/workspace.md`** — 项目文件、代码仓库、数据库、工作目录 - **`references/user.md`** — 家目录、dotfiles、应用设置、SSH/GPG 密钥 - **`references/os.md`** — 完整系统备份、磁盘镜像、LVM 快照、裸机恢复 - **`references/aliyun-snapshot.md`** — 阿里云云盘快照、自动快照策略、跨地域复制、镜像备份
Intended uses
- Use Backup Restore when this documented workflow matches the task.
Implementation notes
- Review the source instructions and adapt inputs before running the workflow.
Try it, then tell us how it went
A copied prompt does not tell us whether the task worked. Report your result after checking the output. We collect your tool and outcome, never your files or prompt.