MySQL Innodb Backup/Restore script using Percona Xtrabackup
In the previous article we saw how we could install and make use of the Percona Xtrabackup backup utility for MySQL.
Here is a script that will create a full database backup of you Innodb engine schemas(tables) without locking any of them and with no down time.
Is important to know that the script has 2 steps, one will create the initial backup piece and the second step will consolidate the initial backup by applying the log so it become "RESTORE READY" or in other words consistent.
So in case you loose the database recovery using this type of backup will not need any logs to be applied to it.
Here is the Backup script
use it as template and alter the variables as per your needs
Now let's create the Restore Script
Very important:
before you plan to restore you backup using xtrabackup utility make sure you do the following
1 - Stop you MySQL instance
2 - Remove all files located in your "datadir" MySQL variable(is where your data files are locates)
3 - run the Restore command(will copy all the backup to the locations stated in the my.cnf file)
4 - start you MySQL instance
I hope this was helpful.
Fell free to drop a comment with your opinion.