If you chose MySQL as your data infrastructure and Microsoft Azure as your cloud infrastructure, you will probably thank this procedure (that I actually turned into a a script).
Chosen Products
Our first task is choosing the backup and automation products. I selected the following two:
- Percona XtraBackup: a leading backup product by Percona. The product creates an hot backup of the database that is equivalent to disk copy. This method is much faster to backup and recover than mysqldump. It also support increment backup.
- Azure SDK Tools Xplat: a node.js based SDK that enables command line interface to the various Azure services including Azure Storage.
- Install Percona XtraBackup
sudo wget http://www.percona.com/redir/downloads/XtraBackup/XtraBackup-2.2.3/binary/debian/precise/x86_64/percona-xtrabackup_2.2.3-4982-1.precise_amd64.deb
sudo dpkg -i percona-xtrabackup_2.2.3-4982-1.precise_amd64.deb
sudo apt-get update
sudo apt-get install -f
sudo dpkg -i percona-xtrabackup_2.2.3-4982-1.precise_amd64.deb
The CentOS
sudo rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
sudo yum -y install percona-xtrabackup.x86_64 - Install Azure SDK Tools Xplat
sudo apt-get updatesudo apt-get -y install nodejs python-software-propertiessudo add-apt-repository ppa:chris-lea/node.jssudo wget https://npmjs.org/install.sh --no-check-certificate | sudo shsudo apt-get install npmsudo npm config set registry http://registry.npmjs.org/sudo npm install -g azure-clisudo ln -s /usr/bin/nodejs /usr/bin/node - Install a backup procedure
- Get a publish settings file from Azure (can be done from the console).
- Get account name and the matching base64 key from the Azure console.
- Import the publish setting filesudo azure account import /opt/mysqlbackup/mysqlbackup.publishsettings
- Create a Storage Container
sudo azure storage container create --container container_name -a account_name -k base64_account_key - Run the backup
- The xtrabackup way
- Run a full backup and prepare it twice to make it ready for recovery
sudo xtrabackup --backup
sudo xtrabackup --prepare
sudo xtrabackup --prepare - Add the frm files and mysql database to your backup
sudo chmod -R +r /var/lib/mysql/
sudo cp -R /var/lib/mysql/myql/* /mnt/backup/mysql/
sudo cp -R /var/lib/mysql/yourdb/*.frm /mnt/backup/yourdb/ - The innobackupex way:
- Run full backup and prepare (adjust the memory usage for your case):
sudo rm -rf /mnt/datadrive/mysqlbackup/*
sudo innobackupex --user=DBUSER --password=DBUSERPASS /mnt/datadrive/mysqlbackup/
sudo innobackupex --apply-log /mnt/datadrive/mysqlbackup/ --use-memory=500M - Tar the files into a unique daily name_now=$(date +"%Y_%m_%d")
_file="/mnt/backup/mysqlbackup$_now.tar.gz"
tar cvzf "$_file" /mnt/datadrive/mysqlbackup/ - Copy the folder to Azure Storage using
- azure storage blob upload -f "$_file" -q --container container_name -a account_name -k base64_account_key
- Create a cron that will run it daily:
> sudo cron -e
* 0 * * * /opt/mysqlbackup/daily.backup.sh >/dev/null 2>&1
Recovery Guide
- Bring back the files from the Azure storage to /mnt/backup/
sudo cd /mnt/backup/ sudo azure storage blob download --container container_name -a account_name -k base64_account_key -b $file_name - Uncompress the files
sudo tar xvfz $file_name - Copy the files to your data folder (/var/lib/mysql) after shutting down the MySQL
- The xtrabackup waysudo service mysql stopsudo rsync -avrP /mnt/backup/ /var/lib/mysql/
- The innobackupex way:
sudo service mysql stopsudo rm -rf /var/lib/mysql/*sudo innobackupex --copy-back /mnt/datadrive/mysqlbackup/sudo chown -R mysql:mysql /var/lib/mysql - Verify the folder permissions
sudo chown -R mysql:mysql /var/lib/mysql - Restart the MySQL and verify everything is working.
sudo service mysql start
Bottom Line
It may be tough. It may be resource and time consuming. However, you must have good recovery process to keep your a$$...
Keep Performing,