M HYPE SPLASH
// updates

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.sh

An 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://XXX

Cron 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?

2

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy