agentleFS
agentsdanceagentsdance/agentskills/skills/database-backup-restore/SKILL.md

database-backup-restore

Skill3 starsChanged 11 months agoApache-2.0View on GitHub

Set up database backup and restore procedures. Use when the user needs to implement backup strategies, create restore scripts, or manage database snapshots.

The file

Files
SKILL.md

Database Backup & Restore

Implement reliable database backup and recovery procedures.

PostgreSQL

Backup

# Full database dump
pg_dump -h localhost -U postgres -d mydb -F c -f backup.dump

# Specific tables
pg_dump -h localhost -U postgres -d mydb -t users -t orders -F c -f partial.dump

# SQL format (plain text)
pg_dump -h localhost -U postgres -d mydb > backup.sql

# All databases
pg_dumpall -h localhost -U postgres > all_databases.sql

# With compression
pg_dump -h localhost -U postgres -d mydb | gzip > backup.sql.gz

Restore

# Restore custom format
pg_restore -h localhost -U postgres -d mydb -c backup.dump

# Restore SQL format
psql -h localhost -U postgres -d mydb < backup.sql

# Create new database from backup
createdb -h localhost -U postgres mydb_restored
pg_restore -h localhost -U postgres -d mydb_restored backup.dump

MySQL

Backup

# Single database
mysqldump -u root -p mydb > backup.sql

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

# With compression
mysqldump -u root -p mydb | gzip > backup.sql.gz

Restore

mysql -u root -p mydb < backup.sql
gunzip < backup.sql.gz | mysql -u root -p mydb

Automated Backup Script

#!/bin/bash
set -euo pipefail

DB_NAME="mydb"
BACKUP_DIR="/backups"
RETENTION_DAYS=30
DATE=$(date +%Y%m%d_%H%M%S)

# Create backup
pg_dump -h localhost -U postgres -d "$DB_NAME" -F c \
  -f "$BACKUP_DIR/${DB_NAME}_${DATE}.dump"

# Upload to S3
aws s3 cp "$BACKUP_DIR/${DB_NAME}_${DATE}.dump" \
  "s3://my-backups/${DB_NAME}/${DATE}.dump"

# Clean old backups
find "$BACKUP_DIR" -name "*.dump" -mtime +$RETENTION_DAYS -delete

echo "Backup completed: ${DB_NAME}_${DATE}.dump"

Cron Schedule

# Daily at 2 AM
0 2 * * * /scripts/backup.sh >> /var/log/backup.log 2>&1

Point-in-Time Recovery (PostgreSQL)

# Enable WAL archiving in postgresql.conf
wal_level = replica
archive_mode = on
archive_command = 'cp %p /archive/%f'

# Restore to specific time
pg_restore --target-time="2024-01-15 10:30:00"

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.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

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.