Prerequisites
Before using this skill, ensure:
- Database credentials with backup permissions (SELECT on all tables)
- Sufficient disk space for backup files (estimate 2-3x database size with compression)
- Cron or task scheduler access for automated scheduling
- Backup destination storage (local disk, NFS, S3, GCS, Azure Blob)
- Encryption tools installed (gpg, openssl) for secure backups
- Test database available for restore validation
Instructions
Step 1: Assess Backup Requirements
- Identify database type (PostgreSQL, MySQL, MongoDB, SQLite)
- Determine backup frequency (hourly, daily, weekly, monthly)
- Define retention policy (how long to keep backups)
- Calculate expected backup size and storage needs
- Document RTO (Recovery Time Objective) and RPO (Recovery Point Objective)
Step 2: Design Backup Strategy
- Choose backup type: full, incremental, or differential
- Select backup destination (local, network storage, cloud)
- Plan backup scheduling to avoid peak usage times
- Define backup naming convention with timestamps
- Determine compression and encryption requirements
Step 3: Generate Backup Scripts
- Create database-specific backup command (pg_dump, mysqldump, mongodump)
- Add compression using gzip or zstd for storage efficiency
- Implement encryption using gpg or openssl for security
- Add error handling and logging to backup script
- Include backup verification (checksum, test restore)
Step 4: Configure Backup Schedule
- Create cron job entry for automated execution
- Set appropriate schedule based on backup frequency
- Configure environment variables for credentials
- Set up log rotation for backup logs
- Test manual execution before enabling automation
Step 5: Implement Retention Policy
- Create cleanup script to remove old backups
- Implement tiered retention (daily 7 days, weekly 4 weeks, monthly 12 months)
- Schedule retention cleanup after backup completion
- Add safeguards to prevent accidental deletion of recent backups
- Log all backup deletions for audit trail
Step 6: Create Restore Procedures
- Document step-by-step restore process
- Create restore scripts for each database type
- Include procedures for point-in-time recovery
- Test restore process on non-production environment
- Document restore time estimates and validation steps
Output
This skill produces:
Backup Scripts: Shell scripts for database dumps with compression and encryption
Cron Configurations: Crontab entries for automated backup scheduling
Retention Scripts: Automated cleanup scripts implementing retention policies
Restore Procedures: Step-by-step documentation and scripts for database restoration
Monitoring Configuration: Log file locations and success/failure notification setup
Error Handling
Backup Failures:
- Check database connectivity and credentials
- Verify sufficient disk space for backup files
- Review database logs for lock or permission issues
- Implement retry logic with exponential backoff
- Send alerts on backup failures
Insufficient Disk Space:
- Monitor disk usage before backup execution
- Implement pre-backup cleanup of old backups
- Use incremental backups to reduce space requirements
- Compress backups more aggressively
- Move backups to remote storage immediately after creation
Encryption Errors:
- Verify encryption tools (gpg, openssl) are installed
- Check encryption key availability and permissions
- Test encryption/decryption process manually
- Document key management procedures
- Store encryption keys securely separate from backups
Schedule Conflicts:
- Ensure only one backup runs at a time (use lock files)
- Adjust backup schedule to avoid peak database usage
- Implement backup queuing for multiple databases
- Monitor backup duration and adjust schedule if needed
- Alert if backup duration exceeds acceptable window
Resources
Backup Script Templates:
- PostgreSQL:
{baseDir}/templates/backup-scripts/postgresql-backup.sh
- MySQL:
{baseDir}/templates/backup-scripts/mysql-backup.sh
- MongoDB:
{baseDir}/templates/backup-scripts/mongodb-backup.sh
- SQLite:
{baseDir}/templates/backup-scripts/sqlite-backup.sh
Restore Procedures: {baseDir}/docs/restore-procedures/
- Point-in-time recovery
- Full database restore
- Selective table restore
- Cross-server migration
Retention Policy Templates: {baseDir}/templates/retention-policies.yaml
Cron Job Examples: {baseDir}/examples/crontab-entries.txt
Monitoring Scripts: {baseDir}/scripts/backup-monitoring.sh
1---2name: automating-database-backups3description: |4 Use when you need to automate database backup processes with scheduling and encryption.5 This skill creates backup scripts for PostgreSQL, MySQL, MongoDB, and SQLite with compression.6 Trigger with phrases like "automate database backups", "schedule database dumps",7 "create backup scripts", or "implement disaster recovery for database".8allowed-tools:9 - Read10 - Write11 - Edit12 - Grep13 - Glob14 - Bash(pg_dump:*, mysqldump:*, mongodump:*, cron:*)15version: 1.0.016license: MIT17---1819## Prerequisites2021Before using this skill, ensure:22- Database credentials with backup permissions (SELECT on all tables)23- Sufficient disk space for backup files (estimate 2-3x database size with compression)24- Cron or task scheduler access for automated scheduling25- Backup destination storage (local disk, NFS, S3, GCS, Azure Blob)26- Encryption tools installed (gpg, openssl) for secure backups27- Test database available for restore validation2829## Instructions3031### Step 1: Assess Backup Requirements321. Identify database type (PostgreSQL, MySQL, MongoDB, SQLite)332. Determine backup frequency (hourly, daily, weekly, monthly)343. Define retention policy (how long to keep backups)354. Calculate expected backup size and storage needs365. Document RTO (Recovery Time Objective) and RPO (Recovery Point Objective)3738### Step 2: Design Backup Strategy391. Choose backup type: full, incremental, or differential402. Select backup destination (local, network storage, cloud)413. Plan backup scheduling to avoid peak usage times424. Define backup naming convention with timestamps435. Determine compression and encryption requirements4445### Step 3: Generate Backup Scripts461. Create database-specific backup command (pg_dump, mysqldump, mongodump)472. Add compression using gzip or zstd for storage efficiency483. Implement encryption using gpg or openssl for security494. Add error handling and logging to backup script505. Include backup verification (checksum, test restore)5152### Step 4: Configure Backup Schedule531. Create cron job entry for automated execution542. Set appropriate schedule based on backup frequency553. Configure environment variables for credentials564. Set up log rotation for backup logs575. Test manual execution before enabling automation5859### Step 5: Implement Retention Policy601. Create cleanup script to remove old backups612. Implement tiered retention (daily 7 days, weekly 4 weeks, monthly 12 months)623. Schedule retention cleanup after backup completion634. Add safeguards to prevent accidental deletion of recent backups645. Log all backup deletions for audit trail6566### Step 6: Create Restore Procedures671. Document step-by-step restore process682. Create restore scripts for each database type693. Include procedures for point-in-time recovery704. Test restore process on non-production environment715. Document restore time estimates and validation steps7273## Output7475This skill produces:7677**Backup Scripts**: Shell scripts for database dumps with compression and encryption7879**Cron Configurations**: Crontab entries for automated backup scheduling8081**Retention Scripts**: Automated cleanup scripts implementing retention policies8283**Restore Procedures**: Step-by-step documentation and scripts for database restoration8485**Monitoring Configuration**: Log file locations and success/failure notification setup8687## Error Handling8889**Backup Failures**:90- Check database connectivity and credentials91- Verify sufficient disk space for backup files92- Review database logs for lock or permission issues93- Implement retry logic with exponential backoff94- Send alerts on backup failures9596**Insufficient Disk Space**:97- Monitor disk usage before backup execution98- Implement pre-backup cleanup of old backups99- Use incremental backups to reduce space requirements100- Compress backups more aggressively101- Move backups to remote storage immediately after creation102103**Encryption Errors**:104- Verify encryption tools (gpg, openssl) are installed105- Check encryption key availability and permissions106- Test encryption/decryption process manually107- Document key management procedures108- Store encryption keys securely separate from backups109110**Schedule Conflicts**:111- Ensure only one backup runs at a time (use lock files)112- Adjust backup schedule to avoid peak database usage113- Implement backup queuing for multiple databases114- Monitor backup duration and adjust schedule if needed115- Alert if backup duration exceeds acceptable window116117## Resources118119**Backup Script Templates**:120- PostgreSQL: `{baseDir}/templates/backup-scripts/postgresql-backup.sh`121- MySQL: `{baseDir}/templates/backup-scripts/mysql-backup.sh`122- MongoDB: `{baseDir}/templates/backup-scripts/mongodb-backup.sh`123- SQLite: `{baseDir}/templates/backup-scripts/sqlite-backup.sh`124125**Restore Procedures**: `{baseDir}/docs/restore-procedures/`126- Point-in-time recovery127- Full database restore128- Selective table restore129- Cross-server migration130131**Retention Policy Templates**: `{baseDir}/templates/retention-policies.yaml`132**Cron Job Examples**: `{baseDir}/examples/crontab-entries.txt`133**Monitoring Scripts**: `{baseDir}/scripts/backup-monitoring.sh`