码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-05-10 14:50:48      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:backup   password   stream   position   created   

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


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


[root@localhost 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 user@www.magedu.com  "cat -  > /backups/`date +%F_%H-%M-%S`.tar" 


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


[root@localhost ~]# 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!


[root@localhost ~]# ls /tmp/

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


还原流归档


[root@localhost ~]# 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

.... 


[root@localhost ~]# ls /tmp/backup/

backup-my.cnf  mysql   percona             sakila  testdb                  xtrabackup_checkpoints  xtrabackup_logfile

ibdata1        pancou  performance_schema  test    xtrabackup_binlog_info  xtrabackup_info


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


[root@localhost ~]# 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!


[root@localhost ~]# 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


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


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

[root@localhost ~]# 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 --remote-host=root@www.magedu.com  /path/IN/REMOTE/HOST/to/backup


[root@localhost ~]# innobackupex --stream=xbstream --compress --user=backup --password=pancou /hotbackup/full/ |ssh -o StrictHostKeyChecking=no root@192.168.1.53 "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的“流”及“备份压缩”功能

标签:backup   password   stream   position   created   

原文地址:http://lijianmin2008.blog.51cto.com/621678/1924058

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!