启用二进制日志文件

vim /etc/my.cnf 配置文件位置及文件名根据实际情况确定
sql_log_bin=ON|OFF:是否记录二进制日志,默认为ON //在需要的时候设置为OFF
log_bin=/PATH/BIN_LOG_FILE:指定二进制日志文件位置; 通常单独存放到与数据库不同的机器中

清理二进制日志文件

show master logs; 查看二进制日志文件列表
flush logs; 切换二进制日志文件(mysql命令),创建新的二进制日志
mysqladmin flush-logs 切换二进制日志文件(bash命令)
purge binary logs to 'mysqlbin.000005'; 删除除mysqlbin.000005日志之前的所有日志,保留mysqlbin.000005及以后的日志
reset master logs; 重新001开始记数二进制日志(老版本)。从MariaDB10.1.6开始支持TO #,指定从#开始记数

一 完全备份,并还原到最新状态(mysqldump)

前提条件:启用二进制日志,并单独存放。在mysql数据丢失时,可以还原最新备份到丢失时刻的数据
1 完全备份

mysqldump -A --single-transaction --master-data=1 > /data/backup/all_mysql.sql

完全备份数据库文件,并存放多份到安全的地方
2 修改数据库(在数据表中添加多条记录。模拟数据增加,但还没有备份时数据丢失的情况。可以通过二进制日志还到最新的数据)

mysql> insert TABLENAME(col_name,...)value(value,...)

3 数据库文件丢失

