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.