#Must be run via cron PASS=<fill in pass> PATHDUMP=<path to store dumps> DATE=$(date '+%d-%m-%Y--%s') EMAIL="<your email address> mysqldump -u root -p$PASS --all-databases --single-transaction > $PATHDUMP/database_$DATE.sql 2>/tmp/.$$errorscript if [ $? -eq 0 ];then echo "MySQL dump database SUCCESSFUL" | mail -s "MySQL dump database SUCCESSFUL" "$EMAIL" gzip $PATHDUMP/database_$DATE.sql else echo "Message is $(cat /tmp/.$$errorscript)" | mail -s "MySQL dump database FAILED" "$EMAIL" rm -f $PATHDUMP/database_$DATE.sql fi #restore with mysql -u root -p$PASS < <unzipped_dump_file>
On Scientific Linux 6.1 make a symbolic link to /etc/cron.daily (will be triggered by anacron)
ln -s <script> /etc/cron.daily