I have a MySQL backup script I picked up somewhere (can't recall where). It works when I run it manually, but run on cron as root it doesn't run for some reason.
There may be a cron log I can check somewhere, but I'm curious if anyone has any ideas as to why it's not creating my daily backups on cron.
#!/bin/bash
# Set the datestamp, login credentials and backup directory
export date=$(date +\%Y\%m\%d)
export creds="-uadmin -p`sudo cat /etc/psa/.psa.shadow`"
export backupdir="/root/backups-mydomain.com-mysql"
# delete week old files
find ${backupdir}/ -regex '.*.dump.gz' -mtime +4 -exec rm {} \;
# dump databases to the backupdir
echo "show databases;" | mysql ${creds} | egrep -v ^Database$ | \
awk '{print "mysqldump ${creds} "$1" | \
gzip > ${backupdir}/db-"$1"-${date}.dump.gz"}' | \
sh
I have tried the following cron entries, neither of which work:
10 0 * * * /root/_backups-generate-mysql.sh
10 0 * * * /bin/sh /root/_backups-generate-mysql.sh
I'm getting this error with the suggestion given below:
/bin/sh: /root/_backups-generate-mysql.sh: Permission denied