rm -rf /data/mysql/*

测试效果,清空mysql数据目录,数据全部丢失,但开启了二进制日志,并单独存放在其他的硬盘中
4 停止mysql服务

service mysqld stop

5 查看完全备份时二进制日志备份的最后位置,实验时备份的最后位置为:CHANGE MASTER TO MASTER_LOG_FILE='mariadb.000001', MASTER_LOG_POS=8944;
通过less 命令查看最新的备份文件all_mysql.sql获取此信息

-- MySQL dump 10.16  Distrib 10.2.23-MariaDB, for Linux (x86_64)
--
-- Host: localhost    Database: 
-- ------------------------------------------------------
-- Server version       10.2.23-MariaDB-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Position to start replication or point-in-time recovery from
--

-- CHANGE MASTER TO MASTER_LOG_FILE='mariadb.000001', MASTER_LOG_POS=8944;

--
-- GTID to start replication from
--
/data/backup/all_2019-05-06.sql
.
.

重启mysql服务:

service mysqld restart

登录mysql :

mysql -uroot -p

临时关闭二进制日志,还原完全备份:

mysql> set sql_log_bin=off;  
mysql> soruce /data/backup/all_mysql.sql

6 还原没有备份的新数据
新开一个终端:用mysqlbinlog工具导出存放在二进制日志中没有备份的新记录,开始位置为第4步中查询到的位置(实验时为8944)

mysqlbinlog --start-position=8944 /data/bin/mariadb.000001 > /data/backup/inc.sql

在原终端中继续还原

mysql> source /data/backup/inc.sql

到此已经还原全部数据

二 xtrabackup(2.4.13)

新版xtrabackup完全备份及还原(MariaDB5.5.60)

安装xtrabackup ,下载的rpm包,因为有依赖,所以用yum安装

[root@Centos7 ~]#yum install percona-xtrabackup-24-2.4.13-1.el7.x86_64.rpm -y
Loaded plugins: fastestmirror, langpacks
Examining percona-xtrabackup-24-2.4.13-1.el7.x86_64.rpm: percona-xtrabackup-24-2.4.13-1.el7.x86_64
Marking percona-xtrabackup-24-2.4.13-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package percona-xtrabackup-24.x86_64 0:2.4.13-1.el7 will be installed
--> Processing Dependency: perl(DBD::mysql) for package: percona-xtrabackup-24-2.4.13-1.el7.x86_64
Determining fastest mirrors
base                                                   | 3.6 kB     00:00     
epel                                                   | 4.7 kB     00:00     
(1/2): epel/updateinfo                                   | 994 kB   00:02     
(2/2): epel/primary_db                                   | 6.7 MB   00:03     
--> Processing Dependency: perl(Digest::MD5) for package: percona-xtrabackup-24-2.4.13-1.el7.x86_64
--> Processing Dependency: libev.so.4()(64bit) for package: percona-xtrabackup-24-2.4.13-1.el7.x86_64
--> Running transaction check
---> Package libev.x86_64 0:4.15-3.el7 will be installed
---> Package perl-DBD-MySQL.x86_64 0:4.023-6.el7 will be installed
---> Package perl-Digest-MD5.x86_64 0:2.52-3.el7 will be installed
--> Processing Dependency: perl(Digest::base) >= 1.00 for package: perl-Digest-MD5-2.52-3.el7.x86_64
--> Running transaction check
---> Package perl-Digest.noarch 0:1.17-245.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================
 Package               Arch   Version      Repository                    Size
==============================================================================
Installing:
 percona-xtrabackup-24 x86_64 2.4.13-1.el7 /percona-xtrabackup-24-2.4.13-1.el7.x86_64
                                                                         31 M
Installing for dependencies:
 libev                 x86_64 4.15-3.el7   epel                          43 k
 perl-DBD-MySQL        x86_64 4.023-6.el7  base                         140 k
 perl-Digest           noarch 1.17-245.el7 base                          23 k
 perl-Digest-MD5       x86_64 2.52-3.el7   base                          30 k

Transaction Summary
==============================================================================
Install  1 Package (+4 Dependent packages)

Total size: 32 M
Total download size: 236 k
Installed size: 32 M
Downloading packages:
(1/4): libev-4.15-3.el7.x86_64.rpm                       |  43 kB   00:00     
(2/4): perl-DBD-MySQL-4.023-6.el7.x86_64.rpm             | 140 kB   00:00     
(3/4): perl-Digest-MD5-2.52-3.el7.x86_64.rpm             |  30 kB   00:00     
(4/4): perl-Digest-1.17-245.el7.noarch.rpm               |  23 kB   00:00     
------------------------------------------------------------------------------
Total                                            234 kB/s | 236 kB  00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libev-4.15-3.el7.x86_64                                    1/5 
  Installing : perl-DBD-MySQL-4.023-6.el7.x86_64                          2/5 
  Installing : perl-Digest-1.17-245.el7.noarch                            3/5 
  Installing : perl-Digest-MD5-2.52-3.el7.x86_64                          4/5 
  Installing : percona-xtrabackup-24-2.4.13-1.el7.x86_64                  5/5 
  Verifying  : perl-Digest-1.17-245.el7.noarch                            1/5 
  Verifying  : perl-Digest-MD5-2.52-3.el7.x86_64                          2/5 
  Verifying  : percona-xtrabackup-24-2.4.13-1.el7.x86_64                  3/5 
  Verifying  : perl-DBD-MySQL-4.023-6.el7.x86_64                          4/5 
  Verifying  : libev-4.15-3.el7.x86_64                                    5/5 

Installed:
  percona-xtrabackup-24.x86_64 0:2.4.13-1.el7                                 

Dependency Installed:
  libev.x86_64 0:4.15-3.el7            perl-DBD-MySQL.x86_64 0:4.023-6.el7   
  perl-Digest.noarch 0:1.17-245.el7    perl-Digest-MD5.x86_64 0:2.52-3.el7   

Complete!

导入测试数据库

[root@Centos7 ~]#mkdir /data/{backup,inc{1,2}}
[root@Centos7 ~]#systemctl start mariadb
[root@Centos7 ~]#mysql < hellodb_innodb.sql 
  • 1 在原主机做完全备份到/data/base
    xtrabackup --backup --target-dir=/data/base
    
    [root@Centos7 ~]#xtrabackup --backup --target-dir=/data/backup
    xtrabackup: recognized server arguments: --datadir=/var/lib/mysql 
    xtrabackup: recognized client arguments: --datadir=/var/lib/mysql --backup=1 --target-dir=/data/backup 
    190508 11:38:05  version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup' (using password: NO).
    190508 11:38:05  version_check Connected to MySQL server
    190508 11:38:05  version_check Executing a version check against the server...
    190508 11:38:05  version_check Done.
    190508 11:38:05 Connecting to MySQL server host: localhost, user: not set, password: not set, port: not set, socket: not set
    Using server version 5.5.60-MariaDB
    xtrabackup version 2.4.13 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 3e7ca7c)
    xtrabackup: uses posix_fadvise().
    xtrabackup: cd to /var/lib/mysql
    xtrabackup: open files limit requested 0, set to 1024
    xtrabackup: using the following InnoDB configuration:
    xtrabackup:   innodb_data_home_dir = .
    xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend
    xtrabackup:   innodb_log_group_home_dir = ./
    xtrabackup:   innodb_log_files_in_group = 2
    xtrabackup:   innodb_log_file_size = 5242880
    InnoDB: Number of pools: 1
    190508 11:38:05 >> log scanned up to (1628321)
    xtrabackup: Generating a list of tablespaces
    190508 11:38:05 [01] Copying ./ibdata1 to /data/backup/ibdata1
    190508 11:38:06 [01]        ...done
    190508 11:38:06 >> log scanned up to (1628321)
    190508 11:38:06 Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
    190508 11:38:06 Executing FLUSH TABLES WITH READ LOCK...
    190508 11:38:06 Starting to backup non-InnoDB tables and files
    190508 11:38:06 [01] Copying ./mysql/db.frm to /data/backup/mysql/db.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/db.MYI to /data/backup/mysql/db.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/db.MYD to /data/backup/mysql/db.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/host.frm to /data/backup/mysql/host.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/host.MYI to /data/backup/mysql/host.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/host.MYD to /data/backup/mysql/host.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/user.frm to /data/backup/mysql/user.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/user.MYI to /data/backup/mysql/user.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/user.MYD to /data/backup/mysql/user.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/func.frm to /data/backup/mysql/func.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/func.MYI to /data/backup/mysql/func.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/func.MYD to /data/backup/mysql/func.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/plugin.frm to /data/backup/mysql/plugin.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/plugin.MYI to /data/backup/mysql/plugin.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/plugin.MYD to /data/backup/mysql/plugin.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/servers.frm to /data/backup/mysql/servers.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/servers.MYI to /data/backup/mysql/servers.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/servers.MYD to /data/backup/mysql/servers.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/tables_priv.frm to /data/backup/mysql/tables_priv.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/tables_priv.MYI to /data/backup/mysql/tables_priv.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/tables_priv.MYD to /data/backup/mysql/tables_priv.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/columns_priv.frm to /data/backup/mysql/columns_priv.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/columns_priv.MYI to /data/backup/mysql/columns_priv.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/columns_priv.MYD to /data/backup/mysql/columns_priv.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_topic.frm to /data/backup/mysql/help_topic.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_topic.MYI to /data/backup/mysql/help_topic.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_topic.MYD to /data/backup/mysql/help_topic.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_category.frm to /data/backup/mysql/help_category.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_category.MYI to /data/backup/mysql/help_category.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_category.MYD to /data/backup/mysql/help_category.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_relation.frm to /data/backup/mysql/help_relation.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_relation.MYI to /data/backup/mysql/help_relation.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_relation.MYD to /data/backup/mysql/help_relation.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_keyword.frm to /data/backup/mysql/help_keyword.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_keyword.MYI to /data/backup/mysql/help_keyword.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/help_keyword.MYD to /data/backup/mysql/help_keyword.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_name.frm to /data/backup/mysql/time_zone_name.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_name.MYI to /data/backup/mysql/time_zone_name.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_name.MYD to /data/backup/mysql/time_zone_name.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone.frm to /data/backup/mysql/time_zone.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone.MYI to /data/backup/mysql/time_zone.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone.MYD to /data/backup/mysql/time_zone.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_transition.frm to /data/backup/mysql/time_zone_transition.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_transition.MYI to /data/backup/mysql/time_zone_transition.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_transition.MYD to /data/backup/mysql/time_zone_transition.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_transition_type.frm to /data/backup/mysql/time_zone_transition_type.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_transition_type.MYI to /data/backup/mysql/time_zone_transition_type.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_transition_type.MYD to /data/backup/mysql/time_zone_transition_type.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_leap_second.frm to /data/backup/mysql/time_zone_leap_second.frm
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_leap_second.MYI to /data/backup/mysql/time_zone_leap_second.MYI
    190508 11:38:06 [01]        ...done
    190508 11:38:06 [01] Copying ./mysql/time_zone_leap_second.MYD to /data/backup/mysql/time_zone_leap_second.MYD
    190508 11:38:06 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/proc.frm to /data/backup/mysql/proc.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/proc.MYI to /data/backup/mysql/proc.MYI
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/proc.MYD to /data/backup/mysql/proc.MYD
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/procs_priv.frm to /data/backup/mysql/procs_priv.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/procs_priv.MYI to /data/backup/mysql/procs_priv.MYI
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/procs_priv.MYD to /data/backup/mysql/procs_priv.MYD
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/general_log.frm to /data/backup/mysql/general_log.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/general_log.CSM to /data/backup/mysql/general_log.CSM
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/general_log.CSV to /data/backup/mysql/general_log.CSV
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/slow_log.frm to /data/backup/mysql/slow_log.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/slow_log.CSM to /data/backup/mysql/slow_log.CSM
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/slow_log.CSV to /data/backup/mysql/slow_log.CSV
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/event.frm to /data/backup/mysql/event.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/event.MYI to /data/backup/mysql/event.MYI
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/event.MYD to /data/backup/mysql/event.MYD
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/ndb_binlog_index.frm to /data/backup/mysql/ndb_binlog_index.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/ndb_binlog_index.MYI to /data/backup/mysql/ndb_binlog_index.MYI
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/ndb_binlog_index.MYD to /data/backup/mysql/ndb_binlog_index.MYD
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/proxies_priv.frm to /data/backup/mysql/proxies_priv.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/proxies_priv.MYI to /data/backup/mysql/proxies_priv.MYI
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./mysql/proxies_priv.MYD to /data/backup/mysql/proxies_priv.MYD
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [00] Writing /data/backup/test/db.opt
    190508 11:38:07 [00]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/db.opt to /data/backup/performance_schema/db.opt
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/cond_instances.frm to /data/backup/performance_schema/cond_instances.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/events_waits_current.frm to /data/backup/performance_schema/events_waits_current.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/events_waits_history.frm to /data/backup/performance_schema/events_waits_history.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/events_waits_history_long.frm to /data/backup/performance_schema/events_waits_history_long.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/events_waits_summary_by_instance.frm to /data/backup/performance_schema/events_waits_summary_by_instance.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/events_waits_summary_by_thread_by_event_name.frm to /data/backup/performance_schema/events_waits_summary_by_thread_by_event_name.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/events_waits_summary_global_by_event_name.frm to /data/backup/performance_schema/events_waits_summary_global_by_event_name.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/file_instances.frm to /data/backup/performance_schema/file_instances.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/file_summary_by_event_name.frm to /data/backup/performance_schema/file_summary_by_event_name.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/file_summary_by_instance.frm to /data/backup/performance_schema/file_summary_by_instance.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/mutex_instances.frm to /data/backup/performance_schema/mutex_instances.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/performance_timers.frm to /data/backup/performance_schema/performance_timers.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/rwlock_instances.frm to /data/backup/performance_schema/rwlock_instances.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/setup_consumers.frm to /data/backup/performance_schema/setup_consumers.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/setup_instruments.frm to /data/backup/performance_schema/setup_instruments.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/setup_timers.frm to /data/backup/performance_schema/setup_timers.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./performance_schema/threads.frm to /data/backup/performance_schema/threads.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./hellodb/db.opt to /data/backup/hellodb/db.opt
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./hellodb/classes.frm to /data/backup/hellodb/classes.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./hellodb/coc.frm to /data/backup/hellodb/coc.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./hellodb/courses.frm to /data/backup/hellodb/courses.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./hellodb/scores.frm to /data/backup/hellodb/scores.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./hellodb/students.frm to /data/backup/hellodb/students.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./hellodb/teachers.frm to /data/backup/hellodb/teachers.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 [01] Copying ./hellodb/toc.frm to /data/backup/hellodb/toc.frm
    190508 11:38:07 [01]        ...done
    190508 11:38:07 Finished backing up non-InnoDB tables and files
    190508 11:38:07 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
    xtrabackup: The latest check point (for incremental): '1628321'
    xtrabackup: Stopping log copying thread.
    .190508 11:38:07 >> log scanned up to (1628321)

190508 11:38:07 Executing UNLOCK TABLES
190508 11:38:07 All tables unlocked
190508 11:38:07 Backup created in directory '/data/backup/'
190508 11:38:07 [00] Writing /data/backup/backup-my.cnf
190508 11:38:07 [00] ...done
190508 11:38:07 [00] Writing /data/backup/xtrabackup_info
190508 11:38:07 [00] ...done
xtrabackup: Transaction log of lsn (1628321) to (1628321) was copied.
190508 11:38:07 completed OK!

scp -r /data/backup/ 目标主机:/data/backup/  将备份数据传送到目标主机上恢复  
```bash
[root@Centos7 ~]#scp -r /data/backup/ 192.168.37.17:/data/
The authenticity of host '192.168.37.17 (192.168.37.17)' can't be established.
ECDSA key fingerprint is SHA256:cgmQO7rW7wGdDrQs+/DxG7bbPUL4cTAZgmJ0b1BIvFc.
ECDSA key fingerprint is MD5:67:ad:d6:de:75:02:e5:38:bc:e5:cc:ef:b6:e8:87:a9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.37.17' (ECDSA) to the list of known hosts.
[email protected]'s password: 
xtrabackup_logfile                          100% 2560   189.1KB/s   00:00    
ibdata1                                     100%   18MB  61.4MB/s   00:00    
db.frm                                      100% 9582     3.5MB/s   00:00    
db.MYI                                      100% 5120     2.6MB/s   00:00    
db.MYD                                      100%  880   856.0KB/s   00:00    
host.frm                                    100% 9510     4.9MB/s   00:00    
host.MYI                                    100% 2048     1.0MB/s   00:00    
host.MYD                                    100%    0     0.0KB/s   00:00    
user.frm                                    100%   10KB   5.4MB/s   00:00    
user.MYI                                    100% 2048     1.2MB/s   00:00    
user.MYD                                    100%  340   303.3KB/s   00:00    
func.frm                                    100% 8665     4.7MB/s   00:00    
func.MYI                                    100% 1024   853.3KB/s   00:00    
func.MYD                                    100%    0     0.0KB/s   00:00    
plugin.frm                                  100% 8586     3.7MB/s   00:00    
plugin.MYI                                  100% 1024     1.1MB/s   00:00    
plugin.MYD                                  100%    0     0.0KB/s   00:00    
servers.frm                                 100% 8838     5.8MB/s   00:00    
servers.MYI                                 100% 1024   932.2KB/s   00:00    
servers.MYD                                 100%    0     0.0KB/s   00:00    
tables_priv.frm                             100% 8955     4.6MB/s   00:00    
tables_priv.MYI                             100% 4096     3.2MB/s   00:00    
tables_priv.MYD                             100%    0     0.0KB/s   00:00    
columns_priv.frm                            100% 8820     3.5MB/s   00:00    
columns_priv.MYI                            100% 4096     2.8MB/s   00:00    
columns_priv.MYD                            100%    0     0.0KB/s   00:00    
help_topic.frm                              100% 8770     5.3MB/s   00:00    
help_topic.MYI                              100%   20KB   9.2MB/s   00:00    
help_topic.MYD                              100%  440KB  53.1MB/s   00:00    
help_category.frm                           100% 8700     4.1MB/s   00:00    
help_category.MYI                           100% 3072     1.6MB/s   00:00    
help_category.MYD                           100% 1092   760.5KB/s   00:00    
help_relation.frm                           100% 8630     3.8MB/s   00:00    
help_relation.MYI                           100%   19KB   2.9MB/s   00:00    
help_relation.MYD                           100% 9252     6.7MB/s   00:00    
help_keyword.frm                            100% 8612     5.2MB/s   00:00    
help_keyword.MYI                            100%   16KB   6.9MB/s   00:00    
help_keyword.MYD                            100%   89KB  35.1MB/s   00:00    
time_zone_name.frm                          100% 8606     4.3MB/s   00:00    
time_zone_name.MYI                          100% 1024   659.9KB/s   00:00    
time_zone_name.MYD                          100%    0     0.0KB/s   00:00    
time_zone.frm                               100% 8636     4.7MB/s   00:00    
time_zone.MYI                               100% 1024   772.0KB/s   00:00    
time_zone.MYD                               100%    0     0.0KB/s   00:00    
time_zone_transition.frm                    100% 8686     6.1MB/s   00:00    
time_zone_transition.MYI                    100% 1024     1.2MB/s   00:00    
time_zone_transition.MYD                    100%    0     0.0KB/s   00:00    
time_zone_transition_type.frm               100% 8748     5.6MB/s   00:00    
time_zone_transition_type.MYI               100% 1024   714.8KB/s   00:00    
time_zone_transition_type.MYD               100%    0     0.0KB/s   00:00    
time_zone_leap_second.frm                   100% 8624     7.0MB/s   00:00    
time_zone_leap_second.MYI                   100% 1024   788.2KB/s   00:00    
time_zone_leap_second.MYD                   100%    0     0.0KB/s   00:00    
proc.frm                                    100%   10KB   5.8MB/s   00:00    
proc.MYI                                    100% 4096     3.3MB/s   00:00    
proc.MYD                                    100%  292   246.5KB/s   00:00    
procs_priv.frm                              100% 8875     4.6MB/s   00:00    
procs_priv.MYI                              100% 4096     3.4MB/s   00:00    
procs_priv.MYD                              100%    0     0.0KB/s   00:00    
general_log.frm                             100% 8776     4.1MB/s   00:00    
general_log.CSM                             100%   35    28.4KB/s   00:00    
general_log.CSV                             100%    0     0.0KB/s   00:00    
slow_log.frm                                100% 8976     7.5MB/s   00:00    
slow_log.CSM                                100%   35    23.5KB/s   00:00    
slow_log.CSV                                100%    0     0.0KB/s   00:00    
event.frm                                   100%   10KB   3.8MB/s   00:00    
event.MYI                                   100% 2048     1.6MB/s   00:00    
event.MYD                                   100%    0     0.0KB/s   00:00    
ndb_binlog_index.frm                        100% 8778     7.1MB/s   00:00    
ndb_binlog_index.MYI                        100% 1024   656.8KB/s   00:00    
ndb_binlog_index.MYD                        100%    0     0.0KB/s   00:00    
proxies_priv.frm                            100% 8800     7.5MB/s   00:00    
proxies_priv.MYI                            100% 5120     4.9MB/s   00:00    
proxies_priv.MYD                            100% 1386     1.0MB/s   00:00    
db.opt                                      100%    0     0.0KB/s   00:00    
db.opt                                      100%   61    35.3KB/s   00:00    
cond_instances.frm                          100% 8624     6.9MB/s   00:00    
events_waits_current.frm                    100% 9220     7.8MB/s   00:00    
events_waits_history.frm                    100% 9220     5.8MB/s   00:00    
events_waits_history_long.frm               100% 9220     6.7MB/s   00:00    
events_waits_summary_by_instance.frm        100% 8878     5.0MB/s   00:00    
events_waits_summary_by_thread_by_event_nam 100% 8854     5.5MB/s   00:00    
events_waits_summary_global_by_event_name.f 100% 8814     3.3MB/s   00:00    
file_instances.frm                          100% 8654     5.2MB/s   00:00    
file_summary_by_event_name.frm              100% 8800     4.3MB/s   00:00    
file_summary_by_instance.frm                100% 8840     6.2MB/s   00:00    
mutex_instances.frm                         100% 8684     4.2MB/s   00:00    
performance_timers.frm                      100% 8776     7.1MB/s   00:00    
rwlock_instances.frm                        100% 8758     4.5MB/s   00:00    
setup_consumers.frm                         100% 8605     5.0MB/s   00:00    
setup_instruments.frm                       100% 8637     7.9MB/s   00:00    
setup_timers.frm                            100% 8650     7.8MB/s   00:00    
threads.frm                                 100% 8650     6.3MB/s   00:00    
db.opt                                      100%   61    37.6KB/s   00:00    
classes.frm                                 100% 8636     5.8MB/s   00:00    
coc.frm                                     100% 8630     4.2MB/s   00:00    
courses.frm                                 100% 8602     4.6MB/s   00:00    
scores.frm                                  100% 8658     6.2MB/s   00:00    
students.frm                                100% 8736     6.6MB/s   00:00    
teachers.frm                                100% 8656     5.4MB/s   00:00    
toc.frm                                     100% 8622     6.7MB/s   00:00    
xtrabackup_checkpoints                      100%  113    65.1KB/s   00:00    
backup-my.cnf                               100%  431   356.9KB/s   00:00    
xtrabackup_info                             100%  424   255.8KB/s   00:00    
[root@Centos7 ~]#
  • 2 在目标主机还原数据
    用以还原的主机同样需要先安装xtrabackup
    预准备数据:xtrabackup --prepare --target-dir=/data/backup
    
    [root@Centos7 ~]#xtrabackup --prepare --target-dir=/data/backup
    xtrabackup: recognized server arguments: --innodb_checksum_algorithm=innodb --innodb_log_checksum_algorithm=innodb --innodb_data_file_path=ibdata1:10M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=5242880 --innodb_fast_checksum=0 --innodb_page_size=16384 --innodb_log_block_size=512 --innodb_undo_directory=. --innodb_undo_tablespaces=0 --server-id=0 --redo-log-version=0 
    xtrabackup: recognized client arguments: --innodb_checksum_algorithm=innodb --innodb_log_checksum_algorithm=innodb --innodb_data_file_path=ibdata1:10M:autoextend --innodb_log_files_in_group=2 --innodb_log_file_size=5242880 --innodb_fast_checksum=0 --innodb_page_size=16384 --innodb_log_block_size=512 --innodb_undo_directory=. --innodb_undo_tablespaces=0 --server-id=0 --redo-log-version=0 --prepare=1 --target-dir=/data/backup 
    xtrabackup version 2.4.13 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 3e7ca7c)
    xtrabackup: cd to /data/backup/
    xtrabackup: This target seems to be not prepared yet.
    InnoDB: Number of pools: 1
    xtrabackup: xtrabackup_logfile detected: size=8388608, start_lsn=(1628321)
    xtrabackup: using the following InnoDB configuration for recovery:
    xtrabackup:   innodb_data_home_dir = .
    xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend
    xtrabackup:   innodb_log_group_home_dir = .
    xtrabackup:   innodb_log_files_in_group = 1
    xtrabackup:   innodb_log_file_size = 8388608
    xtrabackup: using the following InnoDB configuration for recovery:
    xtrabackup:   innodb_data_home_dir = .
    xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend
    xtrabackup:   innodb_log_group_home_dir = .
    xtrabackup:   innodb_log_files_in_group = 1
    xtrabackup:   innodb_log_file_size = 8388608
    xtrabackup: Starting InnoDB instance for recovery.
    xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
    InnoDB: PUNCH HOLE support available
    InnoDB: Mutexes and rw_locks use GCC atomic builtins
    InnoDB: Uses event mutexes
    InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
    InnoDB: Compressed tables use zlib 1.2.7
    InnoDB: Number of pools: 1
    InnoDB: Using CPU crc32 instructions
    InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
    InnoDB: Completed initialization of buffer pool
    InnoDB: page_cleaner coordinator priority: -20
    InnoDB: Highest supported file format is Barracuda.
    InnoDB: The log sequence number 0 in the system tablespace does not match the log sequence number 1628321 in the ib_logfiles!
    InnoDB: Database was not shutdown normally!
    InnoDB: Starting crash recovery.
    InnoDB: Creating shared tablespace for temporary tables
    InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
    InnoDB: File './ibtmp1' size is now 12 MB.
    InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
    InnoDB: 32 non-redo rollback segment(s) are active.
    InnoDB: 5.7.19 started; log sequence number 1628321

xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 1628340
InnoDB: Number of pools: 1
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = .
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = .
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 5242880
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
InnoDB: Compressed tables use zlib 1.2.7
InnoDB: Number of pools: 1
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
InnoDB: Completed initialization of buffer pool
InnoDB: page_cleaner coordinator priority: -20
InnoDB: Setting log file ./ib_logfile101 size to 5 MB
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
InnoDB: New log files created, LSN=1628340
InnoDB: Highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 1628684
InnoDB: Doing recovery: scanned up to log sequence number 1628693 (0%)
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: Removed temporary tablespace data file: "ibtmp1"
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: 5.7.19 started; log sequence number 1628693
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 1628712
190508 11:49:11 completed OK!

- 复制到数据库目录:xtrabackup --copy-back --target-dir=/data/backup  
要求数据库目录必须为空,MySQL服务不能启动  
```bash
[root@Centos7 ~]#xtrabackup --copy-back --target-dir=/data/backup
xtrabackup: recognized server arguments: --datadir=/var/lib/mysql 
xtrabackup: recognized client arguments: --datadir=/var/lib/mysql --copy-back=1 --target-dir=/data/backup 
xtrabackup version 2.4.13 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 3e7ca7c)
190508 11:57:47 [01] Copying ib_logfile0 to /var/lib/mysql/ib_logfile0
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ib_logfile1 to /var/lib/mysql/ib_logfile1
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ibdata1 to /var/lib/mysql/ibdata1
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/db.frm to /var/lib/mysql/mysql/db.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/db.MYI to /var/lib/mysql/mysql/db.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/db.MYD to /var/lib/mysql/mysql/db.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/host.frm to /var/lib/mysql/mysql/host.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/host.MYI to /var/lib/mysql/mysql/host.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/host.MYD to /var/lib/mysql/mysql/host.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/user.frm to /var/lib/mysql/mysql/user.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/user.MYI to /var/lib/mysql/mysql/user.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/user.MYD to /var/lib/mysql/mysql/user.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/func.frm to /var/lib/mysql/mysql/func.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/func.MYI to /var/lib/mysql/mysql/func.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/func.MYD to /var/lib/mysql/mysql/func.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/plugin.frm to /var/lib/mysql/mysql/plugin.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/plugin.MYI to /var/lib/mysql/mysql/plugin.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/plugin.MYD to /var/lib/mysql/mysql/plugin.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/servers.frm to /var/lib/mysql/mysql/servers.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/servers.MYI to /var/lib/mysql/mysql/servers.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/servers.MYD to /var/lib/mysql/mysql/servers.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/tables_priv.frm to /var/lib/mysql/mysql/tables_priv.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/tables_priv.MYI to /var/lib/mysql/mysql/tables_priv.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/tables_priv.MYD to /var/lib/mysql/mysql/tables_priv.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/columns_priv.frm to /var/lib/mysql/mysql/columns_priv.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/columns_priv.MYI to /var/lib/mysql/mysql/columns_priv.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/columns_priv.MYD to /var/lib/mysql/mysql/columns_priv.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_topic.frm to /var/lib/mysql/mysql/help_topic.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_topic.MYI to /var/lib/mysql/mysql/help_topic.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_topic.MYD to /var/lib/mysql/mysql/help_topic.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_category.frm to /var/lib/mysql/mysql/help_category.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_category.MYI to /var/lib/mysql/mysql/help_category.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_category.MYD to /var/lib/mysql/mysql/help_category.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_relation.frm to /var/lib/mysql/mysql/help_relation.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_relation.MYI to /var/lib/mysql/mysql/help_relation.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_relation.MYD to /var/lib/mysql/mysql/help_relation.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_keyword.frm to /var/lib/mysql/mysql/help_keyword.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_keyword.MYI to /var/lib/mysql/mysql/help_keyword.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/help_keyword.MYD to /var/lib/mysql/mysql/help_keyword.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_name.frm to /var/lib/mysql/mysql/time_zone_name.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_name.MYI to /var/lib/mysql/mysql/time_zone_name.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_name.MYD to /var/lib/mysql/mysql/time_zone_name.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone.frm to /var/lib/mysql/mysql/time_zone.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone.MYI to /var/lib/mysql/mysql/time_zone.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone.MYD to /var/lib/mysql/mysql/time_zone.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_transition.frm to /var/lib/mysql/mysql/time_zone_transition.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_transition.MYI to /var/lib/mysql/mysql/time_zone_transition.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_transition.MYD to /var/lib/mysql/mysql/time_zone_transition.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_transition_type.frm to /var/lib/mysql/mysql/time_zone_transition_type.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_transition_type.MYI to /var/lib/mysql/mysql/time_zone_transition_type.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_transition_type.MYD to /var/lib/mysql/mysql/time_zone_transition_type.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_leap_second.frm to /var/lib/mysql/mysql/time_zone_leap_second.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_leap_second.MYI to /var/lib/mysql/mysql/time_zone_leap_second.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/time_zone_leap_second.MYD to /var/lib/mysql/mysql/time_zone_leap_second.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/proc.frm to /var/lib/mysql/mysql/proc.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/proc.MYI to /var/lib/mysql/mysql/proc.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/proc.MYD to /var/lib/mysql/mysql/proc.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/procs_priv.frm to /var/lib/mysql/mysql/procs_priv.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/procs_priv.MYI to /var/lib/mysql/mysql/procs_priv.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/procs_priv.MYD to /var/lib/mysql/mysql/procs_priv.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/general_log.frm to /var/lib/mysql/mysql/general_log.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/general_log.CSM to /var/lib/mysql/mysql/general_log.CSM
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/general_log.CSV to /var/lib/mysql/mysql/general_log.CSV
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/slow_log.frm to /var/lib/mysql/mysql/slow_log.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/slow_log.CSM to /var/lib/mysql/mysql/slow_log.CSM
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/slow_log.CSV to /var/lib/mysql/mysql/slow_log.CSV
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/event.frm to /var/lib/mysql/mysql/event.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/event.MYI to /var/lib/mysql/mysql/event.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/event.MYD to /var/lib/mysql/mysql/event.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/ndb_binlog_index.frm to /var/lib/mysql/mysql/ndb_binlog_index.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/ndb_binlog_index.MYI to /var/lib/mysql/mysql/ndb_binlog_index.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/ndb_binlog_index.MYD to /var/lib/mysql/mysql/ndb_binlog_index.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/proxies_priv.frm to /var/lib/mysql/mysql/proxies_priv.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/proxies_priv.MYI to /var/lib/mysql/mysql/proxies_priv.MYI
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./mysql/proxies_priv.MYD to /var/lib/mysql/mysql/proxies_priv.MYD
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./test/db.opt to /var/lib/mysql/test/db.opt
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/db.opt to /var/lib/mysql/performance_schema/db.opt
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/cond_instances.frm to /var/lib/mysql/performance_schema/cond_instances.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/events_waits_current.frm to /var/lib/mysql/performance_schema/events_waits_current.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/events_waits_history.frm to /var/lib/mysql/performance_schema/events_waits_history.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/events_waits_history_long.frm to /var/lib/mysql/performance_schema/events_waits_history_long.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/events_waits_summary_by_instance.frm to /var/lib/mysql/performance_schema/events_waits_summary_by_instance.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/events_waits_summary_by_thread_by_event_name.frm to /var/lib/mysql/performance_schema/events_waits_summary_by_thread_by_event_name.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/events_waits_summary_global_by_event_name.frm to /var/lib/mysql/performance_schema/events_waits_summary_global_by_event_name.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/file_instances.frm to /var/lib/mysql/performance_schema/file_instances.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/file_summary_by_event_name.frm to /var/lib/mysql/performance_schema/file_summary_by_event_name.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/file_summary_by_instance.frm to /var/lib/mysql/performance_schema/file_summary_by_instance.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/mutex_instances.frm to /var/lib/mysql/performance_schema/mutex_instances.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/performance_timers.frm to /var/lib/mysql/performance_schema/performance_timers.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/rwlock_instances.frm to /var/lib/mysql/performance_schema/rwlock_instances.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/setup_consumers.frm to /var/lib/mysql/performance_schema/setup_consumers.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/setup_instruments.frm to /var/lib/mysql/performance_schema/setup_instruments.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/setup_timers.frm to /var/lib/mysql/performance_schema/setup_timers.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./performance_schema/threads.frm to /var/lib/mysql/performance_schema/threads.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./hellodb/db.opt to /var/lib/mysql/hellodb/db.opt
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./hellodb/classes.frm to /var/lib/mysql/hellodb/classes.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./hellodb/coc.frm to /var/lib/mysql/hellodb/coc.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./hellodb/courses.frm to /var/lib/mysql/hellodb/courses.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./hellodb/scores.frm to /var/lib/mysql/hellodb/scores.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./hellodb/students.frm to /var/lib/mysql/hellodb/students.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./hellodb/teachers.frm to /var/lib/mysql/hellodb/teachers.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./hellodb/toc.frm to /var/lib/mysql/hellodb/toc.frm
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./xtrabackup_info to /var/lib/mysql/xtrabackup_info
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./xtrabackup_master_key_id to /var/lib/mysql/xtrabackup_master_key_id
190508 11:57:47 [01]        ...done
190508 11:57:47 [01] Copying ./ibtmp1 to /var/lib/mysql/ibtmp1
190508 11:57:48 [01]        ...done
190508 11:57:48 completed OK!
  • 还原目录属性,此时mysql目录的属主和属组 为root ,需要修改为mysql
    
    [root@Centos7 ~]#chown -R mysql.mysql /var/lib/mysql
    [root@Centos7 ~]#systemctl start mariadb
    [root@Centos7 ~]#mysql
    Welcome to the MariaDB monitor.  Commands end with ; or \g.
    Your MariaDB connection id is 2
    Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| hellodb |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.01 sec)

MariaDB [(none)]> quit
Bye
[root@Centos7 ~]#

数据已还原到新主机上  

- 增量备份还原  
测试 在原主机数据库中增加一条记录,测试增量备份  
```bash
[root@Centos7 ~]#mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> inster teacher (name,age)value('lisi',18);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'inster teacher (name,age)value('lisi',18)' at line 1
MariaDB [(none)]> inster hellodb.teachers (name,age)value('lisi',18);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'inster hellodb.teachers (name,age)value('lisi',18)' at line 1
MariaDB [(none)]> use hellodb
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes           |
| coc               |
| courses           |
| scores            |
| students          |
| teachers          |
| toc               |
+-------------------+
7 rows in set (0.00 sec)

MariaDB [hellodb]> insert teachers (name,age)value('lisi',18);
Query OK, 1 row affected (0.02 sec)

MariaDB [hellodb]> 

第一次增备份
xtrabackup --backup --target-dir=/data/inc1 --incremenal-basedir=/data/backup

[root@Centos7 ~]#xtrabackup --backup --target-dir=/data/inc1 --incremenal-basedir=/data/backup
xtrabackup: recognized server arguments: --datadir=/var/lib/mysql 
xtrabackup: recognized client arguments: --datadir=/var/lib/mysql --backup=1 --target-dir=/data/inc1 
190508 12:11:59  version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup' (using password: NO).
190508 12:11:59  version_check Connected to MySQL server
190508 12:11:59  version_check Executing a version check against the server...
190508 12:11:59  version_check Done.
190508 12:11:59 Connecting to MySQL server host: localhost, user: not set, password: not set, port: not set, socket: not set
Using server version 5.5.60-MariaDB
xtrabackup version 2.4.13 based on MySQL server 5.7.19 Linux (x86_64) (revision id: 3e7ca7c)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /var/lib/mysql
xtrabackup: open files limit requested 0, set to 1024
xtrabackup: using the following InnoDB configuration:
xtrabackup:   innodb_data_home_dir = .
xtrabackup:   innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup:   innodb_log_group_home_dir = ./
xtrabackup:   innodb_log_files_in_group = 2
xtrabackup:   innodb_log_file_size = 5242880
InnoDB: Number of pools: 1
190508 12:11:59 >> log scanned up to (1629159)
xtrabackup: Generating a list of tablespaces
190508 12:11:59 [01] Copying ./ibdata1 to /data/inc1/ibdata1
190508 12:11:59 [01]        ...done
190508 12:12:00 >> log scanned up to (1629159)
190508 12:12:00 Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
190508 12:12:00 Executing FLUSH TABLES WITH READ LOCK...
190508 12:12:00 Starting to backup non-InnoDB tables and files
190508 12:12:00 [01] Copying ./mysql/db.frm to /data/inc1/mysql/db.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/db.MYI to /data/inc1/mysql/db.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/db.MYD to /data/inc1/mysql/db.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/host.frm to /data/inc1/mysql/host.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/host.MYI to /data/inc1/mysql/host.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/host.MYD to /data/inc1/mysql/host.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/user.frm to /data/inc1/mysql/user.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/user.MYI to /data/inc1/mysql/user.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/user.MYD to /data/inc1/mysql/user.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/func.frm to /data/inc1/mysql/func.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/func.MYI to /data/inc1/mysql/func.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/func.MYD to /data/inc1/mysql/func.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/plugin.frm to /data/inc1/mysql/plugin.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/plugin.MYI to /data/inc1/mysql/plugin.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/plugin.MYD to /data/inc1/mysql/plugin.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/servers.frm to /data/inc1/mysql/servers.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/servers.MYI to /data/inc1/mysql/servers.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/servers.MYD to /data/inc1/mysql/servers.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/tables_priv.frm to /data/inc1/mysql/tables_priv.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/tables_priv.MYI to /data/inc1/mysql/tables_priv.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/tables_priv.MYD to /data/inc1/mysql/tables_priv.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/columns_priv.frm to /data/inc1/mysql/columns_priv.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/columns_priv.MYI to /data/inc1/mysql/columns_priv.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/columns_priv.MYD to /data/inc1/mysql/columns_priv.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_topic.frm to /data/inc1/mysql/help_topic.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_topic.MYI to /data/inc1/mysql/help_topic.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_topic.MYD to /data/inc1/mysql/help_topic.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_category.frm to /data/inc1/mysql/help_category.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_category.MYI to /data/inc1/mysql/help_category.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_category.MYD to /data/inc1/mysql/help_category.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_relation.frm to /data/inc1/mysql/help_relation.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_relation.MYI to /data/inc1/mysql/help_relation.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_relation.MYD to /data/inc1/mysql/help_relation.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_keyword.frm to /data/inc1/mysql/help_keyword.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_keyword.MYI to /data/inc1/mysql/help_keyword.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/help_keyword.MYD to /data/inc1/mysql/help_keyword.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_name.frm to /data/inc1/mysql/time_zone_name.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_name.MYI to /data/inc1/mysql/time_zone_name.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_name.MYD to /data/inc1/mysql/time_zone_name.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone.frm to /data/inc1/mysql/time_zone.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone.MYI to /data/inc1/mysql/time_zone.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone.MYD to /data/inc1/mysql/time_zone.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_transition.frm to /data/inc1/mysql/time_zone_transition.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_transition.MYI to /data/inc1/mysql/time_zone_transition.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_transition.MYD to /data/inc1/mysql/time_zone_transition.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_transition_type.frm to /data/inc1/mysql/time_zone_transition_type.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_transition_type.MYI to /data/inc1/mysql/time_zone_transition_type.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_transition_type.MYD to /data/inc1/mysql/time_zone_transition_type.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_leap_second.frm to /data/inc1/mysql/time_zone_leap_second.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_leap_second.MYI to /data/inc1/mysql/time_zone_leap_second.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/time_zone_leap_second.MYD to /data/inc1/mysql/time_zone_leap_second.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/proc.frm to /data/inc1/mysql/proc.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/proc.MYI to /data/inc1/mysql/proc.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/proc.MYD to /data/inc1/mysql/proc.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/procs_priv.frm to /data/inc1/mysql/procs_priv.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/procs_priv.MYI to /data/inc1/mysql/procs_priv.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/procs_priv.MYD to /data/inc1/mysql/procs_priv.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/general_log.frm to /data/inc1/mysql/general_log.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/general_log.CSM to /data/inc1/mysql/general_log.CSM
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/general_log.CSV to /data/inc1/mysql/general_log.CSV
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/slow_log.frm to /data/inc1/mysql/slow_log.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/slow_log.CSM to /data/inc1/mysql/slow_log.CSM
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/slow_log.CSV to /data/inc1/mysql/slow_log.CSV
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/event.frm to /data/inc1/mysql/event.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/event.MYI to /data/inc1/mysql/event.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/event.MYD to /data/inc1/mysql/event.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/ndb_binlog_index.frm to /data/inc1/mysql/ndb_binlog_index.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/ndb_binlog_index.MYI to /data/inc1/mysql/ndb_binlog_index.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/ndb_binlog_index.MYD to /data/inc1/mysql/ndb_binlog_index.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/proxies_priv.frm to /data/inc1/mysql/proxies_priv.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/proxies_priv.MYI to /data/inc1/mysql/proxies_priv.MYI
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./mysql/proxies_priv.MYD to /data/inc1/mysql/proxies_priv.MYD
190508 12:12:00 [01]        ...done
190508 12:12:00 [00] Writing /data/inc1/test/db.opt
190508 12:12:00 [00]        ...done
190508 12:12:00 [01] Copying ./performance_schema/db.opt to /data/inc1/performance_schema/db.opt
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/cond_instances.frm to /data/inc1/performance_schema/cond_instances.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/events_waits_current.frm to /data/inc1/performance_schema/events_waits_current.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/events_waits_history.frm to /data/inc1/performance_schema/events_waits_history.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/events_waits_history_long.frm to /data/inc1/performance_schema/events_waits_history_long.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/events_waits_summary_by_instance.frm to /data/inc1/performance_schema/events_waits_summary_by_instance.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/events_waits_summary_by_thread_by_event_name.frm to /data/inc1/performance_schema/events_waits_summary_by_thread_by_event_name.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/events_waits_summary_global_by_event_name.frm to /data/inc1/performance_schema/events_waits_summary_global_by_event_name.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/file_instances.frm to /data/inc1/performance_schema/file_instances.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/file_summary_by_event_name.frm to /data/inc1/performance_schema/file_summary_by_event_name.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/file_summary_by_instance.frm to /data/inc1/performance_schema/file_summary_by_instance.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/mutex_instances.frm to /data/inc1/performance_schema/mutex_instances.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/performance_timers.frm to /data/inc1/performance_schema/performance_timers.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/rwlock_instances.frm to /data/inc1/performance_schema/rwlock_instances.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/setup_consumers.frm to /data/inc1/performance_schema/setup_consumers.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/setup_instruments.frm to /data/inc1/performance_schema/setup_instruments.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/setup_timers.frm to /data/inc1/performance_schema/setup_timers.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./performance_schema/threads.frm to /data/inc1/performance_schema/threads.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./hellodb/db.opt to /data/inc1/hellodb/db.opt
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./hellodb/classes.frm to /data/inc1/hellodb/classes.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./hellodb/coc.frm to /data/inc1/hellodb/coc.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./hellodb/courses.frm to /data/inc1/hellodb/courses.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./hellodb/scores.frm to /data/inc1/hellodb/scores.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./hellodb/students.frm to /data/inc1/hellodb/students.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./hellodb/teachers.frm to /data/inc1/hellodb/teachers.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 [01] Copying ./hellodb/toc.frm to /data/inc1/hellodb/toc.frm
190508 12:12:00 [01]        ...done
190508 12:12:00 Finished backing up non-InnoDB tables and files
190508 12:12:00 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
xtrabackup: The latest check point (for incremental): '1629159'
xtrabackup: Stopping log copying thread.
.190508 12:12:00 >> log scanned up to (1629159)

190508 12:12:01 Executing UNLOCK TABLES
190508 12:12:01 All tables unlocked
190508 12:12:01 Backup created in directory '/data/inc1/'
190508 12:12:01 [00] Writing /data/inc1/backup-my.cnf
190508 12:12:01 [00]        ...done
190508 12:12:01 [00] Writing /data/inc1/xtrabackup_info
190508 12:12:01 [00]        ...done
xtrabackup: Transaction log of lsn (1629159) to (1629159) was copied.
190508 12:12:01 completed OK!

再添加一条记录,测试第二次增量备份
xtrabackup --backup --target-dir=/data/inc2 --incremenal-basedir=/data/inc1

  • 将备份数据传送到目标主机
    scp -r /data/* 192.168.37.17:/data/

在目标主机还原数据

  • 预准备完全备份 --apply-log-only 阻止回滚未完成的事务,最后一次合并不用添加
    xtrabackup --prepare --apply-log-only --target-dir=/data/backup
    合并第一次增量备份到完全备份 --incremental-dir 增量备份的目录
    xtrabackup --prepare --apply-log-only --target-dir=/data/backup --incremental-dir=/data/inc1
    合并第二次增量备份到完全备份,因为实验时第二次增量为最后增量,所有不用阻止回滚选项
    xtrabackup --prepare --target-dir=/data/backup --incremental-dir=/data/inc2
    复制到数据库目录,数据库目录必须为空,mysql服务不能启动
    xtrabackup --copy-back --target-dir=/data/backup
    还原属性:chown -R mysql.mysql /var/lib/mysql
    启动服务,可以查询到增加的新数据