
Database Backup Automation
FreeAutomate and secure your database backup processes.
Free · Opens the source repo
What Database Backup Automation does
Database Backup Automation is a powerful skill designed for developers and database administrators who need to streamline their backup processes across various database systems, including PostgreSQL, MySQL, MongoDB, and SQLite. This skill automates the creation of production-ready backup scripts, ensuring that backups are not only created but also compressed and encrypted for security. With built-in scheduling capabilities, users can easily set up cron jobs to run backups at specified intervals, which helps maintain data integrity and availability without manual intervention.
The skill operates through a series of scripts that guide users in generating customized backup scripts tailored to their specific database type and requirements. Users can specify essential parameters such as database connection details, backup schedules, retention policies, and whether encryption is needed. This flexibility allows for a tailored approach to backup management, accommodating both simple setups and complex production environments.
In addition to generating backup scripts, this skill provides functionality for scheduling these backups with cron, validating the integrity of backup files, and creating corresponding restore scripts. This comprehensive approach ensures that users are not only prepared for routine backups but also equipped for disaster recovery scenarios. The included references and best practices further enhance the user's ability to implement effective backup strategies.
Overall, Database Backup Automation is an essential tool for anyone responsible for managing databases, offering a reliable solution to automate and secure backup processes while minimizing the risk of data loss.
When to use it
Use this skill when you need to automate database backups across multiple database systems and require features like scheduling and encryption.
When not to use it
This skill may not be suitable for environments without access to the command line or for users unfamiliar with database management concepts.
What you can build with it
Automating Daily Backups
Set up daily backups for a PostgreSQL database using the skill's scheduling features to ensure data is consistently protected.
Creating Encrypted Backups
Generate a backup script for MySQL that includes encryption, safeguarding sensitive data against unauthorized access.
Disaster Recovery Planning
Utilize the skill to create restore scripts alongside backups, preparing for potential data recovery scenarios.
How to install Database Backup Automation
View source1. Install with the skills CLI
npx skills add jeremylongshore/claude-code-plugins-plus-skills/automating-database-backups --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by jeremylongshoreDatabase Backup Automation
Generate production-ready backup scripts for PostgreSQL, MySQL, MongoDB, and SQLite with compression, encryption, scheduling, and retention policies.
Quick Start
PostgreSQL Backup
#!/bin/bash
set -euo pipefail
BACKUP_DIR="/var/backups/postgresql"
DB_NAME="mydb"
DATE=$(date +%Y%m%d_%H%M%S)
BACKUP_FILE="${BACKUP_DIR}/${DB_NAME}_${DATE}.sql.gz"
pg_dump -h localhost -U postgres -d "$DB_NAME" \
--format=custom \
--compress=9 \
--file="$BACKUP_FILE"
# Encrypt with GPG (optional)
gpg --symmetric --cipher-algo AES256 --batch --passphrase-file /etc/backup.key "$BACKUP_FILE"
rm "$BACKUP_FILE"
MySQL Backup
#!/bin/bash
BACKUP_DIR="/var/backups/mysql"
DB_NAME="mydb"
DATE=$(date +%Y%m%d_%H%M%S)
mysqldump -h localhost -u root -p"${MYSQL_PASSWORD}" \
--single-transaction \
--routines \
--triggers \
"$DB_NAME" | gzip > "${BACKUP_DIR}/${DB_NAME}_${DATE}.sql.gz"
MongoDB Backup
#!/bin/bash
mongodump --uri="mongodb://localhost:27017" \ # 27017: MongoDB port
--db=mydb \
--out=/var/backups/mongodb/$(date +%Y%m%d_%H%M%S) \
--gzip
Instructions
Step 1: Gather Requirements
Ask the user for:
- Database type (PostgreSQL, MySQL, MongoDB, SQLite)
- Database connection details (host, port, database name)
- Backup schedule (cron expression or frequency)
- Retention policy (days to keep)
- Encryption requirement (yes/no)
- Backup destination (local path, S3, GCS)
Step 2: Generate Backup Script
Use scripts/backup_script_generator.py to create a customized backup script:
python3 ${CLAUDE_SKILL_DIR}/scripts/backup_script_generator.py \
--db-type postgresql \
--database mydb \
--output /opt/backup-scripts/mydb-backup.sh \
--compression gzip \
--encryption gpg
Step 3: Schedule with Cron
Use scripts/backup_scheduler.py to create cron entries:
python3 ${CLAUDE_SKILL_DIR}/scripts/backup_scheduler.py \
--script /opt/backup-scripts/mydb-backup.sh \
--schedule "0 2 * * *" \
--user postgres
Step 4: Validate Backup
After backup completes, validate integrity:
python3 ${CLAUDE_SKILL_DIR}/scripts/backup_validator.py \
--backup-file /var/backups/postgresql/mydb_20250115.sql.gz \
--db-type postgresql
Step 5: Generate Restore Procedure
Create matching restore script:
python3 ${CLAUDE_SKILL_DIR}/scripts/restore_script_generator.py \
--db-type postgresql \
--database mydb \
--output /opt/backup-scripts/mydb-restore.sh
Cron Schedule Reference
| Schedule | Cron Expression | Description |
|---|---|---|
| Daily 2 AM | 0 2 * * * | Low-traffic window |
| Every 6 hours | 0 */6 * * * | Frequent backups |
| Weekly Sunday | 0 2 * * 0 | Weekly full backup |
| Monthly 1st | 0 2 1 * * | Monthly archive |
Retention Policy Example
# Keep daily backups for 7 days
# Keep weekly backups for 4 weeks
# Keep monthly backups for 12 months
find /var/backups -name "*.gz" -mtime +7 -delete # Daily cleanup
find /var/backups/weekly -mtime +28 -delete # Weekly cleanup
find /var/backups/monthly -mtime +365 -delete # 365: Monthly cleanup
Output
- Backup Scripts: Database-specific shell scripts with compression and encryption
- Cron Entries: Ready-to-install crontab configurations
- Restore Scripts: Matching restore procedures for each backup type
- Validation Reports: Integrity check results for backup files
Error Handling
| Error | Cause | Solution |
|---|---|---|
| Connection refused | DB not running | Check service status: systemctl status postgresql |
| Permission denied | Wrong credentials | Verify user has backup privileges |
| Disk full | No space | Check space: df -h, clean old backups |
| Lock timeout | Active transactions | Use --single-transaction for MySQL |
Resources
${CLAUDE_SKILL_DIR}/references/postgresql_backup_restore.md- PostgreSQL backup guide${CLAUDE_SKILL_DIR}/references/mysql_backup_restore.md- MySQL backup guide${CLAUDE_SKILL_DIR}/references/mongodb_backup_restore.md- MongoDB backup guide${CLAUDE_SKILL_DIR}/references/sqlite_backup_restore.md- SQLite backup guide${CLAUDE_SKILL_DIR}/references/backup_best_practices.md- Security and storage best practices${CLAUDE_SKILL_DIR}/references/cron_syntax.md- Cron scheduling reference
Overview
Automate database backup processes with scheduling, compression, and encryption.
Prerequisites
- Access to the PostgreSQL environment or API
- Required CLI tools installed and authenticated
- Familiarity with PostgreSQL concepts and terminology
Examples
Basic usage: Apply automating database backups to a standard project setup with default configuration options.
Advanced scenario: Customize automating database backups for production environments with multiple constraints and team-specific requirements.
Frequently asked questions about Database Backup Automation
Similar skills
ClickHouse Logs Queries
Efficiently manage Supabase logs with ClickHouse SQL.
EF Core D2 Database Diagram Generator
Visualize your EF Core models as D2 diagrams effortlessly.
Safe SQL Execution
Ensure secure SQL execution in Supabase applications.
Oracle to PostgreSQL Migration
Identify migration risks between Oracle and PostgreSQL.
SSMA Console
Streamline Oracle to SQL Server migrations with ease.
SQL Performance Optimization
Enhance SQL query efficiency across all databases.
