MCPInstall

backup-strategy

备份策略设计

Installs
92
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/chaterm/terminal-skills --skill backup-strategy
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads backup-strategy automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

备份策略设计

概述

3-2-1 策略、备份验证、保留策略设计技能。

3-2-1 备份策略

核心原则

3 - 至少保留 3 份数据副本
2 - 存储在 2 种不同介质上
1 - 至少 1 份异地存储

扩展 3-2-1-1-0:
3 份副本
2 种介质
1 份异地
1 份离线/不可变
0 个错误(验证通过)

实施示例

# 本地备份(副本 1)
tar -czvf /backup/local/data_$(date +%Y%m%d).tar.gz /data

# NAS 备份(副本 2,不同介质)
rsync -avz /backup/local/ nas:/backup/

# 云备份(副本 3,异地)
aws s3 sync /backup/local/ s3://backup-bucket/

备份类型

完整备份

# 每周完整备份
tar -czvf /backup/full_$(date +%Y%m%d).tar.gz /data

增量备份

# 基于时间戳
tar -czvf /backup/incr_$(date +%Y%m%d).tar.gz \
    --newer-mtime="1 day ago" /data

# 基于快照文件
tar -czvf /backup/incr.tar.gz -g /backup/snapshot.snar /data

差异备份

# 基于完整备份时间
tar -czvf /backup/diff_$(date +%Y%m%d).tar.gz \
    --newer-mtime="$(cat /backup/last_full_date)" /data

保留策略

GFS 策略

# Grandfather-Father-Son
# 日备份:保留 7 天
# 周备份:保留 4 周
# 月备份:保留 12 个月
# 年备份:保留 7 年

#!/bin/bash
BACKUP_DIR="/backup"
DATE=$(date +%Y%m%d)
DOW=$(date +%u)  # 1-7
DOM=$(date +%d)  # 01-31

# 日备份
tar -czvf ${BACKUP_DIR}/daily/backup_${DATE}.tar.gz /data

# 周备份(周日)
if [ "$DOW" -eq 7 ]; then
    cp ${BACKUP_DIR}/daily/backup_${DATE}.tar.gz ${BACKUP_DIR}/weekly/
fi

# 月备份(1号)
if [ "$DOM" -eq "01" ]; then
    cp ${BACKUP_DIR}/daily/backup_${DATE}.tar.gz ${BACKUP_DIR}/monthly/
fi

# 清理
find ${BACKUP_DIR}/daily -mtime +7 -delete
find ${BACKUP_DIR}/weekly -mtime +28 -delete
find ${BACKUP_DIR}/monthly -mtime +365 -delete

滚动保留

#!/bin/bash
# 保留最近 N 个备份
BACKUP_DIR="/backup"
KEEP=10

ls -1t ${BACKUP_DIR}/*.tar.gz | tail -n +$((KEEP+1)) | xargs -r rm

备份验证

完整性检查

# 校验和验证
md5sum backup.tar.gz > backup.md5
md5sum -c backup.md5

# tar 测试
tar -tzvf backup.tar.gz > /dev/null

# gzip 测试
gzip -t backup.tar.gz

恢复测试

#!/bin/bash
# 定期恢复测试
TEST_DIR="/tmp/restore_test"
mkdir -p $TEST_DIR

# 解压测试
tar -xzvf /backup/latest.tar.gz -C $TEST_DIR

# 验证文件数量
ORIG_COUNT=$(find /data -type f | wc -l)
REST_COUNT=$(find $TEST_DIR -type f | wc -l)

if [ "$ORIG_COUNT" -eq "$REST_COUNT" ]; then
    echo "验证通过"
else
    echo "验证失败:文件数量不匹配"
fi

rm -rf $TEST_DIR

常见场景

场景 1:企业备份方案

#!/bin/bash
# 综合备份脚本
CONFIG="/etc/backup/config"
LOG="/var/log/backup.log"

log() { echo "$(date '+%Y-%m-%d %H:%M:%S') $1" >> $LOG; }

# 数据库备份
log "开始数据库备份"
mysqldump --all-databases | gzip > /backup/db_$(date +%Y%m%d).sql.gz

# 文件备份
log "开始文件备份"
tar -czvf /backup/files_$(date +%Y%m%d).tar.gz /data

# 同步到 NAS
log "同步到 NAS"
rsync -avz /backup/ nas:/backup/

# 上传到云
log "上传到云存储"
aws s3 sync /backup/ s3://backup-bucket/

# 验证
log "验证备份"
gzip -t /backup/*.gz

# 清理
log "清理旧备份"
find /backup -mtime +7 -delete

log "备份完成"

场景 2:备份监控

#!/bin/bash
# 检查备份状态
BACKUP_DIR="/backup"
MAX_AGE=86400  # 24小时

LATEST=$(ls -1t ${BACKUP_DIR}/*.tar.gz 2>/dev/null | head -1)

if [ -z "$LATEST" ]; then
    echo "CRITICAL: 无备份文件"
    exit 2
fi

AGE=$(($(date +%s) - $(stat -c %Y "$LATEST")))

if [ $AGE -gt $MAX_AGE ]; then
    echo "WARNING: 备份超过 24 小时"
    exit 1
fi

echo "OK: 最新备份 $(basename $LATEST)"
exit 0

策略对比

策略存储空间恢复速度复杂度
完整高快低
增量低慢高
差异中中中
GFS中中中

最佳实践

1. 自动化备份,避免人工遗漏
2. 定期验证备份可恢复性
3. 加密敏感数据备份
4. 监控备份状态和空间
5. 文档化恢复流程
6. 定期演练恢复过程

FAQ

What does the backup-strategy skill do?

备份策略设计

How do I install backup-strategy?

Run npx skills add https://github.com/chaterm/terminal-skills --skill backup-strategy in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/backup-strategy/ (personal) or .claude/skills/backup-strategy/ (project).

Which AI agents can use backup-strategy?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is backup-strategy safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains backup-strategy?

It is published by chaterm in chaterm/terminal-skills. It has 92 recorded installs.

More from chaterm/terminal-skills

View all →

cron

chaterm/terminal-skills

定时任务管理

1.3K installs

system-admin

chaterm/terminal-skills

Linux system administration and monitoring

DevOps & Cloud561 installs

systemd

chaterm/terminal-skills

Open the skill to read its SKILL.md instructions.

253 installs

network-tools

chaterm/terminal-skills

Open the skill to read its SKILL.md instructions.

217 installs

vpn

chaterm/terminal-skills

Open the skill to read its SKILL.md instructions.

193 installs

ssh

chaterm/terminal-skills

SSH 管理与安全

147 installs

Popular other skills

View category →

hyperframes-cli

heygen-com/hyperframes

The HyperFrames CLI by job - scaffold, check, look at frames, edit the timeline, preview, render locally or in the cloud, publish, project history - plus reading its JSON and recovering from build or render failures.

1.3M installs

triage

mattpocock/skills

Move issues and external PRs through a state machine of triage roles, categorise, verify, grill if needed, and write agent-ready briefs.

1M installs

ask-matt

mattpocock/skills

Ask which skill or flow fits your situation. A router over the skills in this repo.

778.4K installs

to-questionnaire

mattpocock/skills

Turn a decision you can't fully answer into a questionnaire for someone else to fill in.

508.9K installs

wait-what

mattpocock/skills

Stop. That last message did not land: re-pitch it.

459.7K installs

loop-me

mattpocock/skills

Grill me about specs for the workflows I want to build, within this workspace.

447.9K installs