Situatie
We’ll dump daily logical backups with pg_dump, compress them, encrypt with gpg, sync to S3 via rclone, and keep a rotating retention policy locally and on S3.
Solutie
Prerequisites
-
Linux server with
postgresqluser access. -
pg_dumpavailable. -
rcloneinstalled and configured with an S3 remote (rclone config). -
gpginstalled (for symmetric encryption). -
A shell user with
cronaccess.
Files & variables (examples)
Steps
-
Create backup dir & passphrase file
-
Install rclone & test remote
-
Create backup script
/usr/local/bin/pg_backup_to_s3.sh
Make it executable:
-
Schedule cron job
Open root crontab or a dedicated user:
-
Restore example
Troubleshooting & notes
-
Use
pg_dump -Fc(custom format) for fasterpg_restore. If you prefer plain SQL usepg_dump > file.sql -
Test restores regularly (monthly) to ensure backups are usable
-
gpg -cis symmetric encryption; for team setups use public-key encryption instead -
Monitor cron logs and
rcloneexit codes; integrate with your alerting.
Leave A Comment?