Score:1

docker postgres backup creates an empty file when run as a cron job

in flag

I'm trying to create a cronjob that creates db backups every night.

My crontab has the job: * * * * * /home/user/scripts/backup.sh (have it set to go off every min for testing)

In backup.sh, I have:

docker exec -it dbContainer pg_dump -U username -d dbName > /home/user/backups/testingBackup.sql

The file is always empty:

-rw-rw-r--  1 user user    0 Jul 14 08:39 testingBackup.sql

However, if I run the file on my own and type the command /home/user/scripts/backup.sh, it is not empty:

-rw-rw-r--  1 user user 30813 Jul 14 08:45 testingBackup.sql

I feel like it makes sense something is off on the permissions, but everything is done from the "user". I haven't done anything from root such as sudo crontab... sudo /home/user/backups/testingBackup.sql, etc.

I am confused as to why in one scenario, the resulting file is empty, and in the other, it is not.

Thanks for any help

djdomi avatar
za flag
hows about #!/bin/bash in your script? and you may add SHELL=/bin/bash to crontab
Ethan Solomon avatar
in flag
sorry for the extremely late response, got completely sidetracked, but neither of those helped :(
djdomi avatar
za flag
please show me the current state
Ethan Solomon avatar
in flag
the sql file that is created... -rw-rw-r-- 1 user user 0 Aug 26 14:14 testingBackup.sql cron: SHELL=/bin/bash 0 4 * * * /path/otherjob.sh * * * * * /path/backup.sh backup file: #!/bin/bash /usr/bin/docker exec -it dbContainer pg_dump -U postgres -d db > path/testingBackup.sql
Ethan Solomon avatar
in flag
but if i just run: path/backup.sh, I get: -rw-rw-r-- 1 user user 224622 Aug 26 14:18 testingBackup.sql
Score:0
in flag

for the command I have in the sh file: docker exec -it dbContainer pg_dump -U username -d dbName > /home/user/backups/testingBackup.sql

It is running in interactive mode (-it). If I remove this, everything works (so command is: docker exec dbContainer pg_dump -U username -d dbName > /home/user/backups/testingBackup.sql

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.