Mysql Backup script
Writer: S4D-labs
Published: 26 November 2012Here is a small script that backups your mysql-database,
using mysqldump,
and encrypts the files using aescrypt.
You can download aescrypt from www.aescrypt.com
It accepts 1 argument, which is the database name.
You can make it more secure, by not dump it in a temporary file,
and set the passwords as arguments instead of clear text in the script.
I have put it up as a cronjob,
and it works for me.#!/bin/bash DB_NAME=$1 DB_USERNAME='backup' DB_PASSWORD='password_database' SAVEDIR='/var/backup/'; FILE_PASSWORD='pwd_encrypted_file'; #get hostname HOSTNAME=`hostname` #get date DATUM=`date "+%Y-%m-%d"` #to backup dir cd $SAVEDIR; #make savename SAVENAME="$HOSTNAME-$DB_NAME-$DATUM.sql.tar.bz2.aes" #make the backup# with skip-lock other way error #first make a full dump, you can skip this and put everything in 1 command TMPFILE=`mktemp` mysqldump -u $DB_USERNAME --password="$DB_PASSWORD" --skip-lock-tables $DB_NAME > $TMPFILE tar -cjf - $TMPFILE | aescrypt -e -p $FILE_PASSWORD - > $SAVENAME rm $TMPFILE #md5 check sum md5sum $SAVENAME > $SAVENAME.md5 #or sh1 check sum #sh1sum $SAVENAME > $SAVENAME.sh1 #change acces rights chmod 600 $SAVENAME* #Now you can (s)ftp it to a safe location. #or write it to CD