backup-recovery – skill DevOps & Hạ tầng cho agent AI
Triển khai chiến lược sao lưu và khôi phục. Cấu hình rsync, Restic và sao lưu lên cloud. Dùng khi thiết kế giải pháp bảo vệ dữ liệu.
Cài skill backup-recovery bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/backup-recovery-33265.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /backup-recovery – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/backup-recovery-33265.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $backup-recovery – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/backup-recovery-33265.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /backup-recovery – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/backup-recovery-33265.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /backup-recovery – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Backup and Recovery
Implement comprehensive backup and recovery strategies using rsync, Restic, and cloud storage backends. Covers the 3-2-1 rule, automated scheduling, S3/B2 backends, encryption, restore procedures, and verification testing.
When to Use
- Designing a backup strategy for servers, databases, or application data
- Setting up Restic for encrypted, deduplicated backups to local or cloud storage
- Automating backups with systemd timers or cron
- Restoring data after accidental deletion, corruption, or disaster
- Migrating data between environments using backup/restore workflows
- Verifying backup integrity and testing recovery procedures
Prerequisites
rsyncinstalled (included in most Linux distributions)resticinstalled (v0.16+ recommended)- Cloud CLI configured for the backend: AWS CLI for S3,
b2CLI for Backblaze B2 - Sufficient storage at the backup destination (2-3x source size for retention)
- SSH access for remote rsync targets
systemdorcronfor scheduling
The 3-2-1 Backup Rule
- 3 copies of your data (1 primary + 2 backups)
- 2 different storage media or types (e.g., local disk + cloud)
- 1 copy offsite (cloud storage, remote datacenter)
Confirm source/destination paths, retention ownership and recovery targets. A mirror with --delete propagates deletions and is not an independent historical backup; dry-run before destructive sync/prune. Never copy a running PostgreSQL data directory as a consistent backup: use pg_dump or a supported physical backup/snapshot protocol. Run pipelines in Bash with pipefail so failed dumps cannot become apparently successful empty snapshots. Restore to an isolated new database/path first; --clean deletes target objects. Keep repository credentials and recovery keys in a separate approved location; logs and backup data are sensitive.
rsync Backups
Basic Operations
# Sync a local directory to a backup location
rsync -avz --delete /data/ /backup/data/
# Flags explained:
# -a archive mode (preserves permissions, ownership, timestamps, symlinks)
# -v verbose output
# -z compress data during transfer
# --delete remove files at destination that no longer exist at source
# Sync to a remote server over SSH
rsync -avz -e "ssh -i ~/.ssh/backup_key" /data/ backup@remote:/backups/server01/
# Exclude patterns
rsync -avz --delete \
--exclude='*.tmp' \
--exclude='*.log' \
--exclude='.cache/' \
--exclude='node_modules/' \
/data/ /backup/data/
# Use an exclude file for complex patterns
rsync -avz --delete --exclude-from=/etc/backup-excludes.txt /data/ /backup/data/
# Dry run (preview what would change)
rsync -avzn --delete /data/ /backup/data/
# Limit bandwidth to 50 MB/s and show progress
rsync -avz --bwlimit=50000 --progress /data/ backup@remote:/backups/Incremental Backups with Hard Links
# Incremental: unchanged files hard-linked to previous backup (saves space)
rsync -avz --delete \
--link-dest=/backup/daily/latest \
/data/ /backup/daily/$(date +%Y-%m-%d)/
# Update the 'latest' symlink
ln -snf /backup/daily/$(date +%Y-%m-%d) /backup/daily/latest
# Remove backups older than 30 days
find /backup/daily -maxdepth 1 -type d -name "20*" -mtime +30 -exec rm -rf {} \;Restic Backup
Installation
# Debian / Ubuntu
apt install -y restic
# RHEL / CentOS
dnf install -y restic
# Alternatively obtain a pinned release for the actual OS/architecture from
# https://github.com/restic/restic/releases and verify its published checksums
# and signature before installing it. Do not mix latest/ URLs with old filenames.
# Verify installation
restic versionInitialize a Repository
# Local repository
restic init --repo /backup/restic-repo
# AWS S3 backend
export AWS_ACCESS_KEY_ID="AKIAEXAMPLE"
export AWS_SECRET_ACCESS_KEY="secretkey"
restic init --repo s3:s3.amazonaws.com/my-backup-bucket
# S3-compatible (MinIO)
export AWS_ACCESS_KEY_ID="minioadmin"
export AWS_SECRET_ACCESS_KEY="miniosecret"
restic init --repo s3:https://minio.example.com:9000/backup-bucket
# Backblaze B2 backend
export B2_ACCOUNT_ID="accountid"
export B2_ACCOUNT_KEY="accountkey"
restic init --repo b2:my-backup-bucket:server01
# SFTP backend
restic init --repo sftp:backup@remote:/backups/server01
# Restic will prompt for a repository password -- store it securely
# Use a password file for automation
umask 077
read -r -s -p "Repository password: " RESTIC_NEW_PASSWORD
printf '%s\n' "$RESTIC_NEW_PASSWORD" > /etc/restic/password.txt
unset RESTIC_NEW_PASSWORD
chmod 600 /etc/restic/password.txtBackup Operations
# Basic backup
restic backup /data --repo /backup/restic-repo --password-file /etc/restic/password.txt
# Backup multiple directories
restic backup /data /etc \
--repo s3:s3.amazonaws.com/my-backup-bucket \
--password-file /etc/restic/password.txt
# Backup with exclusions
restic backup /data \
--exclude='*.tmp' \
--exclude='*.log' \
--exclude-file=/etc/restic/excludes.txt \
--repo /backup/restic-repo \
--password-file /etc/restic/password.txt
# Backup with tags (useful for filtering snapshots later)
restic backup /data \
--tag server01 --tag production --tag daily \
--repo /backup/restic-repo \
--password-file /etc/restic/password.txt
# Backup stdin (e.g., database dump)
pg_dump -U postgres mydb | restic backup --stdin --stdin-filename mydb.sql \
--repo s3:s3.amazonaws.com/my-backup-bucket \
--password-file /etc/restic/password.txt
# Verbose output showing files processed
restic backup /data -v \
--repo /backup/restic-repo \
--password-file /etc/restic/password.txtSnapshot Management
# List all snapshots (add --tag <tag> to filter)
restic snapshots --repo /backup/restic-repo --password-file /etc/restic/password.txt
# Browse files in the latest snapshot
restic ls latest --repo /backup/restic-repo --password-file /etc/restic/password.txt
# Compare two snapshots
restic diff abc123 def456 --repo /backup/restic-repo --password-file /etc/restic/password.txtRetention Policy (forget + prune)
# Apply retention policy and reclaim space
restic forget \
--keep-daily 7 --keep-weekly 4 --keep-monthly 12 --keep-yearly 3 \
--prune \
--repo /backup/restic-repo \
--password-file /etc/restic/password.txt
# Dry run to preview what would be removed
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 \
--dry-run --repo /backup/restic-repo --password-file /etc/restic/password.txtRestore Procedures
# Restore the latest snapshot to a target directory
restic restore latest --target /restore \
--repo /backup/restic-repo \
--password-file /etc/restic/password.txt
# Restore a specific snapshot by ID
restic restore abc123 --target /restore \
--repo /backup/restic-repo \
--password-file /etc/restic/password.txt
# Restore only specific files or directories
restic restore latest --target /restore --include "/data/config" \
--repo /backup/restic-repo \
--password-file /etc/restic/password.txt
# Mount a snapshot as a FUSE filesystem (browse and copy individual files)
mkdir -p /mnt/restic
restic mount /mnt/restic --repo /backup/restic-repo --password-file /etc/restic/password.txt &
# Browse: ls /mnt/restic/snapshots/latest/
# Unmount when done: umount /mnt/resticVerification
# Verify repository metadata/structure (does not read every data pack)
restic check --repo /backup/restic-repo --password-file /etc/restic/password.txt
# Full data verification (reads all pack files -- slow but thorough)
restic check --read-data --repo /backup/restic-repo --password-file /etc/restic/password.txt
# Verify a random subset of data (faster than full read)
restic check --read-data-subset=5% --repo /backup/restic-repo --password-file /etc/restic/password.txtAutomated Backup with Environment File
/etc/restic/env
# Repository configuration
export RESTIC_REPOSITORY="s3:s3.amazonaws.com/my-backup-bucket"
export RESTIC_PASSWORD_FILE="/etc/restic/password.txt"
export AWS_ACCESS_KEY_ID="AKIAEXAMPLE"
export AWS_SECRET_ACCESS_KEY="secretkey"
# Optional: set cache directory
export RESTIC_CACHE_DIR="/var/cache/restic"Backup Script
#!/bin/bash
# /usr/local/bin/restic-backup.sh
set -euo pipefail
source /etc/restic/env
LOG="/var/log/restic-backup.log"
echo "$(date): Starting backup" >> "$LOG"
restic backup /data /etc \
--exclude-file=/etc/restic/excludes.txt \
--tag "$(hostname)" --tag daily \
--verbose >> "$LOG" 2>&1
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 \
--prune >> "$LOG" 2>&1
# Weekly integrity check (Sundays)
[ "$(date +%u)" -eq 7 ] && restic check --read-data-subset=10% >> "$LOG" 2>&1
echo "$(date): Backup completed" >> "$LOG"chmod +x /usr/local/bin/restic-backup.shScheduled Backups
Systemd Timer (Recommended)
# /etc/systemd/system/restic-backup.service
[Unit]
Description=Re… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- bash-linux – Các mẫu terminal Bash/Linux. Lệnh quan trọng, piping, xử lý lỗi, viết script. Dùng khi…
- bash-pro – Chuyên gia viết Bash script phòng thủ cho tự động hóa production, pipeline CI/CD và các…
- hunt-subdomain – Skill săn lỗ hổng subdomain takeover. Bao gồm dấu vân tay (fingerprint) nhà cung cấp…
- block-storage – Quản lý volume block storage và LVM. Cấu hình block storage trên cloud và ổ đĩa cục bộ…
- blue-green-deploy – Cấu hình chiến lược triển khai không gián đoạn, gồm blue-green, canary và rolling…
- prometheus-configuration – Thiết lập Prometheus để thu thập, lưu trữ và giám sát toàn diện các chỉ số của hạ tầng…
- gcp-cloud-architect – Thiết kế kiến trúc GCP cho startup và doanh nghiệp lớn. Dùng khi cần thiết kế hạ tầng…
- bumblebee – Chạy quét kiểm kê và mức độ phơi nhiễm chuỗi cung ứng Bumblebee trên macOS/Linux để phát…