Copy to Amazon S3 is not successful when running from cron
By Emma Terry •
I have shell script executed by cron.
*/5 * * * * /home/foo/backups/backup.shAn backup script:
#!/bin/bash
FILE_NAME=$(date +%Y%m%d%H%M)
PATH1="/home/foo/backups/data-$FILE_NAME.sql.gz"
pg_dump -U XXX -E utf8 --no-acl -h localhost --no-owner XXX | gzip -c > $PATH1
aws s3 cp $PATH1 s3://XXXCron is executed correctly and local backup is created. But dump file is not copied to Amazon S3 bucket. When I run /home/foo/backups/backup.sh manually, file is transfered to S3.
Is there any reason why S3 cli could not work when aws s3 cp is executed from cron?
1 Answer
Path and Other Environment Variables are not in cron
cron does not have many environment variables set. The default value of the path variable in cron is just /usr/bin:/bin. Try adding the full /path/to/the/aws command in the script.
See this answer for a different solution: cronjob cannot find environment variables defined in .bashrc
Also see Crontab execution of multiple commands but last command is omitted
Hope this helps
0