0

I have a database backup script that works fine when I run it manually, but if I run it via cron it doesn't work and I get this in the log:

Mar 11 11:58:02 ip-172-XX-Y-ZZ mysqldump: Could not retrieve file stat of "/home/admin/-": [Errno 2] No such file or directory: '/home/admin/-'
Mar 11 11:58:02 ip-172-XX-Y-ZZ mysqldump: mysqldump: Got errno 32 on write

This is the script:

#!/bin/bash
# Note: aws credentials are set with `aws configure` after installing aws cli
mysqldump -umysqldumpuser -pmysqldumpuserpassword --all-databases | gzip -c | aws s3 cp - s3://s3-bucket-name/mysql/all-databases--`date +%Y-%m-%d--%H-%M-%S%Z`.sql.gz

crontab includes this:

58 0 * * * ~/scripts/mysqldump-all-databases-to-aws-s3.sh 2>&1 | /usr/bin/logger -t mysqldump

This is a Debian Jessie server on AWS LightSail. I have the same script and crontab on a server running Amazon Linux and it works okay on that one.

I did change the timezone on the Debian server to my local timezone, while on the Amazon Linux server it is set to UTC. Maybe that is causing a problem with cron?

Do you know why this script is failing? Thanks.

  • Usually an environmental issue; are there variables set during a interactive session that are required? (AWS credentials?) – Jeff Schaller Mar 12 '18 at 11:14
  • I just noticed that the log is recording 11:58, but the job runs at 00:58. This is the difference between UTC and my timezone. Is that normal? – Matt Mar 12 '18 at 11:15
  • Hurray, daylight savings! – Jeff Schaller Mar 12 '18 at 11:16
  • 1
    @RuiFRibeiro It's aws s3 cp docs – Matt Mar 12 '18 at 11:27
  • 1
    @Yaron Yes, the aws s3 ls script works as a cron job. I actually have a work around to my problem now by doing it in 3 steps: dump the database to a temp file; copy the temp file to S3; delete the temp file. That works. Still curious as to what caused the error in my original script but this will do for now. Time for bed :) Thanks for everyone's help – Matt Mar 12 '18 at 12:16

Your Answer

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

Browse other questions tagged or ask your own question.