agentleFS
jholhewresjholhewres/devclaw-skills/skills/backup/SKILL.md

backup

Skill4 starsChanged 9 months agoMITView on GitHub

Backup and restore — files, databases, and system backups

  • Deletes or force-pushes
  • Installs packages

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 13 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use --dry-run before running backups

    line 206
  2. Distinctive:

    Test restore procedures regularly

    line 207
  3. Distinctive:

    Keep multiple backup generations

    line 208

“Common” is measured: kept by at least 6 in 10 of the 13 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Backup

Backup and restore files, databases, and systems.

Setup

Base tools (often pre-installed):

  • macOS: rsync, tar included; for DB tools: brew install postgresql mysql (pg_dump, mysqldump), brew install mongodb/brew/mongodb-database-tools (mongodump)
  • Ubuntu: sudo apt install rsync (tar usually included), sudo apt install postgresql-client default-mysql-client mongodb-database-tools for DB backups

Cloud: rclone config for multi-cloud; aws configure for S3.

File Backups

rsync (Incremental)

# Basic sync
rsync -av /source/ /backup/

# With progress
rsync -av --progress /source/ /backup/

# Exclude patterns
rsync -av --exclude 'node_modules' --exclude '.git' --exclude '*.log' /source/ /backup/

# Remote backup
rsync -avz -e ssh /source/ user@remote:/backup/

# Delete files not in source (mirror)
rsync -av --delete /source/ /backup/

# Dry run
rsync -av --dry-run /source/ /backup/

# Backup with date
rsync -av --backup --backup-dir=/backup/$(date +%Y%m%d) /source/ /backup/current/

tar Archives

# Create archive
tar -czvf backup.tar.gz /path/to/backup/

# With exclude
tar -czvf backup.tar.gz --exclude='*.log' --exclude='node_modules' /path/

# Split large archives
tar -czvf - /path/ | split -b 1G - backup.tar.gz.

# Verify archive
tar -tzvf backup.tar.gz

# Extract
tar -xzvf backup.tar.gz -C /destination/

# Incremental tar
tar --create --file=backup.tar --listed-incremental=backup.snar /path/

Database Backups

PostgreSQL

# Full backup
pg_dump -h localhost -U user dbname > backup.sql

# Compressed
pg_dump -h localhost -U user dbname | gzip > backup.sql.gz

# All databases
pg_dumpall -U postgres > all_databases.sql

# Custom format (better for large DBs)
pg_dump -h localhost -U user -Fc dbname > backup.dump

# Restore from SQL
psql -h localhost -U user dbname < backup.sql

# Restore from custom format
pg_restore -h localhost -U user -d dbname backup.dump

MySQL

# Single database
mysqldump -u user -p dbname > backup.sql

# All databases
mysqldump -u user -p --all-databases > all_databases.sql

# With gzip
mysqldump -u user -p dbname | gzip > backup.sql.gz

# Specific tables
mysqldump -u user -p dbname table1 table2 > tables.sql

# Restore
mysql -u user -p dbname < backup.sql

MongoDB

# Export database
mongodump --uri="mongodb://user:pass@host/dbname" --out=backup/

# Export specific collection
mongodump --uri="mongodb://host/dbname" --collection=users --out=backup/

# Import database
mongorestore --uri="mongodb://host/dbname" backup/dbname/

# Export to JSON
mongoexport --uri="mongodb://host/dbname" --collection=users --out=users.json

Automated Backups

Cron Job

# Edit crontab
crontab -e

# Daily backup at 2 AM
0 2 * * * rsync -av /source/ /backup/ >> /var/log/backup.log 2>&1

# Weekly full backup
0 3 * * 0 tar -czvf /backup/weekly-$(date +\%Y\%m\%d).tar.gz /source/

# Monthly database backup
0 4 1 * * pg_dump -U user dbname | gzip > /backup/db-$(date +\%Y\%m).sql.gz

Backup Script

#!/bin/bash
# backup.sh

DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/backup/$DATE"
SOURCE="/data"

mkdir -p "$BACKUP_DIR"

# Files
rsync -av "$SOURCE/" "$BACKUP_DIR/files/"

# Database
pg_dump -U user mydb | gzip > "$BACKUP_DIR/database.sql.gz"

# Cleanup old backups (keep last 7)
find /backup -type d -mtime +7 -exec rm -rf {} \;

echo "Backup completed: $BACKUP_DIR"

Cloud Backup

AWS S3

# Sync to S3
aws s3 sync /local/ s3://bucket/backup/

# With glacier storage
aws s3 sync /local/ s3://bucket/backup/ --storage-class GLACIER

# Restore from S3
aws s3 sync s3://bucket/backup/ /local/

rclone (Multi-cloud)

# Setup
rclone config

# Sync to Google Drive
rclone sync /local/ gdrive:backup/

# Sync to Dropbox
rclone sync /local/ dropbox:backup/

# Encrypted backup
rclone sync /local/ crypt:backup/

Tips

  • Use --dry-run before running backups
  • Test restore procedures regularly
  • Keep multiple backup generations
  • Encrypt sensitive backups
  • Store offsite or in cloud

Triggers

backup, restore, rsync, database backup, file backup, pg_dump, mysqldump, archive

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.