How To - Restore MariaDB slave with XtraBackup
Lets look at a faster way to restore a MySQL (who still uses MySQL?) or the better MariaDB, Percona master/slave replication after a failure. Lets look at the old hard way…
mysqldump is just painful or me when a better alternative exists. So here comes XtraBackup to the rescue. This is by far the fastest way to get replication running again, especially without any downtime.
First lets use XtraBackup’s innobackupex wrapper to do a full dump of the master database. I am going to assume that you have your credentials saved in ~/.my.cnf. Depending on your open file limit and the number of tables you have you may need to set your ulimit. You can check it with ulimit -n. If necessary increase it ulimit -n {new value}. For most people this won’t be a issue, but it creeps for me once and a while.
From the Master server, we will use innobackupex to dump the data. Then apply the logs needed for the restore and copy it over with rsync. As always with XtraBackup you are looking for the completed OK! message. I am going to assume since you have a Master/Slave setup you have ssh keys setup between the machines, you are using Ed25519 keys right?
Now we will be working from the slave. We will need to stop the MySQL server, as always verify it has properly stopped.
Now I will make a backup of the old mysql data directory. Obviously if you have moved it, you will need to adjust the path.
Now lets move the new MySQL data directory in-place and start the database.
Now that we have the slave running it is still far behind, so we will need to get replication running again.
Now the key is we have the bin-log number and the exact position to start the replication again on the slave.
You should now see that Slave_IO_Running: Yes, also pay attention to the seconds behind master.
If this is your first time working with XtraBackup you should read my how to.
brian4286
Brian has spent more than fifteen years as Unix enthusiast, specalising in systems administration and solutions architecture for SMB's to Fortune 100 companies. His career has focused on emerging and niche technologies to major advancements in the industry - most notibly cloud.