Postgres db backup a little after crontab

I am trying to make a simple postgres backup using crontab. Here is the command I'm using:

# m  h  dom mon dow user     command
 49 13  *   *   *   postgres /usr/bin/pg_dump store | bzip2 > /home/backups/postgres/$(date +"\%Y-\%m-\%d")_store.sq.bz2

      

A backup file is created, but it is very small (looks like 14 bytes).

I can run this command just fine in the terminal (with a file size that matches my db).

No errors are mentioned in the log files (grep CRON / var / log / syslog). Any idea what could be disabled?

+3


source to share


1 answer


The key to solving this is realizing that running the "same" command in bash and running it through Cron are not the same thing. !

For example, when run through Cron, the obvious defaults (bit paths .bash_profile / .pgpass / default) do not match, and hence running in bash may not work in Cron.



For the checklist:

  • Make sure Bzip2 is replaced with full path (e.g. /usr/bin/bzip2

    on CentOS / RHEL)
  • Make sure the Store

    database is " " read by the Cron command (for example adding -U Postgres would be a good addition). If the DB login depends on the .pgpass file, it will not work with cron. In such scenarios, you need to ensure that pg_hba.conf is configured for this purpose (for example, you can allow authentication " trust

    " for a specific known combination of DB / machine / user, etc.)
  • Make sure / home / backups / postgres / ... is writable for obvious reasons.
0


source







All Articles