I'm trying to run a cronjob to backup my database every day. I have created the cronjob by logging in to root and doing crontab -e
, then pasting in my command:
* * * * * /bin/bash -l -c 'cd /var/lib/postgresql && sudo -u postgres pg_dump db_development -O -f "/var/lib/postgresql/backup/db-`date +\%Y-\%m-\%d\\%k:\%M:\%S`.sql"' > /var/lib/postgresql/log/cron.log 2>&1
It is terribly annoying because the command works PERFECTLY if i run it in terminal, with either the postgres user or with root. However, I get no data back at all from the cronjob task. The log file is blank and the backup file is never created.
I've been trying to fix this for 10+ hours and I'm out of ideas. Any help is appreciated. Thanks.