Thanks for reading this.
I have created a bash script to backup my databases. The script will create a directory for the day then create a backup file for each database within that directory.
It runs as expected if I call it from the command line.
I want it to run when the machine starts up so I have created a cron job to run it.
When the cron job runs it creates the directory but it doesn't create the files.
I have checked the syslog and I can see the cron job being processed but there is no output that indicates an error. There is a message which appears to suggest that an email would have been sent if postfix or some such were installed. I don't really want to install postfix unless I really have to.
Is there any other log I could be looking at?
Here's the cron job (it runs as root):
@reboot /usr/bin/db.backup.sh
here's the bash script:
#!/bin/bash
DB_BACKUP="/files/database_backups/`date +%Y-%m-%d`"
DB_USER="root"
DB_PASSWD="a"
HN=`hostname | awk -F. '{print $1}'`
# Create the backup directory
mkdir -p $DB_BACKUP
# Remove backups older than 10 days
find /files/database_backups/ -maxdepth 1 -type d -mtime +10 -exec rm -rf {} \;
# Backup each database on the system
for db in $(mysql --user=$DB_USER --password=$DB_PASSWD -e 'show databases' -s --skip-column-names|grep -viE '(staging|performance_schema|information_schema)');
do mysqldump --max-allowed-packet=1073741824 --user=$DB_USER --password=$DB_PASSWD --events --opt --single-transaction $db | gzip > "$DB_BACKUP/$db-$(date +%Y-%m-%d).sql.gz";
chown -R www-data:www-data $DB_BACKUP
done