kartoza / docker-pg-backup

A cron job that will back up databases running in a docker postgres container
GNU General Public License v2.0
452 stars 103 forks source link

Issue with hostname resolution while running cron schedule #60

Closed mantoniuk closed 2 years ago

mantoniuk commented 2 years ago

Hi everyone, I'm wondering why backups.sh script works fine when running it manually from container but not working on cron schedule. I'm running 13-3.1 version and here is my backups-cron file:

# Run the backups at 11pm each night
0 2 * * * /backup-scripts/backups.sh > /var/log/cron.out 2>&1

# We need a blank line here for it to be a valid cron file

As we can see in /var/log/cron.out file:

psql: error: could not translate host name "db" to address: Temporary failure in name resolution pg_dumpall: error: could not connect to database "template1": could not translate host name "db" to address: Temporary failure in name resolution

Thank you for your help.

NyakudyaA commented 2 years ago

I fixed that issue in https://github.com/kartoza/docker-pg-backup/blob/master/scripts/start.sh#L149. The main reason why that happens is that if you run the script within the container it runs in the same shell where env variables are exposed while the cron script is running in a sub shell that doesn't have access to the env variables. I will update the image later today with this fix from master

NyakudyaA commented 2 years ago

@mantoniuk Can you pull and try again, should be fixed now