0

I have this command in the crontab

 bash /opt/database/pg_backup_rotated.sh -c /opt/database/pg_backup.config >> /opt/data/logs/daily-database_dump.log 2>&1

and in the.bashrc I have PG_PASSWORD supplied for the backup user. The crontab stops by asking password while executing the above command through the terminal and works fine (it does not ask for a password). What is wrong?

I am using instructions from there to backup: https://wiki.postgresql.org/wiki/Automated_Backup_on_Linux

2
  • cron executes bash non-interactively, which bypasses your PG_PASSWORD assignment in ~/.bashrc Commented Feb 23, 2023 at 2:26
  • @steeldriver thx for the response. How can I fix it? Commented Feb 23, 2023 at 11:40

1 Answer 1

1

If you're using pg_dump in your backup script, it can read from ~/.pgpass in the home directory of the calling user. So create a ~/.pgpass file with the password in it.

hostname:port:database:username:password

For example:

localhost:5432:application_production:application:OukaaKu9oleif4Oomee2Gubaw9shie7h

Here's the documentation about that file.

3
  • Thanks for your response. However, I am not using pg_dump. I have added the link for my method Commented Feb 23, 2023 at 12:22
  • Those scripts appear to call pg_dump?
    – popey
    Commented Feb 23, 2023 at 12:29
  • yeap. okay i will try Commented Feb 23, 2023 at 12:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .