This guide looks into how to setup xtrabackup backup system for MariaDB on CentOS7, and how to full backup an MariaDB, and then restore the DB.
First thing, ensure the minimum setup for database config file:
[root@centos7 ~]# vi /etc/my.cnf
# # This group is read both both by the client and the server # use it for options that affect everything # [client-server] # # This group is read by the server # [mysqld] # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # # include all files from the config directory # !includedir /etc/my.cnf.d
[root@centos7 ~]# vi /etc/my.cnf.d/server.cnf
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock log-error=/var/log/mariadb/mariadb.log pid-file=/var/run/mariadb/mariadb.pidStart MariaDB/Mysql
[root@centos7 ~]# service mysql startInstall percona repository, and install xtrabackup
[root@centos7 ~]# yum install https://www.percona.com/redir/downloads/percona-release/redhat/latest/percona-release-0.1-3.noarch.rpm [root@centos7 ~]# yum list|grep percona [root@centos7 ~]# yum install percona-xtrabackupWe will create a backup directory
[root@centos7 ~]# mkdir /root/backupInstallation done. To proceed with Full backup,we need to issue the innobackupex, with the DB admin user and password, and also the backup directory.
[root@centos7 ~]# innobackupex --user=root --password=PASSWORD /root/backupTo get the backup information for a particular backup, we can check the xtrabackup_checkpoints file.
[root@centos7 backup]# cat /root/backup/2015-09-29_02-01-17/xtrabackup_checkpointsWe have done the Full backup. To restore a Full backup, we have to stop the MariaDB/Mysql server first.
[root@centos7 ~]# service mysql stopMove the current mysql data directory to somewhere.
[root@centos7 ~]# rm -fr /var/lib/mysql_old [root@centos7 ~]# mv /var/lib/mysql/ /var/lib/mysql_oldIssue the following command to restore.
[root@centos7 ~]# innobackupex --copy-back /root/backup/2015-09-29_02-01-17/Change back the ownership of the mysql data directory.
[root@centos7 ~]# chown mysql:mysql /var/lib/mysql -RAnd lastly, start the MariaDB/Mysql service.
[root@centos7 ~]# service mysql start