Using percona xtrabackup for backup

•

taking backup

percona xtrabackup is consider a hot backup that backup the whole data directory with its redo logs and also it will take backup of the my.cnf

to take backup we have already setup directory for backup

mkidr backup

33ce6fb2bf3e1ef1057bf4d18ebf6534.png

to take the backup we will use the below command which will also compress the backup

xtrabackup -uroot -p --compress --backup --target-dir=/backup

36258d83544c0c768429c5826cfede87.png

by the end of prompt you should receive LSN number .

f8f50a0cc891545925259498745c1360.png

restore backup

to restore backup we need to first prepare the backup .

Data files are not point-in-time consistent until they are prepared, because they were copied at different times as the program ran, and they might have been changed while this was happening.

If you try to start InnoDB with these data files, it will detect corruption and stop working to avoid running on damaged data. The –prepare step makes the files perfectly consistent at a single instant in time, so you can run InnoDB on them.

first we need to decompress the backup we can do so by using --decompress and also --remove-original which will proceed to remove compress files after decompress

xtrabackup -uroot -p --compress --backup --target-dir=/backup

c6a8c6e0667fd13944805e4eddccd14c.png

after that we can prepare the backup
xtrabackup -uroot -p --prepare --target-dir=/backup

18efc8af63ee8c23068d060a519ee9eb.png

to restore the backup first stop mysqld services
systemctl stop mysqld

ba85e348964344e5805e62b4d54f7d1f.png

next go to data directory and remove all the files in the data dir

cd /var/lib/mysql
rm -rf *

6ee1b16ce342aab9b6248da558267f4c.png

now we can copy the content of bacup to data dir
we can do it manully using cp
or use percona xtrabackup it self to copy the backup file to the data dir
xtrabackup will automatically detect the data dir path

xtrabackup --copy-back --target-dir=/backup

672498179b1a77a05abfd5893bbc18d6.png

after that change the owner of the files back to MySQL user

chown -R mysql:mysql /var/lib/mysql

now start mysqld services and it should start normally

476613accce87201352ea881ed22bc49.png