Percona Xtrabackup is open source backup solution for Percona & mysql server. It will not block the database or very minimal lock while performing backup.
Installation using yum repository
1. First,installing yum repos.
1 |
yum install http://www.percona.com/downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm |
2.Check the required package
1 |
yum list | grep percona |
3.Finally, installing the package
1 |
yum install percona-xtrabackup-24 |
Taking Backup
First,creating a user for backup purpose
1 2 3 |
CREATE USER 'backup'@'localhost' IDENTIFIED BY 'Bkp@123'; GRANT RELOAD, LOCK TABLES, PROCESS, REPLICATION CLIENT ON *.* TO 'backup'@'localhost'; FLUSH PRIVILEGES; |
Now take backup using below command
It will create backup in /home/backup_folder/ directory
1 |
xtrabackup --backup --user=backup --password='Bkp@123' --datadir=/var/lib/mysql -S /var/lib/mysql/mysql.sock --target-dir=/home/backup_folder/ |
Restoration of Backup
First,we need to prepare our backup for restoration purpose
1 |
xtrabackup --user=backup --password='Bkp@123' --prepare --target-dir=/home/backup_folder/ |
Finally,restoring the prepared backup
1 |
xtrabackup --user=backup --password='Bkp@123' --copy-back --datadir=/var/lib/mysql --target-dir=/home/backup_folder/ |
or
1 |
rsync -avrP /home/backup_folder/ /var/lib/mysql/ |
Lastly giving mysql privilege to data directory
1 |
chown -R mysql:mysql /var/lib/mysql |
Ref:- https://www.percona.com/doc/percona-xtrabackup/LATEST/index.html