1

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

  • hows about #!/bin/bash in your script? and you may add SHELL=/bin/bash to crontab – djdomi Jul 21 '21 at 07:27
  • sorry for the extremely late response, got completely sidetracked, but neither of those helped :( – Ethan Solomon Aug 26 '21 at 17:07
  • please show me the current state – djdomi Aug 26 '21 at 17:21
  • 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 Aug 26 '21 at 18:16
  • but if i just run: path/backup.sh, I get: -rw-rw-r-- 1 user user 224622 Aug 26 14:18 testingBackup.sql – Ethan Solomon Aug 26 '21 at 18:19

1 Answers1

0

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