Db Backup
Generate automated backup scripts with rotation for PostgreSQL, MySQL, SQLite, and MongoDB.
Install via CLI (Recommended)
clawhub install openclaw/skills/skills/sa9saq/db-backupDB Backup
Create automated database backup scripts with compression, rotation, and scheduling.
Instructions
-
Ask user for: Database type, name(s), connection details, backup dir (default:
~/backups/db/), retention (default: 7 days), schedule (default: daily 2 AM) -
Generate script based on database type:
PostgreSQL
#!/bin/bash
set -euo pipefail
BACKUP_DIR="${BACKUP_DIR:-$HOME/backups/db}"
RETENTION_DAYS="${RETENTION_DAYS:-7}"
TS=$(date +%Y%m%d_%H%M%S)
DB="DATABASE_NAME"
mkdir -p "$BACKUP_DIR" && chmod 700 "$BACKUP_DIR"
pg_dump -Fc "$DB" > "$BACKUP_DIR/${DB}_${TS}.dump"
chmod 600 "$BACKUP_DIR/${DB}_${TS}.dump"
find "$BACKUP_DIR" -name "${DB}_*.dump" -mtime +$RETENTION_DAYS -delete
echo "[$(date)] ✅ Backup: ${DB}_${TS}.dump"
MySQL
#!/bin/bash
set -euo pipefail
BACKUP_DIR="${BACKUP_DIR:-$HOME/backups/db}"
RETENTION_DAYS="${RETENTION_DAYS:-7}"
TS=$(date +%Y%m%d_%H%M%S)
DB="DATABASE_NAME"
mkdir -p "$BACKUP_DIR" && chmod 700 "$BACKUP_DIR"
mysqldump --single-transaction "$DB" | gzip > "$BACKUP_DIR/${DB}_${TS}.sql.gz"
chmod 600 "$BACKUP_DIR/${DB}_${TS}.sql.gz"
find "$BACKUP_DIR" -name "${DB}_*.sql.gz" -mtime +$RETENTION_DAYS -delete
echo "[$(date)] ✅ Backup: ${DB}_${TS}.sql.gz"
SQLite
#!/bin/bash
set -euo pipefail
BACKUP_DIR="${BACKUP_DIR:-$HOME/backups/db}"
RETENTION_DAYS="${RETENTION_DAYS:-7}"
TS=$(date +%Y%m%d_%H%M%S)
DB_FILE="PATH_TO_DB.sqlite"
DB_NAME=$(basename "$DB_FILE" .sqlite)
mkdir -p "$BACKUP_DIR" && chmod 700 "$BACKUP_DIR"
sqlite3 "$DB_FILE" ".backup '$BACKUP_DIR/${DB_NAME}_${TS}.sqlite'"
gzip "$BACKUP_DIR/${DB_NAME}_${TS}.sqlite"
chmod 600 "$BACKUP_DIR/${DB_NAME}_${TS}.sqlite.gz"
find "$BACKUP_DIR" -name "${DB_NAME}_*.sqlite.gz" -mtime +$RETENTION_DAYS -delete
echo "[$(date)] ✅ Backup: ${DB_NAME}_${TS}.sqlite.gz"
-
Set up cron:
chmod +x backup.sh (crontab -l 2>/dev/null; echo "0 2 * * * /path/to/backup.sh >> /path/to/backup.log 2>&1") | crontab - -
Verify: Run manually once and check output
Security
- NEVER hardcode passwords — use
~/.pgpass(PostgreSQL),~/.my.cnf(MySQL), or env vars - Set
chmod 600on all dump files,chmod 700on backup directory - Add backup directory to
.gitignore - For remote storage: pipe to
aws s3 cporrclone copy
Troubleshooting
- "permission denied": Check DB user privileges and file permissions
- "command not found": Install
postgresql-client,mysql-client, orsqlite3 - Disk full: Check
df -hbefore backup; add pre-check to script - Locked DB (SQLite): Ensure no write transactions during
.backup
Requirements
- Database client tools:
pg_dump,mysqldump,sqlite3, ormongodump gzip,find,crontab(standard Unix)- No API keys needed
Metadata
Not sure this is the right skill?
Describe what you want to build — we'll match you to the best skill from 16,000+ options.
Find the right skillPaste this into your clawhub.json to enable this plugin.
{
"plugins": {
"official-sa9saq-db-backup": {
"enabled": true,
"auto_update": true
}
}
}Related Skills
threat-model
Threat modeling and attack scenario design. Identify risks before they become vulnerabilities. STRIDE, attack trees, risk matrix.
Sns Auto Poster
Schedule and automate social media posts to X/Twitter with cron-based queue management.
security-review
Comprehensive security review for code, configs, and operations. OWASP, prompt injection, crypto security. Auto-triggers on security-related changes.
Process Monitor
Monitor system processes, identify top CPU/memory consumers, and alert on resource thresholds.
Readme Generator
Auto-generate comprehensive README.md files by analyzing project structure and configuration.