Cron job for Postgresql backup is not working

centos7cronpostgresql

I have set a cron job to take backup the database every hour.

/etc/crontab

0 */1 * * * sh /opt/post.sh

/opt/post.sh

pg_dump -U postgres db_name > /home/golp/Desktop/backup.sql

For authentication, I am using .pgpass file.

localhost:5432:db_name:postgres:password

Regarding permissions,

chmod 0600 ~/.pgpass
chown postgres:postgres /home/golp/Desktop/

The cron job seems to run every hour (I checked the log). I find that the backup file created by cron job is empty. I am using CentOS 7 1503 and Postgresql 9.5

NOTE: When I run pg_dump -U postgres db_name > /home/golp/Desktop/backup.sql as root user in terminal, backup is created as expected.

Kindly help.

Best Answer

Try putting the full path to pg_dump in your script.

Related Topic