Backup & Restore
PostgreSQL backup
Section titled “PostgreSQL backup”pg_dump
Section titled “pg_dump”# Full database backuppg_dump -U rcommerce -h localhost rcommerce > backup.sql
# With timestamppg_dump -U rcommerce -h localhost rcommerce > backup_$(date +%Y%m%d_%H%M%S).sqlAutomated backups
Section titled “Automated backups”Create a cron job:
#!/bin/bashpg_dump -U rcommerce -h localhost rcommerce | gzip > /backups/rcommerce_$(date +%Y%m%d).sql.gzfind /backups -name "rcommerce_*.sql.gz" -mtime +30 -deleteRestore
Section titled “Restore”# Restore from backuppsql -U rcommerce -h localhost rcommerce < backup.sql
# Restore from compressed backupgunzip < backup.sql.gz | psql -U rcommerce -h localhost rcommerceUploads backup
Section titled “Uploads backup”Back up the uploads directory:
tar -czf uploads_$(date +%Y%m%d).tar.gz /var/lib/rcommerce/uploads/Full backup script
Section titled “Full backup script”#!/bin/bashDATE=$(date +%Y%m%d_%H%M%S)BACKUP_DIR="/backups/rcommerce"
# Databasepg_dump -U rcommerce rcommerce | gzip > "$BACKUP_DIR/db_$DATE.sql.gz"
# Uploadstar -czf "$BACKUP_DIR/uploads_$DATE.tar.gz" /var/lib/rcommerce/uploads/
# Configcp /etc/rcommerce/config.toml "$BACKUP_DIR/config_$DATE.toml"
# Cleanup old backups (keep 30 days)find "$BACKUP_DIR" -mtime +30 -deletePoint-in-time recovery
Section titled “Point-in-time recovery”Enable WAL archiving in PostgreSQL for point-in-time recovery:
# postgresql.confarchive_mode = onarchive_command = 'cp %p /archive/%f'