在日常的linux运维工作中,大数据量备份与还原,始终是个难点。关于mysql的备份和恢复,比较传统的是用mysqldump工具,今天这里推荐另一个备份工具innobackupex。innobackupex和mysqldump都可以对mysql进行热备份的,mysqldump对mysql的innodb的备份可以使用single-transaction参数来开启一个事务,利用innodb的mvcc来不进行锁表进行热备份,mysqldump备份是逻辑备份,备份出来的文件是sql语句,所以备份和恢复的时候很慢,但是备份和恢复时候很清楚。当MYSQL数据超过10G时,用mysqldump来导出备份就比较慢了,此种情况下用innobackupex这个工具就比mysqldump要快很多。利用它对mysql做全量和增量备份,仅仅依据本人实战操作做一记录,如有误述,敬请指出~
一、innobackupex的介绍
Xtrabackup是由percona开发的一个开源软件,是使用perl语言完成的脚本工具,能够非常快速地备份与恢复mysql数据库,且支持在线热备份(备份时不影响数据读写),此工具调用xtrabackup和tar4ibd工具,实现很多对性能要求并不高的任务和备份逻辑,可以说它是innodb热备工具ibbackup的一个开源替代品。
Xtrabackup中包含两个工具:1)xtrabackup :只能用于热备份innodb,xtradb两种数据引擎表的工具,不能备份其他表。2)innobackupex:是一个对xtrabackup封装的perl脚本,提供了用于myisam(会锁表)和innodb引擎,及混合使用引擎备份的能力。主要是为了方便同时备份InnoDB和MyISAM引擎的表,但在处理myisam时需要加一个读锁。并且加入了一些使用的选项。如slave-info可以记录备份恢 复后,作为slave需要的一些信息,根据这些信息,可以很方便的利用备份来重做slave。innobackupex比xtarbackup有更强的功能,它整合了xtrabackup和其他的一些功能,它不但可以全量备份/恢复,还可以基于时间的增量备份与恢复。innobackupex同时支持innodb,myisam。Xtrabackup可以做什么
1)在线(热)备份整个库的InnoDB, XtraDB表2)在xtrabackup的上一次整库备份基础上做增量备份(innodb only)3)以流的形式产生备份,可以直接保存到远程机器上(本机硬盘空间不足时很有用)MySQL数据库本身提供的工具并不支持真正的增量备份,二进制日志恢复是point-in-time(时间点)的恢复而不是增量备份。Xtrabackup工具支持对InnoDB存储引擎的增量备份,工作原理如下:
1)首先完成一个完全备份,并记录下此时检查点的LSN(Log Sequence Number)。2)在进程增量备份时,比较表空间中每个页的LSN是否大于上次备份时的LSN,如果是,则备份该页,同时记录当前检查点的LSN。首先,在logfile中找到并记录最后一个checkpoint(“last checkpoint LSN”),然后开始从LSN的位置开始拷贝InnoDB的logfile到xtrabackup_logfile;接着,开始拷贝全部的数据文件.ibd;在拷贝全部数据文件结束之后,才停止拷贝logfile。因为logfile里面记录全部的数据修改情况,所以,即时在备份过程中数据文件被修改过了,恢复时仍然能够通过解析xtrabackup_logfile保持数据的一致。innobackupex备份mysql数据的流程
innobackupex首先调用xtrabackup来备份innodb数据文件,当xtrabackup完成后,innobackupex就查看文件xtrabackup_suspended ;然后执行“FLUSH TABLES WITH READ LOCK”来备份其他的文件。innobackupex恢复mysql数据的流程
innobackupex首先读取my.cnf,查看变量(datadir,innodb_data_home_dir,innodb_data_file_path,innodb_log_group_home_dir)对应的目录是存在,确定相关目录存在后,然后先copy myisam表和索引,然后在copy innodb的表、索引和日志。------------------------------------------------------------------------------------------------------------------------------------------
下面详细说下innobackupex备份和恢复的工作原理:(1)备份的工作原理
如果在程序启动阶段未指定模式,innobackupex将会默认以备份模式启动。 默认情况下,此脚本以--suspend-at-end选项启动xtrabackup,然后xtrabackup程序开始拷贝InnoDB数据文件。当xtrabackup程序执行结束,innobackupex将会发现xtrabackup创建了xtrabackup_suspended_2文件,然后执行FLUSH TABLES WITH READ LOCK,此语句对所有的数据库表加读锁。然后开始拷贝其他类型的文件。 如果--ibbackup未指定,innobackupex将会自行尝试确定使用的xtrabackup的binary。其确定binary的逻辑如下:首先判断备份目录中xtrabackup_binary文件是否存在,如果存在,此脚本将会依据此文件确定使用的xtrabackup binary。否则,脚本将会尝试连接database server,通过server版本确定binary。如果连接无法建立,xtrabackup将会失败,需要自行指定binary文件。 在binary被确定后,将会检查到数据库server的连接是否可以建立。其执行逻辑是:建立连接、执行query、关闭连接。若一切正常,xtrabackup将以子进程的方式启动。 FLUSH TABLES WITH READ LOCK是为了备份MyISAM和其他非InnoDB类型的表,此语句在xtrabackup已经备份InnoDB数据和日志文件后执行。在这之后,将会备份 .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV, .par, and .opt 类型的文件。 当所有上述文件备份完成后,innobackupex脚本将会恢复xtrabackup的执行,等待其备份上述逻辑执行过程中生成的事务日志文件。接下来,表被解锁,slave被启动,到server的连接被关闭。接下来,脚本会删掉xtrabackup_suspended_2文件,允许xtrabackup进程退出。(2)恢复的工作原理 为了恢复一个备份,innobackupex需要以--copy-back选项启动。 innobackupex将会首先通过my.cnf文件读取如下变量:datadir, innodb_data_home_dir, innodb_data_file_path, innodb_log_group_home_dir,并确定这些目录存在。 接下来,此脚本将会首先拷贝MyISAM表、索引文件、其他类型的文件(如:.frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV, par and .opt files),接下来拷贝InnoDB表数据文件,最后拷贝日志文件。拷贝执行时将会保留文件属性,在使用备份文件启动MySQL前,可能需要更改文件的owener(如从拷贝文件的user更改到mysql用户)。---------------------------------------------------------------------------------------------------------------------------------------------二、innobackupex针对mysql数据库的备份环境部署
1)源码安装Xtrabackup,将源码包下载到/usr/local/src下源码包下载 [root@test-huanqiu ~]# cd /usr/local/src先安装依赖包[root@test-huanqiu src]# yum -y install cmake gcc gcc-c++ libaio libaio-devel automake autoconf bzr bison libtool zlib-devel libgcrypt-devel libcurl-devel crypt* libgcrypt* python-sphinx openssl imake libxml2-devel expat-devel ncurses5-devel ncurses-devle vim-common libgpg-error-devel libidn-devel perl-DBI perl-DBD-MySQL perl-Time-HiRes perl-IO-Socket-SSL [root@test-huanqiu src]# wget [root@test-huanqiu src]# tar -zvxf percona-xtrabackup-2.1.9.tar.gz[root@test-huanqiu src]# cd percona-xtrabackup-2.1.9[root@test-huanqiu percona-xtrabackup-2.1.9]# ./utils/build.sh //执行该安装脚本,会出现下面信息Build an xtrabackup binary against the specified InnoDB flavor.
Usage: build.sh CODEBASE
where CODEBASE can be one of the following values or aliases: innodb51 | plugin build against InnoDB plugin in MySQL 5.1 innodb55 | 5.5 build against InnoDB in MySQL 5.5 innodb56 | 5.6,xtradb56, build against InnoDB in MySQL 5.6 | mariadb100,galera56 xtradb51 | xtradb,mariadb51 build against Percona Server with XtraDB 5.1 | mariadb52,mariadb53 xtradb55 | galera55,mariadb55 build against Percona Server with XtraDB 5.5根据上面提示和你使用的存储引擎及版本,选择相应的参数即可。因为我用的是MySQL 5.6版本,所以执行如下语句安装:[root@test-huanqiu percona-xtrabackup-2.1.9]# ./utils/build.sh innodb56以上语句执行成功后,表示安装完成。最后,把生成的二进制文件拷贝到一个自定义目录下(本例中为/home/mysql/admin/bin/percona-xtrabackup-2.1.9),并把该目录放到环境变量PATH中。[root@test-huanqiu percona-xtrabackup-2.1.9]# mkdir -p /home/mysql/admin/bin/percona-xtrabackup-2.1.9/[root@test-huanqiu percona-xtrabackup-2.1.9]# cp ./innobackupex /home/mysql/admin/bin/percona-xtrabackup-2.1.9/[root@test-huanqiu percona-xtrabackup-2.1.9]# cp ./src/xtrabackup_56 ./src/xbstream /home/mysql/admin/bin/percona-xtrabackup-2.1.9/[root@test-huanqiu percona-xtrabackup-2.1.9]# vim /etc/profile.......export PATH=$PATH:/home/mysql/admin/bin/percona-xtrabackup-2.1.9/[root@test-huanqiu percona-xtrabackup-2.1.9]# source /etc/profile测试下innobackupex是否正常使用
[root@test-huanqiu percona-xtrabackup-2.1.9]# innobackupex --help--------------------------------------------------------------------------------------------------------------------------------------------可能报错1Can't locate Time/HiRes.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /home/mysql/admin/bin/percona-xtrabackup-2.1.9/innobackupex line 23.
BEGIN failed--compilation aborted at /home/mysql/admin/bin/percona-xtrabackup-2.1.9/innobackupex line 23.解决方案:
.pm实际上是Perl的包,只需安装perl-Time-HiRes即可:[root@test-huanqiu percona-xtrabackup-2.1.9]# yum install -y perl-Time-HiRes
可能报错2
Can't locate DBI.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /usr/local/webserver/mysql5.1.57/bin/mysqlhotcopy line 25. BEGIN failed--compilation aborted at /usr/local/webserver/mysql5.1.57/bin/mysqlhotcopy line 25. 报错原因:系统没有按安装DBI组件。DBI(Database Interface)是perl连接数据库的接口。其是perl连接数据库的最优秀方法,他支持包括Orcal,Sybase,mysql,db2等绝大多数的数据库。解决办法:
安装DBI组件(Can't locate DBI.pm in @INC-mysql接口)或者单独装DBI、Data-ShowTable、DBD-mysql 三个组件[root@test-huanqiu percona-xtrabackup-2.1.9]# yum -y install perl-DBD-MySQL接着使用innobackupex命令测试是否正常
[root@test-huanqiu percona-xtrabackup-2.1.9]# innobackupex --helpOptions: --apply-log Prepare a backup in BACKUP-DIR by applying the transaction log file named "xtrabackup_logfile" located in the same directory. Also, create new transaction logs. The InnoDB configuration is read from the file "backup-my.cnf".--compact
Create a compact backup with all secondary index pages omitted. This option is passed directly to xtrabackup. See xtrabackup documentation for details.--compress
This option instructs xtrabackup to compress backup copies of InnoDB data files. It is passed directly to the xtrabackup child process. Try 'xtrabackup --help' for more details.............-------------------------------------------------------------------------------------------------------------------------------------------------------------2)全量备份和恢复
---------------->全量备份操作<----------------执行下面语句进行全备:mysql的安装目录是/usr/local/mysqlmysql的配置文件路径/usr/local/mysql/my.cnfmysql的密码是123456全量备份后的数据存放目录是/backup/mysql/data [root@test-huanqiu ~]# mkdir -p /backup/mysql/data [root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 /backup/mysql/dataInnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona LLC and/or its affiliates 2009-2013. All Rights Reserved....................161201 00:07:15 innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/usr/local/mysql/my.cnf;mysql_read_default_group=xtrabackup' as 'root' (using password: YES).161201 00:07:15 innobackupex: Connected to MySQL server161201 00:07:15 innobackupex: Executing a version check against the server...161201 00:07:15 innobackupex: Done...................161201 00:07:19 innobackupex: Connection to database server closed161201 00:07:19 innobackupex: completed OK!出现上面的信息,表示备份已经ok。
上面执行的备份语句会将mysql数据文件(即由my.cnf里的变量datadir指定)拷贝至备份目录下(/backup/mysql/data)
注意:如果不指定--defaults-file,默认值为/etc/my.cnf。备份成功后,将在备份目录下创建一个时间戳目录(本例创建的目录为/backup/mysql/data/2016-12-01_00-07-15),在该目录下存放备份文件。查看备份数据:
[root@test-huanqiu ~]# ll /backup/mysql/data total 4drwxr-xr-x. 6 root root 4096 Dec 1 00:07 2016-12-01_00-07-15[root@test-huanqiu ~]# ll /backup/mysql/data/2016-12-01_00-07-15/total 12324-rw-r--r--. 1 root root 357 Dec 1 00:07 backup-my.cnfdrwx------. 2 root root 4096 Dec 1 00:07 huanqiu-rw-r-----. 1 root root 12582912 Dec 1 00:07 ibdata1drwx------. 2 root root 4096 Dec 1 00:07 mysqldrwxr-xr-x. 2 root root 4096 Dec 1 00:07 performance_schemadrwxr-xr-x. 2 root root 4096 Dec 1 00:07 test-rw-r--r--. 1 root root 13 Dec 1 00:07 xtrabackup_binary-rw-r--r--. 1 root root 24 Dec 1 00:07 xtrabackup_binlog_info-rw-r-----. 1 root root 89 Dec 1 00:07 xtrabackup_checkpoints-rw-r-----. 1 root root 2560 Dec 1 00:07 xtrabackup_logfile----------------------------------------------------------------------------------------------------------------------------------
可能报错1:161130 05:56:48 innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/usr/local/mysql/my.cnf;mysql_read_default_group=xtrabackup' as 'root' (using password: YES).innobackupex: Error: Failed to connect to MySQL server as DBD::mysql module is not installed at /home/mysql/admin/bin/percona-xtrabackup-2.1.9/innobackupex line 2956.解决办法:
[root@test-huanqiu ~]# yum -y install perl-DBD-MySQL.x86_64 ......Package perl-DBD-MySQL-4.013-3.el6.x86_64 already installed and latest version //发现本机已经安装了[root@test-huanqiu ~]# rpm -qa|grep perl-DBD-MySQL
perl-DBD-MySQL-4.013-3.el6.x86_64发现本机已经安装了最新版的perl-DBD-MYSQL了,但是仍然报出上面的错误!!
莫慌~~继续下面的操作进行问题的解决查看mysql.so依赖的lib库
[root@test-huanqiu ~]# ldd /usr/lib64/perl5/auto/DBD/mysql/mysql.so linux-vdso.so.1 => (0x00007ffd291fc000) libmysqlclient.so.16 => not found //这一项为通过检查,缺失libmysqlclient.so.16库导致 libz.so.1 => /lib64/libz.so.1 (0x00007f78ff9de000) libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f78ff7a7000) libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f78ff58e000) libm.so.6 => /lib64/libm.so.6 (0x00007f78ff309000) libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007f78ff09d000) libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f78fecb9000) libc.so.6 => /lib64/libc.so.6 (0x00007f78fe924000) libfreebl3.so => /lib64/libfreebl3.so (0x00007f78fe721000) libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f78fe4dd000) libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f78fe1f5000) libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f78fdff1000) libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f78fddc5000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f78fdbc0000) /lib64/ld-linux-x86-64.so.2 (0x00007f78ffe1d000) libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f78fd9b5000) libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f78fd7b2000) libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f78fd597000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f78fd37a000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f78fd15a000)以上结果说明缺少libmysqlclient.so.16这个二进制包,找个官方原版的mysql的libmysqlclient.so.16替换了即可!
[root@test-huanqiu~]# find / -name libmysqlclient.so.16 //查看本机并没有libmysqlclient.so.16库文件查看mysql/lib下的libmysqlclinet.so库文件
[root@test-huanqiu~]# ll /usr/local/mysql/lib/total 234596-rw-r--r--. 1 mysql mysql 19520800 Nov 29 12:27 libmysqlclient.alrwxrwxrwx. 1 mysql mysql 16 Nov 29 12:34 libmysqlclient_r.a -> libmysqlclient.alrwxrwxrwx. 1 mysql mysql 17 Nov 29 12:34 libmysqlclient_r.so -> libmysqlclient.solrwxrwxrwx. 1 mysql mysql 20 Nov 29 12:34 libmysqlclient_r.so.18 -> libmysqlclient.so.18lrwxrwxrwx. 1 mysql mysql 24 Nov 29 12:34 libmysqlclient_r.so.18.1.0 -> libmysqlclient.so.18.1.0lrwxrwxrwx. 1 mysql mysql 20 Nov 29 12:34 libmysqlclient.so -> libmysqlclient.so.18lrwxrwxrwx. 1 mysql mysql 24 Nov 29 12:34 libmysqlclient.so.18 -> libmysqlclient.so.18.1.0-rwxr-xr-x. 1 mysql mysql 8858235 Nov 29 12:27 libmysqlclient.so.18.1.0-rw-r--r--. 1 mysql mysql 211822074 Nov 29 12:34 libmysqld.a-rw-r--r--. 1 mysql mysql 14270 Nov 29 12:27 libmysqlservices.adrwxr-xr-x. 3 mysql mysql 4096 Nov 29 12:34 plugin将mysql/lib/libmysqlclient.so.18.1.0库文件拷贝到/lib64下,拷贝后命名为libmysqlclient.so.16
[root@test-huanqiu~]# cp /usr/local/mysql/lib/libmysqlclient.so.18.1.0 /lib64/libmysqlclient.so.16[root@test-huanqiu~]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf/usr/local/mysql/lib/ /lib64/[root@test-huanqiu~]# ldconfig最后卸载perl-DBD-MySQL,并重新安装perl-DBD-MySQL
[root@test-huanqiu~]# rpm -qa|grep perl-DBD-MySQLperl-DBD-MySQL-4.013-3.el6.x86_64[root@test-huanqiu~]# rpm -e --nodeps perl-DBD-MySQL [root@test-huanqiu~]# rpm -qa|grep perl-DBD-MySQL[root@test-huanqiu~]# yum -y install perl-DBD-MySQL待重新安装后,再次重新检查mysql.so依赖的lib库,发现已经都通过了
[root@test-huanqiu~]# ldd /usr/lib64/perl5/auto/DBD/mysql/mysql.so linux-vdso.so.1 => (0x00007ffe3669b000) libmysqlclient.so.16 => /usr/lib64/mysql/libmysqlclient.so.16 (0x00007f4af5c25000) libz.so.1 => /lib64/libz.so.1 (0x00007f4af5a0f000) libcrypt.so.1 => /lib64/libcrypt.so.1 (0x00007f4af57d7000) libnsl.so.1 => /lib64/libnsl.so.1 (0x00007f4af55be000) libm.so.6 => /lib64/libm.so.6 (0x00007f4af533a000) libssl.so.10 => /usr/lib64/libssl.so.10 (0x00007f4af50cd000) libcrypto.so.10 => /usr/lib64/libcrypto.so.10 (0x00007f4af4ce9000) libc.so.6 => /lib64/libc.so.6 (0x00007f4af4955000) libfreebl3.so => /lib64/libfreebl3.so (0x00007f4af4751000) libgssapi_krb5.so.2 => /lib64/libgssapi_krb5.so.2 (0x00007f4af450d000) libkrb5.so.3 => /lib64/libkrb5.so.3 (0x00007f4af4226000) libcom_err.so.2 => /lib64/libcom_err.so.2 (0x00007f4af4021000) libk5crypto.so.3 => /lib64/libk5crypto.so.3 (0x00007f4af3df5000) libdl.so.2 => /lib64/libdl.so.2 (0x00007f4af3bf1000) /lib64/ld-linux-x86-64.so.2 (0x00007f4af61d1000) libkrb5support.so.0 => /lib64/libkrb5support.so.0 (0x00007f4af39e5000) libkeyutils.so.1 => /lib64/libkeyutils.so.1 (0x00007f4af37e2000) libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f4af35c8000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f4af33aa000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f4af318b000)可能报错2
sh: xtrabackup_56: command not foundinnobackupex: Error: no 'mysqld' group in MySQL options at /home/mysql/admin/bin/percona-xtrabackup-2.1.9/innobackupex line 4350.有可能是percona-xtrabackup编译安装后,在编译目录的src下存在xtrabackup_innodb56,只需要其更名为xtrabackup_56,然后拷贝到上面的/home/mysql/admin/bin/percona-xtrabackup-2.1.9/下即可!
----------------------------------------------------------------------------------------------------------------------------------还可以在远程进行全量备份,命令如下:
[root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 --host=127.0.0.1 --parallel=2 --throttle=200 /backup/mysql/data 2>/backup/mysql/data/bak.log 1>/backup/mysql/data/`data +%Y-%m-%d_%H-%M%S`参数解释:--user=root 备份操作用户名,一般都是root用户 --password=root123 数据库密码--host=127.0.0.1 主机ip,本地可以不加(适用于远程备份)。注意要提前在mysql中授予连接的权限,最好备份前先测试用命令中的用户名、密码和host能否正常连接mysql。--parallel=2 --throttle=200 并行个数,根据主机配置选择合适的,默认是1个,多个可以加快备份速度。/backup/mysql/data 备份存放的目录2>/backup/mysql/data/bak.log 备份日志,将备份过程中的输出信息重定向到bak.log这种备份跟上面相比,备份成功后,不会自动在备份目录下创建一个时间戳目录,需要如上命令中自己定义。
[root@test-huanqiu ~]# cd /backup/mysql/data/[root@test-huanqiu data]# lldrwxr-xr-x. 6 root root 4096 Dec 1 03:18 2016-12-01_03-18-37-rw-r--r--. 1 root root 5148 Dec 1 03:18 bak.log[root@test-huanqiu data]# cat bak.log //备份信息都记录在这个日志里,如果备份失败,可以到这里日志里查询----------------------------------------------------------------------------------------------------------------------------
---------------->全量备份后的恢复操作<----------------
比如在上面进行全量备份后,由于误操作将数据库中的huanqiu库删除了。
[root@test-huanqiu ~]# mysql -p123456.......mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || huanqiu || mysql || performance_schema || test |+--------------------+5 rows in set (0.00 sec)mysql> use huanqiu;
Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed
mysql> show tables;+-------------------------+| Tables_in_huanqiu |+-------------------------+| card_agent_file || product_sale_management |+-------------------------+2 rows in set (0.00 sec)mysql> drop database huanqiu;
Query OK, 2 rows affected (0.12 sec)mysql> show databases;
+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.00 sec)现在进行恢复数据操作
注意:恢复之前1)要先关闭数据库2)要删除数据文件和日志文件(也可以mv移到别的地方,只要确保清空mysql数据存放目录就行)[root@test-huanqiu ~]# ps -ef|grep mysqlroot 2442 21929 0 00:25 pts/2 00:00:00 grep mysqlroot 28279 1 0 Nov29 ? 00:00:00 /bin/sh /usr/local/mysql//bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/data/mysql/data/mysql.pidmysql 29059 28279 0 Nov29 ? 00:09:07 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql/data --plugin-dir=/usr/local/mysql//lib/plugin --user=mysql --log-error=/data/mysql/data/mysql-error.log --pid-file=/data/mysql/data/mysql.pid --socket=/usr/local/mysql/var/mysql.sock --port=3306由上面可查出mysql的数据和日志存放目录是/data/mysql/data
[root@test-huanqiu ~]# /etc/init.d/mysql stopShutting down MySQL.. SUCCESS! [root@test-huanqiu ~]# rm -rf /data/mysql/data/*[root@test-huanqiu ~]# ls /data/mysql/data[root@test-huanqiu ~]#查看备份数据
[root@[root@test-huanqiu ~]# ls /backup/mysql/data/2016-12-01_00-07-15恢复数据
[root@[root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 --use-memory=4G --apply-log /backup/mysql/data/2016-12-01_00-07-15[root@[root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 --copy-back /backup/mysql/data/2016-12-01_00-07-15........innobackupex: Copying '/backup/mysql/data/2016-12-01_00-07-15/ib_logfile2' to '/data/mysql/data/ib_logfile2'innobackupex: Copying '/backup/mysql/data/2016-12-01_00-07-15/ib_logfile0' to '/data/mysql/data/ib_logfile0'innobackupex: Finished copying back files.161201 00:31:33 innobackupex: completed OK!
出现上面的信息,说明数据恢复成功了!!从上面的恢复操作可以看出,执行恢复分为两个步骤:
1)第一步恢复步骤是应用日志(apply-log),为了加快速度,一般建议设置--use-memory(如果系统内存充足,可以使用加大内存进行备份 ),这个步骤完成之后,目录/backup/mysql/data/2016-12-01_00-07-15下的备份文件已经准备就绪。2)第二步恢复步骤是拷贝文件(copy-back),即把备份文件拷贝至原数据目录下。恢复完成之后,一定要记得检查数据目录的所有者和权限是否正确。[root@test-huanqiu ~]# ll /data/mysql/data/
total 110608drwxr-xr-x. 2 root root 4096 Dec 1 00:31 huanqiu-rw-r--r--. 1 root root 12582912 Dec 1 00:31 ibdata1-rw-r--r--. 1 root root 33554432 Dec 1 00:31 ib_logfile0-rw-r--r--. 1 root root 33554432 Dec 1 00:31 ib_logfile1-rw-r--r--. 1 root root 33554432 Dec 1 00:31 ib_logfile2drwxr-xr-x. 2 root root 4096 Dec 1 00:31 mysqldrwxr-xr-x. 2 root root 4096 Dec 1 00:31 performance_schemadrwxr-xr-x. 2 root root 4096 Dec 1 00:31 test[root@test-huanqiu ~]# chown -R mysql.mysql /data/mysql/data/ //将数据目录的权限修改为mysql:mysql [root@test-huanqiu ~]# ll /data/mysql/data/total 110608drwxr-xr-x. 2 mysql mysql 4096 Dec 1 00:31 huanqiu-rw-r--r--. 1 mysql mysql 12582912 Dec 1 00:31 ibdata1-rw-r--r--. 1 mysql mysql 33554432 Dec 1 00:31 ib_logfile0-rw-r--r--. 1 mysql mysql 33554432 Dec 1 00:31 ib_logfile1-rw-r--r--. 1 mysql mysql 33554432 Dec 1 00:31 ib_logfile2drwxr-xr-x. 2 mysql mysql 4096 Dec 1 00:31 mysqldrwxr-xr-x. 2 mysql mysql 4096 Dec 1 00:31 performance_schemadrwxr-xr-x. 2 mysql mysql 4096 Dec 1 00:31 test-------------------------------------------------------------------------------------------------------------------------------------------可能报错:sh: xtrabackup: command not foundinnobackupex: Error: no 'mysqld' group in MySQL options at /home/mysql/admin/bin/percona-xtrabackup-2.1.9/innobackupex line 4350.解决:将xtrabackup_56复制成xtrabackup即可
[root@test-huanqiu percona-xtrabackup-2.1.9]# lsinnobackupex xbstream xtrabackup_56[root@test-huanqiu percona-xtrabackup-2.1.9]# cp xtrabackup_56 xtrabackup[root@test-huanqiu percona-xtrabackup-2.1.9]# lsinnobackupex xbstream xtrabackup xtrabackup_56-------------------------------------------------------------------------------------------------------------------------------------------最后,启动mysql,查看数据是否恢复回来了
[root@test-huanqiu ~]# /etc/init.d/mysql startStarting MySQL.. SUCCESS! [root@test-huanqiu ~]# mysql -p123456........mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || huanqiu || mysql || performance_schema || test |+--------------------+5 rows in set (0.00 sec)mysql> use huanqiu;
Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changed
mysql> show tables;+-------------------------+| Tables_in_huanqiu |+-------------------------+| card_agent_file || product_sale_management |+-------------------------+2 rows in set (0.00 sec)mysql>
3)增量备份和恢复
---------------->增量备份操作<----------------特别注意:innobackupex 增量备份仅针对InnoDB这类支持事务的引擎,对于MyISAM等引擎,则仍然是全备。增量备份需要基于全量备份
先假设我们已经有了一个全量备份(如上面的/backup/mysql/data/2016-12-01_00-07-15),我们需要在该全量备份的基础上做第一次增量备份。[root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 --incremental-basedir=/backup/mysql/data/2016-12-01_00-07-15 --incremental /backup/mysql/data 其中:--incremental-basedir 指向全量备份目录--incremental 指向增量备份的目录上面语句执行成功之后,会在--incremental执行的目录下创建一个时间戳子目录(本例中为:/backup/mysql/data/2016-12-01_01-12-22),在该目录下存放着增量备份的所有文件。[root@test-huanqiu ~]# ll /backup/mysql/data/total 8drwxr-xr-x. 6 root root 4096 Dec 1 00:27 2016-12-01_00-07-15 //全量备份目录drwxr-xr-x. 6 root root 4096 Dec 1 01:12 2016-12-01_01-12-22 //增量备份目录在备份目录下,有一个文件xtrabackup_checkpoints记录着备份信息,其中可以查出
1)全量备份的信息如下:[root@test-huanqiu 2016-12-01_00-07-15]# pwd/backup/mysql/data/2016-12-01_00-07-15[root@test-huanqiu 2016-12-01_00-07-15]# cat xtrabackup_checkpoints backup_type = full-preparedfrom_lsn = 0to_lsn = 1631561last_lsn = 1631561compact = 02)基于以上全量备份的增量备份的信息如下:
[root@test-huanqiu 2016-12-01_01-12-22]# pwd/backup/mysql/data/2016-12-01_01-12-22[root@test-huanqiu 2016-12-01_01-12-22]# cat xtrabackup_checkpoints backup_type = incrementalfrom_lsn = 1631561to_lsn = 1631776last_lsn = 1631776compact = 0从上面可以看出,增量备份的from_lsn正好等于全备的to_lsn。
那么,我们是否可以在增量备份的基础上再做增量备份呢?答案是肯定的,只要把--incremental-basedir执行上一次增量备份的目录即可,如下所示:[root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 --incremental-basedir=/backup/mysql/data/2016-12-01_01-12-22 --incremental /backup/mysql/data [root@test-huanqiu data]# lltotal 12drwxr-xr-x. 6 root root 4096 Dec 1 00:27 2016-12-01_00-07-15 //全量备份目录drwxr-xr-x. 6 root root 4096 Dec 1 01:12 2016-12-01_01-12-22 //增量备份目录1drwxr-xr-x. 6 root root 4096 Dec 1 01:23 2016-12-01_01-23-23 //增量备份目录2它的xtrabackup_checkpoints记录着备份信息如下:
[root@test-huanqiu 2016-12-01_01-23-23]# pwd/backup/mysql/data/2016-12-01_01-23-23[root@test-huanqiu 2016-12-01_01-23-23]# cat xtrabackup_checkpoints backup_type = incrementalfrom_lsn = 1631776to_lsn = 1638220last_lsn = 1638220compact = 0可以看到,第二次增量备份的from_lsn是从上一次增量备份的to_lsn开始的。
---------------->增量备份后的恢复操作<----------------
增量备份的恢复要比全量备份复杂很多,增量备份与全量备份有着一些不同,尤其要注意的是:1)需要在每个备份(包括完全和各个增量备份)上,将已经提交的事务进行“重放”。“重放”之后,所有的备份数据将合并到完全备份上。2)基于所有的备份将未提交的事务进行“回滚”。于是,操作就变成了:不能回滚,因为有可能第一次备份时候没提交,在增量中已经成功提交第一步是在所有备份目录下重做已提交的日志(注意备份目录路径要跟全路径)
1)innobackupex --apply-log --redo-only BASE-DIR 2)innobackupex --apply-log --redo-only BASE-DIR --incremental-dir=INCREMENTAL-DIR-1 3)innobackupex --apply-log BASE-DIR --incremental-dir=INCREMENTAL-DIR-2 其中:BASE-DIR 是指全量备份的目录INCREMENTAL-DIR-1 是指第一次增量备份的目录INCREMENTAL-DIR-2 是指第二次增量备份的目录,以此类推。这里要注意的是:1)最后一步的增量备份并没有--redo-only选项!回滚进行崩溃恢复过程2)可以使用--use_memory提高性能。以上语句执行成功之后,最终数据在BASE-DIR(即全量目录)下,其实增量备份就是把增量目录下的数据,整合到全变量目录下,然后在进行,全数据量的还原。第一步完成之后,我们开始下面关键的第二步,即拷贝文件,进行全部还原!注意:必须先停止mysql数据库,然后清空数据库目录(这里是指/data/mysql/data)下的文件。
4)innobackupex --copy-back BASE-DIR
同样地,拷贝结束之后,记得检查下数据目录(这里指/data/mysql/data)的权限是否正确(修改成mysql:mysql),然后再重启mysql。接下来进行案例说明:
假设我们已经有了一个全量备份2016-12-01_00-07-15删除在上面测试创建的两个增量备份[root@test-huanqiu ~]# cd /backup/mysql/data/[root@test-huanqiu data]# lltotal 12drwxr-xr-x. 6 root root 4096 Dec 1 00:27 2016-12-01_00-07-15drwxr-xr-x. 6 root root 4096 Dec 1 01:12 2016-12-01_01-12-22drwxr-xr-x. 6 root root 4096 Dec 1 01:23 2016-12-01_01-23-23[root@test-huanqiu data]# rm -rf 2016-12-01_01-12-22/[root@test-huanqiu data]# rm -rf 2016-12-01_01-23-23/[root@test-huanqiu data]# lltotal 4drwxr-xr-x. 6 root root 4096 Dec 1 00:27 2016-12-01_00-07-15假设在全量备份后,mysql数据库中又有新数据写入
[root@test-huanqiu ~]# mysql -p123456.........mysql> create database ceshi;Query OK, 1 row affected (0.00 sec)mysql> use ceshi;
Database changedmysql> create table test1( -> id int3, -> name varchar(20) -> );Query OK, 0 rows affected (0.07 sec)mysql> insert into test1 values(1,"wangshibo");
Query OK, 1 row affected, 1 warning (0.03 sec)mysql> select * from test1;
+------+-----------+| id | name |+------+-----------+| 1 | wangshibo |+------+-----------+1 row in set (0.00 sec)mysql> show databases;
+--------------------+| Database |+--------------------+| information_schema || ceshi || huanqiu || mysql || performance_schema || test |+--------------------+6 rows in set (0.00 sec)mysql>
然后进行一次增量备份:
[root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 --incremental-basedir=/backup/mysql/data/2016-12-01_00-07-15 --incremental /backup/mysql/data[root@test-huanqiu ~]# ll /backup/mysql/data/total 8drwxr-xr-x. 6 root root 4096 Dec 1 00:27 2016-12-01_00-07-15 //全量备份目录drwxr-xr-x. 7 root root 4096 Dec 1 03:41 2016-12-01_03-41-41 //增量备份目录接着再在mysql数据库中写入新数据
mysql> insert into test1 values(2,"guohuihui");Query OK, 1 row affected, 1 warning (0.00 sec)mysql> insert into test1 values(3,"wuxiang");
Query OK, 1 row affected, 1 warning (0.00 sec)mysql> insert into test1 values(4,"liumengnan");
Query OK, 1 row affected, 1 warning (0.01 sec)mysql> select * from test1;
+------+------------+| id | name |+------+------------+| 1 | wangshibo || 2 | guohuihui || 3 | wuxiang || 4 | liumengnan |+------+------------+4 rows in set (0.00 sec)接着在增量的基础上再进行一次增量备份
[root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 --incremental-basedir=/backup/mysql/data/2016-12-01_03-41-41 --incremental /backup/mysql/data [root@test-huanqiu ~]# ll /backup/mysql/data/total 12drwxr-xr-x. 6 root root 4096 Dec 1 00:27 2016-12-01_00-07-15 //全量备份目录drwxr-xr-x. 7 root root 4096 Dec 1 02:24 2016-12-01_02-24-11 //增量备份目录1drwxr-xr-x. 7 root root 4096 Dec 1 03:42 2016-12-01_03-42-43 //增量备份目录2现在删除数据库huanqiu、ceshi
mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || ceshi || huanqiu || mysql || performance_schema || test |+--------------------+6 rows in set (0.00 sec)mysql> drop database huanqiu;
Query OK, 2 rows affected (0.02 sec)mysql> drop database ceshi;
Query OK, 1 row affected (0.01 sec)mysql> show databases;
+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || test |+--------------------+4 rows in set (0.00 sec)mysql>
接下来就开始进行数据恢复操作:
先恢复应用日志(注意最后一个不需要加--redo-only参数)
[root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 --apply-log --redo-only /backup/mysql/data/2016-12-01_00-07-15[root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 --apply-log --redo-only /backup/mysql/data/2016-12-01_00-07-15 --incremental-dir=/backup/mysql/data/2016-12-01_02-24-11[root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 --apply-log /backup/mysql/data/2016-12-01_00-07-15 --incremental-dir=/backup/mysql/data/2016-12-01_03-42-43到此,恢复数据工作还没有结束!还有最重要的一个环节,就是把增量目录下的数据整合到全量备份目录下,然后再进行一次全量还原。
停止mysql数据库,并清空数据目录[root@test-huanqiu ~]# /etc/init.d/mysql stop[root@test-huanqiu ~]# rm -rf /data/mysql/data/*最后拷贝文件,并验证数据目录的权限
[root@test-huanqiu ~]# innobackupex --defaults-file=/usr/local/mysql/my.cnf --user=root --password=123456 --copy-back /backup/mysql/data/2016-12-01_00-07-15[root@test-huanqiu ~]# chown -R mysql.mysql /data/mysql/data/*
[root@test-huanqiu ~]# /etc/init.d/mysql start最后,检查下数据是否恢复
[root@test-huanqiu ~]# mysql -p123456........mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || ceshi || huanqiu || mysql || performance_schema || test |+--------------------+6 rows in set (0.00 sec)mysql> select * from ceshi.test1;+------+------------+| id | name |+------+------------+| 1 | wangshibo || 2 | guohuihui || 3 | wuxiang || 4 | liumengnan |+------+------------+4 rows in set (0.00 sec)
另外注意:
上面在做备份的时候,将备份目录和增量目录都放在了同一个目录路径下,其实推荐放在不同的路径下,方便管理!比如:/backup/mysql/data/full 存放全量备份目录/backup/mysql/data/daily1 存放第一次增量备份目录/backup/mysql/data/daily2 存放第二次增量目录以此类推在恢复的时候,注意命令中的路径要跟对!
-----------------------------------------------------------------------------------------------------
innobackupex 常用参数说明--defaults-file同xtrabackup的--defaults-file参数--apply-log
对xtrabackup的--prepare参数的封装--copy-back
做数据恢复时将备份数据文件拷贝到MySQL服务器的datadir ;--remote-host=HOSTNAME
通过ssh将备份数据存储到进程服务器上;--stream=[tar]
备 份文件输出格式, tar时使用tar4ibd , 该文件可在XtarBackup binary文件中获得.如果备份时有指定--stream=tar, 则tar4ibd文件所处目录一定要在$PATH中(因为使用的是tar4ibd去压缩, 在XtraBackup的binary包中可获得该文件)。在 使用参数stream=tar备份的时候,你的xtrabackup_logfile可能会临时放在/tmp目录下,如果你备份的时候并发写入较大的话 xtrabackup_logfile可能会很大(5G+),很可能会撑满你的/tmp目录,可以通过参数--tmpdir指定目录来解决这个问题。--tmpdir=DIRECTORY
当有指定--remote-host or --stream时, 事务日志临时存储的目录, 默认采用MySQL配置文件中所指定的临时目录tmpdir--redo-only --apply-log组,
强制备份日志时只redo ,跳过rollback。这在做增量备份时非常必要。--use-memory=#
该参数在prepare的时候使用,控制prepare时innodb实例使用的内存量--throttle=IOS
同xtrabackup的--throttle参数--sleep=是给ibbackup使用的,指定每备份1M数据,过程停止拷贝多少毫秒,也是为了在备份时尽量减小对正常业务的影响,具体可以查看ibbackup的手册 ;
--compress[=LEVEL]
对备份数据迚行压缩,仅支持ibbackup,xtrabackup还没有实现;--include=REGEXP
对 xtrabackup参数--tables的封装,也支持ibbackup。备份包含的库表,例如:--include="test.*",意思是要备份 test库中所有的表。如果需要全备份,则省略这个参数;如果需要备份test库下的2个表:test1和test2,则写 成:--include="test.test1|test.test2"。也可以使用通配符,如:--include="test.test*"。--databases=LIST
列出需要备份的databases,如果没有指定该参数,所有包含MyISAM和InnoDB表的database都会被备份;--uncompress
解压备份的数据文件,支持ibbackup,xtrabackup还没有实现该功能;--slave-info,
备 份从库, 加上--slave-info备份目录下会多生成一个xtrabackup_slave_info 文件, 这里会保存主日志文件以及偏移, 文件内容类似于:CHANGE MASTER TO MASTER_LOG_FILE='', MASTER_LOG_POS=0--socket=SOCKET
指定mysql.sock所在位置,以便备份进程登录mysql.三、innobackupex全量、增量备份脚本
可以根据自己线上数据库情况,编写全量和增量备份脚本,然后结合crontab设置计划执行。
比如:每周日的1:00进行全量备份,每周1-6的1:00进行增量备份。还可以在脚本里编写邮件通知信息(可以用mail或sendemail)==================================================================
在使用xtrabackup对mysql执行备份操作的时候,出现下面的报错:.....................xtrabackup: innodb_log_file_size = 50331648InnoDB: Error: log file ./ib_logfile0 is of different size 33554432 bytesInnoDB: than specified in the .cnf file 50331648 bytes!解决办法:可以计算一下33554432的大小,33554432/1024/1024=32查看my.cnf配置文件的innodb_log_file_size参数配置:innodb_log_file_size = 32M需要调整这个文件的大小再计算一下50331648的大小,50331648/1024/1024=48修改my.cnf配置文件的下面一行参数值:innodb_log_file_size = 48M然后重启mysql
============下面是曾经使用过的一个mysql通过innobackupex进行增量备份脚本===========
[root@mysql-node ~]# cat /data/backup/script/incremental-backup-mysql.sh#!/bin/sh########################################################################### Description: Mysql增量备份脚本## File Name: incremental-backup-mysql.sh## Author: wangshibo## mail: wangshibo@kevin.com## Created Time: 2018年1月11日 14:17:09##########################################################################today=`date +%Y%m%d`datetime=`date +%Y%m%d-%H-%M-%S`config=/etc/my.cnfbasePath=/data/backuplogfilePath=$basePath/logslogfile=$logfilePath/incr_$datetime.logUSER=mybakPASSWD=Mysql@!@#1988checkdataBases="activiti batchdb core scf_v2 midfax asset bc_asset"pid=`ps -ef | grep -v "grep" |grep -i innobackupex|awk '{print $2}'|head -n 1`if [ -z $pid ]then echo " start incremental backup database " >> $logfile OneMonthAgo=`date -d "1 month ago" +%Y%m%d` path=$basePath/incr_$datetime mkdir -p $path last_backup=`cat $logfilePath/last_backup_sucess.log| head -1` echo " last backup is ===> " $last_backup >> $logfile sudo /data/backup/script/percona-xtrabackup-2.4.2-Linux-x86_64/bin/innobackupex --defaults-file=$config --user=$USER --password=$PASSWD --compress --compress-threads=2 --compress-chunk-size=64K --slave-info --safe-slave-backup --host=localhost --incremental $path --incremental-basedir=$last_backup --databases="${dataBases}" --no-timestamp >> $logfile 2>&1 sudo chown app.app $path -R ret=`tail -n 2 $logfile |grep "completed OK"|wc -l` if [ "$ret" = 1 ] ; then echo 'delete expired backup ' $basePath/incr_$OneMonthAgo* >> $logfile rm -rf $basePath/incr_$OneMonthAgo* rm -f $logfilePath/incr_$OneMonthAgo*.log echo $path > $logfilePath/last_backup_sucess.log else echo 'backup failure ,no delete expired backup' >> $logfile fielse echo "****** innobackupex in backup database ****** " >> $logfilefi增量备份文件放在了本机的/data/backup目录下,再编写一个rsync脚本同步到远程备份机上(192.168.10.130):[root@mysql-node ~]# cat /data/rsync.sh #!/bin/bashdatetime=`date +%Y%m%d-%H-%M-%S`logfile=/data/rsync.logecho "$datetime Rsync backup mysql start " >> $logfilesudo rsync -e "ssh -p6666" -avpgolr /data/backup bigtree@192.168.10.130:/data/backup_data/bigtree/DB_bak/10.0.40.52/ >> $logfile 2>&1ret=`tail -n 1 $logfile |grep "total size"|wc -l`if [ "$ret" = 1 ] ; then echo "$datetime Rsync backup mysql finish " >> $logfileelse echo "$datetime Rsync backup failure ,pls sendmail" >> $logfilefi结合crontab进行定时任务执行(每4个小时执行一次)[root@mysql-node ~]# crontab -e1 4,8,12,16,20,23 * * * /data/backup/script/incremental-backup-mysql.sh > /dev/null 2>&110 0,4,8,12,16,20,23 * * * /data/rsync.sh > /dev/null 2>&1顺便看一下本机/data/backup目录下面的增量备份数据[root@mysql-node ~]# ll /data/backup总用量 786364drwxr-xr-x 2 app app 4096 7月 31 01:01 2018-07-31drwxr-xr-x 2 app app 4096 8月 1 01:01 2018-08-01drwxr-xr-x 14 app app 4096 7月 31 00:01 full_20180731-00-01-01drwxr-xr-x 14 app app 4096 8月 1 00:01 full_20180801-00-01-01drwxr-xr-x 9 app app 4096 7月 31 04:01 incr_20180731-04-01-01drwxr-xr-x 9 app app 4096 7月 31 08:01 incr_20180731-08-01-01drwxr-xr-x 9 app app 4096 7月 31 12:01 incr_20180731-12-01-01drwxr-xr-x 9 app app 4096 7月 31 16:01 incr_20180731-16-01-01drwxr-xr-x 9 app app 4096 7月 31 20:01 incr_20180731-20-01-01drwxr-xr-x 9 app app 4096 7月 31 23:01 incr_20180731-23-01-01drwxr-xr-x 9 app app 4096 8月 1 04:01 incr_20180801-04-01-01drwxr-xr-x 9 app app 4096 8月 1 08:01 incr_20180801-08-01-01drwxr-xr-x 9 app app 4096 8月 1 12:01 incr_20180801-12-01-01drwxr-xr-x 9 app app 4096 8月 1 16:01 incr_20180801-16-01-01drwxr-xr-x 9 app app 4096 8月 1 20:01 incr_20180801-20-01-01drwxr-xr-x 9 app app 4096 8月 1 23:01 incr_20180801-23-01-01drwxrwxr-x 2 app app 20480 8月 9 08:01 logsdrwxrwxr-x 3 app app 4096 7月 12 17:43 script