mysql xtrabackup backup restore implementation share

  • 2020-05-14 05:04:43
  • OfStack

Introduction to the
Xtrabackup is the mysql database backup tool provided by percona. According to the official introduction, it is also one of only 11 open source tools in the world that can heat up the innodb and xtradb databases. Features:
(1) the backup process is fast and reliable;
(2) the backup process will not interrupt the transaction being executed;
(3) it can save disk space and traffic based on functions such as compression;
(4) automatic backup verification;
(5) fast reduction speed;
Xtrabackup includes two tools:
* xtrabackup - tool for hot backup of innodb, xtradb tables. Cannot backup other tables.
* innobackupex - the perl script encapsulated by xtrabackup provides the ability to backup MyISAM tables. (full library and data table backup).
When using innobakupex backup, it will call xtrabackup to backup all InnoDB tables and copy all relevant files about the table structure definition (.frm), as well as MyISAM, MERGE, CSV and ARCHIVE tables.
Files related to triggers and database configuration information are also backed up. These files will be saved to a directory with a time command.
Along with the backup, innobackupex will also create the following files in the backup directory:
(1)xtrabackup_checkpoints -- range information of backup type (such as full or incremental), backup status (such as whether it is already in prepared state) and LSN(log sequence number); Each InnoDB page (typically 16k size) contains a log sequence number, LSN. LSN is the system version number for the entire database system, and the LSN associated with each page can indicate how the page has changed recently.
(2)xtrabackup_binlog_info -- the location of the binary log file currently in use by the mysql server and the binary log events up to this point in the backup.
(3)xtrabackup_binlog_pos_innodb -- the current position of the binary log file used for the InnoDB or XtraDB tables.
(4)xtrabackup_binary -- the executable file of xtrabackup used in backup;
(5) backup-my.cnf -- configuration option information used by backup command;
When using innobackupex for backup, you can also use the -- no-timestamp option to prevent the command from automatically creating a directory named after the time. The innobackupex command will create an BACKUP-DIR directory to store the backup data.
The base 2 version
http://www.percona.com/downloads/XtraBackup/
wget http://www.percona.com/downloads/XtraBackup/LATEST/binary/Linux/x86_64/percona-xtrabackup-2.0.3-470.tar.gz
tar zxvf percona-xtrabackup-2.0.3-470.tar.gz
cd percona-xtrabackup-2.0.3/bin
cp * /usr/bin/
The installation of mysql 5.5.28 is not described here
Create a directory for data backup
mkdir -p /opt/mysql_bak/
Modify the database configuration file:
vim /etc/my.cnf
datadir = /home/mysql/data/
mysqladmin -uroot password 123456
Full library backup:
innobackupex --user=root --password=123456 --defaults-file=/etc/my.cnf /opt/mysql_bak/
Separate backup:
innobackupex --user=root --password=123456 --defaults-file=/etc/my.cnf --database=test /opt/mysql_bak
Backup and package compression:
innobackupex --user=root --password=123456 --defaults-file=/etc/my.cnf --database=test --stream=tar /opt/mysql_bak/ | gzip > /opt/mysql_bak/testdb.tar.gz
time-stamped
innobackupex --user=root --password=123456 --defaults-file=/etc/my.cnf --database=test --stream=tar /opt/mysql_bak/ | gzip > /opt/mysql_bak/`date +%F`_testdb.tar.gz

Related articles: