-
Edit the script to adapt
BACKUP_DIR
. Default user and database are bothapp
, you may need to change that too. -
I recommend have a
.pgpass
is your home directory. The format ishostname:port:database:username:password
, one connection per line. Alternatively, you can call the script withPGPASSWORD=*** backup.sh ...
-
Make the script executable and try it out:
chmod +x backup.sh ./backup.sh 1.2.3.4 daily 1
./backup.sh HOSTNAME SUBFOLDER KEEP_COUNT
So, given the command ./backup.sh 1.2.3.4 daily 7
, the default script will save the database app
on host 1.2.3.4
to /mnt/backups/daily/backup_TIMESTAMP.dump
, and keep the 7 most recent files.
Passing a password (if you skipped step 2):
PGPASSWORD=YOUR_PASSWORD ./backup.sh HOSTNAME SUBFOLDER KEEP_COUNT
Using another user or database:
PGUSER=YOUR_USER DB=YOUR_DATABASE ./backup.sh HOSTNAME SUBFOLDER KEEP_COUNT
crontab -e
and add something like:
0 2 * * * /home/app/backup.sh 1.2.3.4 production_daily 7 | /home/app/logger.sh
0 * * * * /home/app/backup.sh 1.2.3.4 production_hourly 24 | /home/app/logger.sh