S
Syn
@admin

Robust Production Backup Script: Automated PostgreSQL & Nginx Web Root Sync

đŸ’Ŧ 1 replies|đŸ‘ī¸ 59 views
S
⚡
@adminâ€ĸ
$admin|~/legend|
⭐ 1 Rep
1 months ago#1

Sharing a clean, battle-tested Bash script I use across various VPS nodes to handle automated daily backups, gzip compression, and local file rotation.

~/ code
#!/bin/bash BACKUP_DIR="/var/backups/devyield" DATE=$(date +%Y-%m-%d_%H-%M-%S)

~/ code
mkdir -p $BACKUP_DIR # 1. Dump PostgreSQL Database pg_dump -U postgres devyield_production | gzip > "$BACKUP_DIR/db_$DATE.sql.gz" # 2. Archive Web Uploads / Root Configurations tar -czf "$BACKUP_DIR/files_$DATE.tar.gz" /var/www/devyield # 3. Purge backups older than 7 days find $BACKUP_DIR -type f -mtime +7 -exec rm {} + echo "Backup completed successfully at $DATE"</code></pre><br/> Feel free to drop this into a cron job to run nightly at midnight. Simple, lightweight, and zero third-party dependencies required.
1

You must log in to reply to this thread.