foreword
In the process of MySQL backup and building slave databases, we mostly use mysqldump for relatively small databases, which is simple and convenient. But when building a slave library in a large database, and the database host does not have a good storage to meet the backup requirements, you need to use innobackupex to assist you in making a backup, and you can even use it to build a MySQL slave library, which is very Simple.
1. MySQL innobackupex backup and recovery
1.1 Compress xbsteam to pack and compress for backup and recovery
- backup
innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --stream=xbstream --compress /data/backup/ > /data/backup/full.xbstream
- decompress xbstream
xbstream -x < /data/backup/full.xbstream -C /data/backup_qp/
- decompress qp
innobackupex --decompress /data/backup_qp
- delete qp file
find /data/backup -name "*.qp" | xargs rm
Note: If the report cannot find qpress, you need to install it first
qpress
1.2 Backup and restore using tar gzip
- backup
innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --stream=tar /data/backup/ |gzip > /data/backup/full.tar.gz
- unzip
tar -zxvf /data/backup/full.tar.gz -C /data/backup_targz
1.3 Backup and restore using tar bzip
- backup
innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --stream=tar /data/backup/ |bzip2 > /data/backup/full.tar.bz2
- unzip
tar -jxvf /data/backup/full.tar.gz -C /data/backup_tarbz
The sizes of various backup files are as follows. It is found that the compression method of bz2 is the smallest. There is still a big difference in the space occupied by uncompressed and compressed. It is recommended to use the compressed method.
2. MySQL is built from the library
2.1, xbsteam way backup, and then manually copy to the remote host
ref: Use innobackupex to build MySQL slave library
2.2, package in xbsteam mode and back up to the remote host through ssh and decompress
- perform backup
innobackupex --defaults-file=/etc/my.cnf --user=root --password='root' --stream=xbstream /tmp | ssh [email protected] "/app/percona/percona-xtrabackup-2.4.3-Linux-x86_64/bin/xbstream -x -C /data/mysql/data"
- If you find that innobackupex has been waiting for FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS, you can kill other connections
mysql -e "show processlist" | grep -v -i -e root -e id | awk '{printf "kill "$1";"}' | mysql
- The log is as follows:
161219 20:11:21 [00] Streaming xtrabackup_binlog_info 161219 20:11:21 [00] ...done 161219 20:11:21 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS... xtrabackup: The latest check point (for incremental): '6499141903477' xtrabackup: Stopping log copying thread. .161219 20:11:21 >> log scanned up to (6499141993412) 161219 20:11:23 Executing UNLOCK TABLES 161219 20:11:23 All tables unlocked 161219 20:11:23 [00] Streaming ib_buffer_pool to 161219 20:11:23 [00] ...done 161219 20:11:23 Backup created in directory '/tmp' MySQL binlog position: filename 'mysql-bin.001249', position '151576713', GTID of the last change '4d814c80-9dae-11e6-9711-005056bd55e1:1-113121904, 5f7b59b2-3e74-11e6-aa1d-005056bd55e1:27485200-29545503, db6a8610-9b3e-11e6-8730-005056bd2c74:1-221265164' 161219 20:11:23 [00] Streaming backup-my.cnf 161219 20:11:23 [00] ...done 161219 20:11:23 [00] Streaming xtrabackup_info 161219 20:11:23 [00] ...done xtrabackup: Transaction log of lsn (6498376046758) to (6499141993412) was copied. 161219 20:11:24 completed OK!
- Apply redo to the standby database
innobackupex --apply-log .
Note: If it cannot be found
xbsream
, you need to specify an absolute path, or configure the environment variable of ssh to let the SSH Server use a custom environment variable-winter.zhang-ChinaUnix Blog
2.3 Pack and compress in xbsteam mode (qpress) back up to a remote host through ssh and decompress
- perform backup
innobackupex --defaults-file=/etc/my.cnf --user=root --password='root' --stream=xbstream --compress /tmp | ssh [email protected] "/app/percona/percona-xtrabackup-2.4.3-Linux-x86_64/bin/xbstream -x -C /data/mysql/data"
- Decompression
If the xtrabackup version is greater than 2.1.4, you can directly decompress it in this wayinnobackupex --decompress /backup/bk_compress
- Apply redo to the standby database
innobackupex --apply-log .