Xtrabackup的“流”及“备份压缩”功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Xtrabackup的“流”及“备份压缩”功能相关的知识,希望对你有一定的参考价值。

Xtrabackup对备份的数据文件支持“流”功能,即可以将备份的数据通过STDOUT传输给tar程序进行归档,而不是默认的直接保存至某备份目录中。要使用此功能,仅需要使用--stream选项即可。如:


# innobackupex --stream=tar  /backup | gzip > /backup/`date +%F_%H-%M-%S`.tar.gz


[[email protected] opt]# innobackupex --stream=tar --user=backup --password=pancou /hotbackup/full/|gzip > /opt/full`date +%F_%H-%M-%S`.tar.gz

... ...

170428 13:40:24 Executing UNLOCK TABLES

170428 13:40:24 All tables unlocked

170428 13:40:24 Backup created in directory ‘/hotbackup/full/‘

mysql binlog position: filename ‘mysql-bin.000001‘, position ‘313‘, GTID of the last change ‘‘

170428 13:40:24 [00] Streaming backup-my.cnf

170428 13:40:24 [00]        ...done

170428 13:40:24 [00] Streaming xtrabackup_info

170428 13:40:24 [00]        ...done

xtrabackup: Transaction log of lsn (21898933) to (21898933) was copied.

170428 13:40:24 completed OK!


甚至也可以使用类似如下命令将数据备份至其它服务器:

# innobackupex --stream=tar  /backup | ssh [email protected]  "cat -  > /backups/`date +%F_%H-%M-%S`.tar" 


---------------------------------使用xbstream流备份:


[[email protected] ~]# innobackupex --stream=xbstream --user=backup --password=pancou /hotbackup/full/ > /tmp/full_`date +%F_%H-%M-%S`.xbs

170510 12:08:14 innobackupex: Starting the backup operation


IMPORTANT: Please check that the backup run completes successfully.

           At the end of a successful backup run innobackupex

           prints "completed OK!".

....        ......


170510 12:08:18 Executing UNLOCK TABLES

170510 12:08:18 All tables unlocked

170510 12:08:18 Backup created in directory ‘/hotbackup/full/‘

MySQL binlog position: filename ‘mysql-bin.000005‘, position ‘339748‘, GTID of the last change ‘0-2-960‘

170510 12:08:18 [00] Streaming backup-my.cnf

170510 12:08:18 [00]        ...done

170510 12:08:18 [00] Streaming xtrabackup_info

170510 12:08:18 [00]        ...done

xtrabackup: Transaction log of lsn (23216778) to (23216778) was copied.

170510 12:08:18 completed OK!


[[email protected] ~]# ls /tmp/

backup  full_2017-05-10_12-08-14.xbs  hsperfdata_nexus  keyring-KtDQQF  keyring-u5nHlu  mysql  percona-version-check  sakila.sql


还原流归档


[[email protected] ~]# xbstream -xv -C /tmp/backup/ </tmp/full_2017-05-10_12-08-14.xbs 

ibdata1

pancou/rpel_table.ibd

mysql/innodb_table_stats.ibd

mysql/gtid_slave_pos.ibd

.... 


[[email protected] ~]# ls /tmp/backup/

backup-my.cnf  mysql   percona             sakila  testdb                  xtrabackup_checkpoints  xtrabackup_logfile

ibdata1        pancou  performance_schema  test    xtrabackup_binlog_info  xtrabackup_info


------------------------------------------使用流压缩:


[[email protected] ~]# innobackupex --stream=xbstream --compress --user=backup --password=pancou /hotbackup/full/ > /tmp/full_`date +%F_%H-%M-%S`.xbs


170510 12:16:51 Executing UNLOCK TABLES

170510 12:16:51 All tables unlocked

170510 12:16:51 Backup created in directory ‘/hotbackup/full/‘

MySQL binlog position: filename ‘mysql-bin.000005‘, position ‘339748‘, GTID of the last change ‘0-2-960‘

170510 12:16:51 [00] Compressing and streaming backup-my.cnf

170510 12:16:51 [00]        ...done

170510 12:16:51 [00] Compressing and streaming xtrabackup_info

170510 12:16:51 [00]        ...done

xtrabackup: Transaction log of lsn (23216778) to (23216778) was copied.

170510 12:16:51 completed OK!


[[email protected] ~]# ll -h /tmp/

total 110M

drwxr-xr-x 9 root   root     4.0K May 10 12:09 backup

-rw-r--r-- 1 root   root     102M May 10 12:08 full_2017-05-10_12-08-14.xbs

-rw-r--r-- 1 root   root     4.8M May 10 12:16 full_2017-05-10_12-16-48.xbs


--------------------------------------------------解压缩


[[email protected] ~]# xbstream -xv -C /tmp/backup/ < /tmp/full_2017-05-10_12-16-48.xbs 

[[email protected] ~]# ls /tmp/backup/

backup-my.cnf.qp  mysql   percona             sakila  testdb                     xtrabackup_checkpoints  xtrabackup_logfile.qp

ibdata1.qp        pancou  performance_schema  test    xtrabackup_binlog_info.qp  xtrabackup_info.qp


-----------------------------------------------远程主机流压缩备份

同时,innobackupex备份的数据文件也可以存储至远程主机,这可以使用--remote-host选项来实现:

# innobackupex [email protected]  /path/IN/REMOTE/HOST/to/backup


[[email protected] ~]# innobackupex --stream=xbstream --compress --user=backup --password=pancou /hotbackup/full/ |ssh -o StrictHostKeyChecking=no [email protected] "cat - > /tmp/full_`date +%F_%H-%M-%S`.xbs"


此外,在执行本地备份时,还可以使用--parallel选项对多个文件进行并行复制。此选项用于指定在复制时启动的线程数目。当然,在实际进行备份时要利用此功能的便利性,也需要启用innodb_file_per_table选项或共享的表空间通过innodb_data_file_path选项存储在多个ibdata文件中。对某一数据库的多个文件的复制无法利用到此功能。其简单使用方法如下:

# innobackupex --parallel  /path/to/backup


本文出自 “linunx运维专题” 博客,请务必保留此出处http://lijianmin2008.blog.51cto.com/621678/1924058

以上是关于Xtrabackup的“流”及“备份压缩”功能的主要内容,如果未能解决你的问题,请参考以下文章

xtrabackup介绍及备份原理

XtraBackup原理解读

使用 xtrabackup 进行MySQL数据库物理备份

使用 xtrabackup 进行MySQL数据库物理备份

XtraBackup物理备份(未测试)

MySQL之XtraBackup实现完全备份增量备份数据还原