简体   繁体   中英

Running cron produces different result than running its command

I have the following script that saves a db backup to s3:

# next, backup the mysql `premiered` database to the backups folder
echo successfully backed up mysql databasee
mysqldump --single-transaction -u root test | gzip  > $BACKUPFOLDER/$CONNECT

# finally, save the backups to s3 via s3fs
s3fs test-backups ./s3fs
cp $BACKUPFOLDER/$CONNECT ./s3fs/$CONNECT
echo succeessfully saved sql file to s3

When I run this as a shell command, $ ./backup.sh , it correctly saves the file to S3. However, when I run this command via cron, it literally saves the file to the local ./s3fs folder and does not save it to S3. Why does this occur and what do I need to do to fix this?

The cron job executes under user cron that does not, by default, have access to your S3 credentials. I suppose you store them in your S3_* environment variables, but the cron job executes with an almost empty environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM