mysql备份和恢复机制之Xtrabackup

说明:Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍 ,是一款开源能够对innodb和xtradb数据库进行热备的工具。
percona是mysql的分支,就是mysql的二次开发,对mysql的性能做了提升;mariadb也是mysql的一个分支
特点:
(1)备份过程快速、可靠
(2)备份过程不会打断正在执行的事务
(3)能够基于压缩等功能节约磁盘空间和流量
(4)自动实现备份检验
(5)还原速度快
第一大步:
安装
1.[root@mysql-master ~]#yum install percona-xtrabackup -y
2.创建数据库
create database test;
        use test;
        create table bak(id int ,name char(20));  创建表
        insert into bak values(1,'dog');
3.创建最小权限用户用来管理数据库,尽量不要使用root
MariaDB [(none)]> grant reload,lock tables,replication client on *.* to 'bakupuser'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> 
第二大步:进行完全备份
使用第一步创建的最小权限用户身份进行备份
root@mysql-master ~]#innobackupex --user=bakupuser --password=123456 /backup/
171227 19:56:21 innobackupex: Starting the backup operation

IMPORTANT: Please check that the backup run completes successfully.
           At the end of a successful backup run innobackupex
           prints "completed OK!".

Can't locate Digest/MD5.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 - line 693.
BEGIN failed--compilation aborted at - line 693.
171227 19:56:22 Connecting to MySQL server host: localhost, user: bakupuser, password: set, port: 0, socket: /var/lib/mysql/mysql.sock
Using server version 5.5.52-MariaDB
innobackupex version 2.3.6 based on MySQL server 5.6.24 Linux (x86_64) (revision id: )
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
171227 19:56:22 >> log scanned up to (1602621)
xtrabackup: Generating a list of tablespaces
171227 19:56:22 [01] Copying ./ibdata1 to /backup//2017-12-27_19-56-21/ibdata1
171227 19:56:23 >> log scanned up to (1602621)
171227 19:56:23 [01]        ...done
171227 19:56:24 >> log scanned up to (1602621)
171227 19:56:24 Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
171227 19:56:24 Executing FLUSH TABLES WITH READ LOCK...
171227 19:56:24 Starting to backup non-InnoDB tables and files
171227 19:56:24 [01] Copying ./mysql/db.frm to /backup//2017-12-27_19-56-21/mysql/db.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/db.MYI to /backup//2017-12-27_19-56-21/mysql/db.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/db.MYD to /backup//2017-12-27_19-56-21/mysql/db.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/host.frm to /backup//2017-12-27_19-56-21/mysql/host.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/host.MYI to /backup//2017-12-27_19-56-21/mysql/host.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/host.MYD to /backup//2017-12-27_19-56-21/mysql/host.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/user.frm to /backup//2017-12-27_19-56-21/mysql/user.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/user.MYI to /backup//2017-12-27_19-56-21/mysql/user.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/user.MYD to /backup//2017-12-27_19-56-21/mysql/user.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/func.frm to /backup//2017-12-27_19-56-21/mysql/func.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/func.MYI to /backup//2017-12-27_19-56-21/mysql/func.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/func.MYD to /backup//2017-12-27_19-56-21/mysql/func.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/plugin.frm to /backup//2017-12-27_19-56-21/mysql/plugin.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/plugin.MYI to /backup//2017-12-27_19-56-21/mysql/plugin.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/plugin.MYD to /backup//2017-12-27_19-56-21/mysql/plugin.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/servers.frm to /backup//2017-12-27_19-56-21/mysql/servers.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/servers.MYI to /backup//2017-12-27_19-56-21/mysql/servers.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/servers.MYD to /backup//2017-12-27_19-56-21/mysql/servers.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/tables_priv.frm to /backup//2017-12-27_19-56-21/mysql/tables_priv.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/tables_priv.MYI to /backup//2017-12-27_19-56-21/mysql/tables_priv.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/tables_priv.MYD to /backup//2017-12-27_19-56-21/mysql/tables_priv.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/columns_priv.frm to /backup//2017-12-27_19-56-21/mysql/columns_priv.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/columns_priv.MYI to /backup//2017-12-27_19-56-21/mysql/columns_priv.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/columns_priv.MYD to /backup//2017-12-27_19-56-21/mysql/columns_priv.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_topic.frm to /backup//2017-12-27_19-56-21/mysql/help_topic.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_topic.MYI to /backup//2017-12-27_19-56-21/mysql/help_topic.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_topic.MYD to /backup//2017-12-27_19-56-21/mysql/help_topic.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_category.frm to /backup//2017-12-27_19-56-21/mysql/help_category.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_category.MYI to /backup//2017-12-27_19-56-21/mysql/help_category.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_category.MYD to /backup//2017-12-27_19-56-21/mysql/help_category.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_relation.frm to /backup//2017-12-27_19-56-21/mysql/help_relation.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_relation.MYI to /backup//2017-12-27_19-56-21/mysql/help_relation.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_relation.MYD to /backup//2017-12-27_19-56-21/mysql/help_relation.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_keyword.frm to /backup//2017-12-27_19-56-21/mysql/help_keyword.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_keyword.MYI to /backup//2017-12-27_19-56-21/mysql/help_keyword.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/help_keyword.MYD to /backup//2017-12-27_19-56-21/mysql/help_keyword.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_name.frm to /backup//2017-12-27_19-56-21/mysql/time_zone_name.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_name.MYI to /backup//2017-12-27_19-56-21/mysql/time_zone_name.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_name.MYD to /backup//2017-12-27_19-56-21/mysql/time_zone_name.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone.frm to /backup//2017-12-27_19-56-21/mysql/time_zone.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone.MYI to /backup//2017-12-27_19-56-21/mysql/time_zone.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone.MYD to /backup//2017-12-27_19-56-21/mysql/time_zone.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_transition.frm to /backup//2017-12-27_19-56-21/mysql/time_zone_transition.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_transition.MYI to /backup//2017-12-27_19-56-21/mysql/time_zone_transition.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_transition.MYD to /backup//2017-12-27_19-56-21/mysql/time_zone_transition.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_transition_type.frm to /backup//2017-12-27_19-56-21/mysql/time_zone_transition_type.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_transition_type.MYI to /backup//2017-12-27_19-56-21/mysql/time_zone_transition_type.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_transition_type.MYD to /backup//2017-12-27_19-56-21/mysql/time_zone_transition_type.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_leap_second.frm to /backup//2017-12-27_19-56-21/mysql/time_zone_leap_second.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_leap_second.MYI to /backup//2017-12-27_19-56-21/mysql/time_zone_leap_second.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/time_zone_leap_second.MYD to /backup//2017-12-27_19-56-21/mysql/time_zone_leap_second.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/proc.frm to /backup//2017-12-27_19-56-21/mysql/proc.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/proc.MYI to /backup//2017-12-27_19-56-21/mysql/proc.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/proc.MYD to /backup//2017-12-27_19-56-21/mysql/proc.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/procs_priv.frm to /backup//2017-12-27_19-56-21/mysql/procs_priv.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/procs_priv.MYI to /backup//2017-12-27_19-56-21/mysql/procs_priv.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/procs_priv.MYD to /backup//2017-12-27_19-56-21/mysql/procs_priv.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/general_log.frm to /backup//2017-12-27_19-56-21/mysql/general_log.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/general_log.CSM to /backup//2017-12-27_19-56-21/mysql/general_log.CSM
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/general_log.CSV to /backup//2017-12-27_19-56-21/mysql/general_log.CSV
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/slow_log.frm to /backup//2017-12-27_19-56-21/mysql/slow_log.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/slow_log.CSM to /backup//2017-12-27_19-56-21/mysql/slow_log.CSM
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/slow_log.CSV to /backup//2017-12-27_19-56-21/mysql/slow_log.CSV
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/event.frm to /backup//2017-12-27_19-56-21/mysql/event.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/event.MYI to /backup//2017-12-27_19-56-21/mysql/event.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/event.MYD to /backup//2017-12-27_19-56-21/mysql/event.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/ndb_binlog_index.frm to /backup//2017-12-27_19-56-21/mysql/ndb_binlog_index.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/ndb_binlog_index.MYI to /backup//2017-12-27_19-56-21/mysql/ndb_binlog_index.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/ndb_binlog_index.MYD to /backup//2017-12-27_19-56-21/mysql/ndb_binlog_index.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/proxies_priv.frm to /backup//2017-12-27_19-56-21/mysql/proxies_priv.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/proxies_priv.MYI to /backup//2017-12-27_19-56-21/mysql/proxies_priv.MYI
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./mysql/proxies_priv.MYD to /backup//2017-12-27_19-56-21/mysql/proxies_priv.MYD
171227 19:56:24 [01]        ...done
171227 19:56:24 [00] Writing test/db.opt
171227 19:56:24 [00]        ...done
171227 19:56:24 [01] Copying ./performance_schema/db.opt to /backup//2017-12-27_19-56-21/performance_schema/db.opt
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/cond_instances.frm to /backup//2017-12-27_19-56-21/performance_schema/cond_instances.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/events_waits_current.frm to /backup//2017-12-27_19-56-21/performance_schema/events_waits_current.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/events_waits_history.frm to /backup//2017-12-27_19-56-21/performance_schema/events_waits_history.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/events_waits_history_long.frm to /backup//2017-12-27_19-56-21/performance_schema/events_waits_history_long.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/events_waits_summary_by_instance.frm to /backup//2017-12-27_19-56-21/performance_schema/events_waits_summary_by_instance.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/events_waits_summary_by_thread_by_event_name.frm to /backup//2017-12-27_19-56-21/performance_schema/events_waits_summary_by_thread_by_event_name.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/events_waits_summary_global_by_event_name.frm to /backup//2017-12-27_19-56-21/performance_schema/events_waits_summary_global_by_event_name.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/file_instances.frm to /backup//2017-12-27_19-56-21/performance_schema/file_instances.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/file_summary_by_event_name.frm to /backup//2017-12-27_19-56-21/performance_schema/file_summary_by_event_name.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/file_summary_by_instance.frm to /backup//2017-12-27_19-56-21/performance_schema/file_summary_by_instance.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/mutex_instances.frm to /backup//2017-12-27_19-56-21/performance_schema/mutex_instances.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/performance_timers.frm to /backup//2017-12-27_19-56-21/performance_schema/performance_timers.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/rwlock_instances.frm to /backup//2017-12-27_19-56-21/performance_schema/rwlock_instances.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/setup_consumers.frm to /backup//2017-12-27_19-56-21/performance_schema/setup_consumers.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/setup_instruments.frm to /backup//2017-12-27_19-56-21/performance_schema/setup_instruments.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/setup_timers.frm to /backup//2017-12-27_19-56-21/performance_schema/setup_timers.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./performance_schema/threads.frm to /backup//2017-12-27_19-56-21/performance_schema/threads.frm
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./class/db.opt to /backup//2017-12-27_19-56-21/class/db.opt
171227 19:56:24 [01]        ...done
171227 19:56:24 [01] Copying ./class/tb.frm to /backup//2017-12-27_19-56-21/class/tb.frm
171227 19:56:25 [01]        ...done
171227 19:56:25 [01] Copying ./test1/db.opt to /backup//2017-12-27_19-56-21/test1/db.opt
171227 19:56:25 [01]        ...done
171227 19:56:25 [01] Copying ./test1/course.frm to /backup//2017-12-27_19-56-21/test1/course.frm
171227 19:56:25 [01]        ...done
171227 19:56:25 Finished backing up non-InnoDB tables and files
171227 19:56:25 [00] Writing xtrabackup_binlog_info
171227 19:56:25 [00]        ...done
171227 19:56:25 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
xtrabackup: The latest check point (for incremental): '1602621'
xtrabackup: Stopping log copying thread.
.171227 19:56:25 >> log scanned up to (1602621)

171227 19:56:25 Executing UNLOCK TABLES
171227 19:56:25 All tables unlocked
171227 19:56:25 Backup created in directory '/backup//2017-12-27_19-56-21'
MySQL binlog position: filename 'mysql-bin.000005', position '812'
171227 19:56:25 [00] Writing backup-my.cnf
171227 19:56:25 [00]        ...done
171227 19:56:25 [00] Writing xtrabackup_info
171227 19:56:25 [00]        ...done
xtrabackup: Transaction log of lsn (1602621) to (1602621) was copied.
171227 19:56:25 completed OK!
[rootredis-master01 ~]# ls /backup/
2017-12-27_19-56-21
[rootmysql-master1 ~]# cd /backup/2017-12-27_19-56-21/      注:下面增量备份的东西就放在此目录下
[rootmysql-master1 2017-12-27_19-56-21]# ls
backup-my.cnf  ibdata1  performance_schema  test1                   xtrabackup_checkpoints  xtrabackup_logfile
class          mysql    test                xtrabackup_binlog_info  xtrabackup_info
第三大步:进行增量备份
说明【增量备份 每个InnoDB的页面都会包含一个存储信息,每当相关的数据发生改变,相关 的页面的存储就会自动增长。这正是InnoDB表可以进行增量备份的基础,即 innobackupex通过备份上次完全备份之后发生改变的页面来实现 innobackupex命令会在备份目录中创建一个新的以时间命名的目录以存放所 有的增量备份数据。另外,在执行过增量备份之后再一次进行增量备份时,其 –incremental-basedir应该指向上一次的增量备份所在的目录 注:增量备份仅能应用于InnoDB或XtraDB表,对于MyISAM表而言 ,执行增量备份时其实进行的是完全备份】
1.向表中插入新增数据
[rootmysql-master1 ~]# mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.52-MariaDB MariaDB Server

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

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

MariaDB [(none)]> insert into test1.course values(002,'linux');
Query OK, 1 row affected (0.21 sec)

MariaDB [(none)]> select * from test1.course;
+------+-------+
| id   | name  |
+------+-------+
|    1 | math  |
|    2 | linux |
+------+-------+
2 rows in set (0.00 sec)

MariaDB [(none)]> exit;
Bye
2.进行增量备份:
[rootmysql-master1 ~]# innobackupex --incremental /backup/ --incremental-basedir=/backup/2017-12-27_19-56-21/  注:此目录为全量备份所在目录,也即指明在哪的基础上进行增量备份
171227 20:05:28 innobackupex: Starting the backup operation

IMPORTANT: Please check that the backup run completes successfully.
           At the end of a successful backup run innobackupex
           prints "completed OK!".

Can't locate Digest/MD5.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 - line 693.
BEGIN failed--compilation aborted at - line 693.
171227 20:05:28 Connecting to MySQL server host: localhost, user: (null), password: not set, port: 0, socket: /var/lib/mysql/mysql.sock
Using server version 5.5.52-MariaDB
innobackupex version 2.3.6 based on MySQL server 5.6.24 Linux (x86_64) (revision id: )
incremental backup from 1602621 is enabled.
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
171227 20:05:28 >> log scanned up to (1603665)
xtrabackup: Generating a list of tablespaces
xtrabackup: using the full scan for incremental backup
171227 20:05:29 [01] Copying ./ibdata1 to /backup//2017-12-27_20-05-28/ibdata1.delta
171227 20:05:29 [01]        ...done
171227 20:05:29 >> log scanned up to (1603665)
171227 20:05:29 Executing FLUSH NO_WRITE_TO_BINLOG TABLES...
171227 20:05:29 Executing FLUSH TABLES WITH READ LOCK...
171227 20:05:29 Starting to backup non-InnoDB tables and files
171227 20:05:29 [01] Copying ./mysql/db.frm to /backup//2017-12-27_20-05-28/mysql/db.frm
171227 20:05:29 [01]        ...done
171227 20:05:29 [01] Copying ./mysql/db.MYI to /backup//2017-12-27_20-05-28/mysql/db.MYI
171227 20:05:29 [01]        ...done
171227 20:05:29 [01] Copying ./mysql/db.MYD to /backup//2017-12-27_20-05-28/mysql/db.MYD
171227 20:05:29 [01]        ...done
171227 20:05:29 [01] Copying ./mysql/host.frm to /backup//2017-12-27_20-05-28/mysql/host.frm
171227 20:05:29 [01]        ...done
171227 20:05:29 [01] Copying ./mysql/host.MYI to /backup//2017-12-27_20-05-28/mysql/host.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/host.MYD to /backup//2017-12-27_20-05-28/mysql/host.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/user.frm to /backup//2017-12-27_20-05-28/mysql/user.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/user.MYI to /backup//2017-12-27_20-05-28/mysql/user.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/user.MYD to /backup//2017-12-27_20-05-28/mysql/user.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/func.frm to /backup//2017-12-27_20-05-28/mysql/func.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/func.MYI to /backup//2017-12-27_20-05-28/mysql/func.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/func.MYD to /backup//2017-12-27_20-05-28/mysql/func.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/plugin.frm to /backup//2017-12-27_20-05-28/mysql/plugin.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/plugin.MYI to /backup//2017-12-27_20-05-28/mysql/plugin.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/plugin.MYD to /backup//2017-12-27_20-05-28/mysql/plugin.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/servers.frm to /backup//2017-12-27_20-05-28/mysql/servers.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/servers.MYI to /backup//2017-12-27_20-05-28/mysql/servers.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/servers.MYD to /backup//2017-12-27_20-05-28/mysql/servers.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/tables_priv.frm to /backup//2017-12-27_20-05-28/mysql/tables_priv.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/tables_priv.MYI to /backup//2017-12-27_20-05-28/mysql/tables_priv.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/tables_priv.MYD to /backup//2017-12-27_20-05-28/mysql/tables_priv.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/columns_priv.frm to /backup//2017-12-27_20-05-28/mysql/columns_priv.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/columns_priv.MYI to /backup//2017-12-27_20-05-28/mysql/columns_priv.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/columns_priv.MYD to /backup//2017-12-27_20-05-28/mysql/columns_priv.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_topic.frm to /backup//2017-12-27_20-05-28/mysql/help_topic.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_topic.MYI to /backup//2017-12-27_20-05-28/mysql/help_topic.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_topic.MYD to /backup//2017-12-27_20-05-28/mysql/help_topic.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_category.frm to /backup//2017-12-27_20-05-28/mysql/help_category.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_category.MYI to /backup//2017-12-27_20-05-28/mysql/help_category.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_category.MYD to /backup//2017-12-27_20-05-28/mysql/help_category.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_relation.frm to /backup//2017-12-27_20-05-28/mysql/help_relation.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_relation.MYI to /backup//2017-12-27_20-05-28/mysql/help_relation.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_relation.MYD to /backup//2017-12-27_20-05-28/mysql/help_relation.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_keyword.frm to /backup//2017-12-27_20-05-28/mysql/help_keyword.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_keyword.MYI to /backup//2017-12-27_20-05-28/mysql/help_keyword.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/help_keyword.MYD to /backup//2017-12-27_20-05-28/mysql/help_keyword.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_name.frm to /backup//2017-12-27_20-05-28/mysql/time_zone_name.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_name.MYI to /backup//2017-12-27_20-05-28/mysql/time_zone_name.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_name.MYD to /backup//2017-12-27_20-05-28/mysql/time_zone_name.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone.frm to /backup//2017-12-27_20-05-28/mysql/time_zone.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone.MYI to /backup//2017-12-27_20-05-28/mysql/time_zone.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone.MYD to /backup//2017-12-27_20-05-28/mysql/time_zone.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_transition.frm to /backup//2017-12-27_20-05-28/mysql/time_zone_transition.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_transition.MYI to /backup//2017-12-27_20-05-28/mysql/time_zone_transition.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_transition.MYD to /backup//2017-12-27_20-05-28/mysql/time_zone_transition.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_transition_type.frm to /backup//2017-12-27_20-05-28/mysql/time_zone_transition_type.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_transition_type.MYI to /backup//2017-12-27_20-05-28/mysql/time_zone_transition_type.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_transition_type.MYD to /backup//2017-12-27_20-05-28/mysql/time_zone_transition_type.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_leap_second.frm to /backup//2017-12-27_20-05-28/mysql/time_zone_leap_second.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_leap_second.MYI to /backup//2017-12-27_20-05-28/mysql/time_zone_leap_second.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/time_zone_leap_second.MYD to /backup//2017-12-27_20-05-28/mysql/time_zone_leap_second.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/proc.frm to /backup//2017-12-27_20-05-28/mysql/proc.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/proc.MYI to /backup//2017-12-27_20-05-28/mysql/proc.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/proc.MYD to /backup//2017-12-27_20-05-28/mysql/proc.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/procs_priv.frm to /backup//2017-12-27_20-05-28/mysql/procs_priv.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/procs_priv.MYI to /backup//2017-12-27_20-05-28/mysql/procs_priv.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/procs_priv.MYD to /backup//2017-12-27_20-05-28/mysql/procs_priv.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/general_log.frm to /backup//2017-12-27_20-05-28/mysql/general_log.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/general_log.CSM to /backup//2017-12-27_20-05-28/mysql/general_log.CSM
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/general_log.CSV to /backup//2017-12-27_20-05-28/mysql/general_log.CSV
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/slow_log.frm to /backup//2017-12-27_20-05-28/mysql/slow_log.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/slow_log.CSM to /backup//2017-12-27_20-05-28/mysql/slow_log.CSM
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/slow_log.CSV to /backup//2017-12-27_20-05-28/mysql/slow_log.CSV
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/event.frm to /backup//2017-12-27_20-05-28/mysql/event.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/event.MYI to /backup//2017-12-27_20-05-28/mysql/event.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/event.MYD to /backup//2017-12-27_20-05-28/mysql/event.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/ndb_binlog_index.frm to /backup//2017-12-27_20-05-28/mysql/ndb_binlog_index.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/ndb_binlog_index.MYI to /backup//2017-12-27_20-05-28/mysql/ndb_binlog_index.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/ndb_binlog_index.MYD to /backup//2017-12-27_20-05-28/mysql/ndb_binlog_index.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/proxies_priv.frm to /backup//2017-12-27_20-05-28/mysql/proxies_priv.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/proxies_priv.MYI to /backup//2017-12-27_20-05-28/mysql/proxies_priv.MYI
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./mysql/proxies_priv.MYD to /backup//2017-12-27_20-05-28/mysql/proxies_priv.MYD
171227 20:05:30 [01]        ...done
171227 20:05:30 [00] Writing test/db.opt
171227 20:05:30 [00]        ...done
171227 20:05:30 [01] Copying ./performance_schema/db.opt to /backup//2017-12-27_20-05-28/performance_schema/db.opt
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/cond_instances.frm to /backup//2017-12-27_20-05-28/performance_schema/cond_instances.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/events_waits_current.frm to /backup//2017-12-27_20-05-28/performance_schema/events_waits_current.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/events_waits_history.frm to /backup//2017-12-27_20-05-28/performance_schema/events_waits_history.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/events_waits_history_long.frm to /backup//2017-12-27_20-05-28/performance_schema/events_waits_history_long.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/events_waits_summary_by_instance.frm to /backup//2017-12-27_20-05-28/performance_schema/events_waits_summary_by_instance.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/events_waits_summary_by_thread_by_event_name.frm to /backup//2017-12-27_20-05-28/performance_schema/events_waits_summary_by_thread_by_event_name.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/events_waits_summary_global_by_event_name.frm to /backup//2017-12-27_20-05-28/performance_schema/events_waits_summary_global_by_event_name.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/file_instances.frm to /backup//2017-12-27_20-05-28/performance_schema/file_instances.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/file_summary_by_event_name.frm to /backup//2017-12-27_20-05-28/performance_schema/file_summary_by_event_name.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/file_summary_by_instance.frm to /backup//2017-12-27_20-05-28/performance_schema/file_summary_by_instance.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/mutex_instances.frm to /backup//2017-12-27_20-05-28/performance_schema/mutex_instances.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/performance_timers.frm to /backup//2017-12-27_20-05-28/performance_schema/performance_timers.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/rwlock_instances.frm to /backup//2017-12-27_20-05-28/performance_schema/rwlock_instances.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/setup_consumers.frm to /backup//2017-12-27_20-05-28/performance_schema/setup_consumers.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/setup_instruments.frm to /backup//2017-12-27_20-05-28/performance_schema/setup_instruments.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/setup_timers.frm to /backup//2017-12-27_20-05-28/performance_schema/setup_timers.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./performance_schema/threads.frm to /backup//2017-12-27_20-05-28/performance_schema/threads.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./class/db.opt to /backup//2017-12-27_20-05-28/class/db.opt
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./class/tb.frm to /backup//2017-12-27_20-05-28/class/tb.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./test1/db.opt to /backup//2017-12-27_20-05-28/test1/db.opt
171227 20:05:30 [01]        ...done
171227 20:05:30 [01] Copying ./test1/course.frm to /backup//2017-12-27_20-05-28/test1/course.frm
171227 20:05:30 [01]        ...done
171227 20:05:30 Finished backing up non-InnoDB tables and files
171227 20:05:30 [00] Writing xtrabackup_binlog_info
171227 20:05:30 [00]        ...done
171227 20:05:30 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
xtrabackup: The latest check point (for incremental): '1603665'
xtrabackup: Stopping log copying thread.
.171227 20:05:30 >> log scanned up to (1603665)

171227 20:05:30 Executing UNLOCK TABLES
171227 20:05:30 All tables unlocked
171227 20:05:30 Backup created in directory '/backup//2017-12-27_20-05-28'
MySQL binlog position: filename 'mysql-bin.000005', position '1006'
171227 20:05:30 [00] Writing backup-my.cnf
171227 20:05:30 [00]        ...done
171227 20:05:30 [00] Writing xtrabackup_info
171227 20:05:30 [00]        ...done
xtrabackup: Transaction log of lsn (1603665) to (1603665) was copied.
171227 20:05:30 completed OK!
第四大步:模拟故障,进行数据库恢复
说明:【数据恢复准备: 一般情况下,在备份完成后,数据尚且不能用于恢复操作, 因为备份的数据中 可能会包含尚未提交的事务或已经提交但尚未同步至数据文件中的事务。因此 ,此时数据文件仍处理不一致状态。 准备”的主要作用正是通过回滚未提交 的事务及同步已经提交的事务至数据文件也使得数据文件处于一致性状态 “ 准备”(prepare)增量备份与整理完全备份有着一些不同,
尤其要注意的是:
(1)需要在每个备份(包括完全和各个增量备份)上,将已经提交的事务进行“重放”。“重放”之后 ,所有的备份数据将合并到完全备份上
(2)基于所有的备份将未提交的事务进行“回滚”。
1.数据恢复准备
[rootmysql-master ~]# ls /backup/
2017-12-27_19-56-21  2017-12-27_20-05-28
执行操作(首先进行完全备份):innobackupex --apply-log --redo-only 2017-12-27_19-56-21 
接着执行增量:innobackupex --apply-log --redo-only  2017-12-27_19-56-21   --incrementaldir=2017-12-27_20-05-28            
【 注:需指明完全备份和增量备份目录,2017-12-27_19-56-21是完全备份目录,2017-12-27_20-05-28是增量备份目录】
2.模拟不小心删除数据库,并进行数据库恢复
(1)不小心删除数据库
[rootmysql-master ~]# cd /var/lib/mysql
[rootmysql-master mysql]# ls
aria_log.00000001  ib_logfile0  mysql-bin.000001  mysql-bin.000005        mysql.sock          test1
aria_log_control   ib_logfile1  mysql-bin.000002  mysql-bin.index         performance_schema
class              master.info  mysql-bin.000003  mysql-relay-log.000005  relay-log.info
ibdata1            mysql        mysql-bin.000004  mysql-relay-log.index   test
[rootmysql-master mysql]# rm -rf test1
[rootmysql-master mysql]# mysql -uroot
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| class              |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.10 sec)
(2)进行数据库恢复
[rootmysql-master]# innobackupex --copy-back /backup/2017-12-27_19-56-21/此处目录指定为全量备份时的目录,所以最终恢复后也只是全
量备份的数据,不能恢复完全
171227 20:43:45 innobackupex: Starting the copy-back operation

IMPORTANT: Please check that the copy-back run completes successfully.
           At the end of a successful copy-back run innobackupex
           prints "completed OK!".

innobackupex version 2.3.6 based on MySQL server 5.6.24 Linux (x86_64) (revision id: )
Original data directory /var/lib/mysql is not empty!
由于实验的时候忘记执行上面的数据恢复准备操作了,所以造成以上错误!
解决方案:
(3)
[rootmysql-master mysql]# cd /var/lib
[rootmysql-master lib]# cp -a mysql mysql.bak
[rootmysql-master lib]# rm -rf mysql
[rootmysql-master lib]# mkdir mysql
[rootmysql-master lib]# cd mysql
[rootmysql-master mysql]# ls
[rootmysql-master mysql]# innobackupex --copy-back /backup/2017-12-27_19-56-21/
171227 20:40:36 innobackupex: Starting the copy-back operation

IMPORTANT: Please check that the copy-back run completes successfully.
           At the end of a successful copy-back run innobackupex
           prints "completed OK!".
第五大步:连接数据库,查看数据库是否恢复
[rootmysql-master mysql]# chown -R mysql.mysql /var/lib/mysql
[rootmysql-master mysql]# systemctl restart mariadb
[rootmysql-master mysql]# mysql -uroot
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, 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 |
| class              |
| mysql              |
| performance_schema |
| test               |
| test1              |
+--------------------+
6 rows in set (0.00 sec)

MariaDB [(none)]> select * from test1.course;
+------+------+
| id   | name |
+------+------+
|    1 | math |
+------+------+
1 row in set (0.00 sec)

MariaDB [(none)]> exit;
Bye
注意:这里只恢复到第一次完整备份的状态,因为在执行 innobackupex --copy-back /backup/2017-12-27_19-56-21/恢复数据时备份目录指定错误,2017-12-27_19-56-21/是增量备份的目录,执行时看错了
由于前面忘了进行数据的重放和回滚,所以又重新创建了一个数据库重新演示一下
1.[rootmysql-master ~]# innobackupex --apply-log --redo-only 2017-12-27_21-11-13
171227 21:20:58 innobackupex: Starting the apply-log operation

IMPORTANT: Please check that the apply-log run completes successfully.
           At the end of a successful apply-log run innobackupex
           prints "completed OK!".

innobackupex version 2.3.6 based on MySQL server 5.6.24 Linux (x86_64) (revision id: )
innobackupex: Can't change dir to '/root/2017-12-27_21-11-13' (Errcode: 2 - No such file or directory)
xtrabackup: cannot my_setwd /root/2017-12-27_21-11-13
解决方法:带上路径,就好了,如下
[rootmysql-master ~]# innobackupex --apply-log --redo-only /backup/
171227 21:21:36 innobackupex: Starting the apply-log operation

IMPORTANT: Please check that the apply-log run completes successfully.
           At the end of a successful apply-log run innobackupex
           prints "completed OK!".
2.[rootmysql-master ~]# innobackupex --apply-log --redo-only /backup/2017-12-27_21-11-13 --incrementaldir=/backup/2017-12-27_21-13-57
3.模拟数据库误删除
[rootmysql-master mysql]# rm -rf test1
[rootmysql-master mysql]# ls /backup/
2017-12-27_21-11-13  2017-12-27_21-13-57
[rootmysql-master mysql]# innobackupex --copy-back /backup/2017-12-27_21-11-13 【注:全量备份目录】
171227 21:33:21 innobackupex: Starting the copy-back operation

IMPORTANT: Please check that the copy-back run completes successfully.
           At the end of a successful copy-back run innobackupex
           prints "completed OK!".

innobackupex version 2.3.6 based on MySQL server 5.6.24 Linux (x86_64) (revision id: )
Original data directory /var/lib/mysql is not empty!
恢复的时候发现出现如上错误
解决方法:删除/var/lib/mysql下的所有文件
[rootmysql-master mysql]# rm -rf *    
[rootmysql-master mysql]# ls
[rootmysql-master mysql]# innobackupex --copy-back /backup/2017-12-27_21-11-13 成功执行,此目录一定要是全量备份的目录,所以执行命
令的时候一定要找准
171227 21:35:41 innobackupex: Starting the copy-back operation
[rootmysql-master mysql]# chown -R mysql.mysql ./*
[rootmysql-master mysql]# systemctl start mariadb
查看数据恢复情况:成功恢复
MariaDB [(none)]> select * from test1.course;
+------+-------+
| id   | name  |
+------+-------+
|    1 | math  |
|    2 | linux |
+------+-------+















你可能感兴趣的:(linux,运维)