Postgresql backup

Here is an example of a script that you can use to do a Postgresql database backup.

In the control panel select config on the Postgresql database.
Create a file named pg_backup.sh in the scripts folder, paste the following and change the database name and password.

#!/bin/sh

export PGPASSWORD=YourPassword
DATABASE=YourDatabase
USER=webadmin
RETENTION=3
DATE=`date +%Y%m%d_%H%M`

find /var/lib/jelastic/backup/ -name "*.sql.bz2" -mtime +$RETENTION -exec rm {} \;
pg_dump -Fc $DATABASE -U $USER > /var/lib/jelastic/backup/$DATABASE-dump-$DATE.sql

 

Then edit the postgres file in the cron folder and add the following line to run the backup daily at 02:00.

0 2 * * * sh /var/lib/jelastic/bin/pg_backup.sh > /var/lib/jelastic/log/backup.log 2>&1

 

 

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Article is closed for comments.