1、安装xtrabackup工具
以下测试安装xtrabackup备份恢复工具的二进制包,进行测试。安装的路径为mysql安装路径,本次测试mysql的安装路径为:/usr/local/mysql。
tar -zxvf percona-xtrabackup-2.3.4-Linux-x86_64.tar.gz
cp percona-xtrabackup-2.3.4-Linux-x86_64 /usr/local/mysql/bin
2、创建备份用户
建备份用户backup@localhost,xtraback只能用于本地操作,故只授权本地操作。
GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO backup@localhost;
3、声明PATH环境变量
为xtrabackup备份恢复工具添加到PATH路径中。
export PATH=$PATH:/usr/local/mysql/bin
4、创建测试库
创建测试库backup_test,测试表test。
mysql -uroot -poracle -S/tmp/mysql.sock -e 'create database backup_test;'
mysql -uroot -poracle -S/tmp/mysql.sock -e 'create table backup_test.test(id int);'
mysql -uroot -poracle -S/tmp/mysql.sock -e'insert into backup_test.test values(1),(2),(3),(4),(5);'
mysql -uroot -poracle -S/tmp/mysql.sock -e'select * from backup_test.test;'
[root@mysql2 bin]#
/usr/local/mysql/bin/innobackupex --defaults-file=/etc/my.cnf --user=root --password=oracle /mysql/backup
160517 19:06:08 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!".
160517 19:06:08 version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;port=3306;mysql_socket=/tmp/mysql.sock' as 'root' (using password: YES).
160517 19:06:08 version_check Connected to MySQL server
160517 19:06:08 version_check Executing a version check against the server...
160517 19:06:08 version_check Done.
160517 19:06:08 Connecting to MySQL server host: localhost, user: root, password: set, port: 3306, socket: /tmp/mysql.sock
Using server version 5.6.27-log
/usr/local/mysql/bin/innobackupex version 2.3.4 based on MySQL server 5.6.24 Linux (x86_64) (revision id: e80c779)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /mysql/data
xtrabackup: open files limit requested 0, set to 1024
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = /mysql/data
xtrabackup: innodb_data_file_path = ibdata1:128M:autoextend
xtrabackup: innodb_log_group_home_dir = /mysql/logs
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 1073741824
160517 19:06:08 >>
log scanned up to (1634958)
xtrabackup: Generating a list of tablespaces
160517 19:06:08 [01]
Copying /mysql/data/ibdata1 to /mysql/backup/2016-05-17_19-06-08/ibdata1
160517 19:06:09 >>
log scanned up to (1634958)
160517 19:06:10 >>
log scanned up to (1634958)
160517 19:06:10 [01] ...done
160517 19:06:10 [01] Copying ./mysql/slave_relay_log_info.ibd to /mysql/backup/2016-05-17_19-06-08/mysql/slave_relay_log_info.ibd
160517 19:06:10 [01] ...done
160517 19:06:10 [01] Copying ./mysql/slave_worker_info.ibd to /mysql/backup/2016-05-17_19-06-08/mysql/slave_worker_info.ibd
160517 19:06:10 [01] ...done
160517 19:06:10 [01] Copying ./mysql/slave_master_info.ibd to /mysql/backup/2016-05-17_19-06-08/mysql/slave_master_info.ibd
160517 19:06:10 [01] ...done
160517 19:06:10 [01] Copying ./mysql/innodb_index_stats.ibd to /mysql/backup/2016-05-17_19-06-08/mysql/innodb_index_stats.ibd
160517 19:06:10 [01] ...done
160517 19:06:10 [01] Copying ./mysql/innodb_table_stats.ibd to /mysql/backup/2016-05-17_19-06-08/mysql/innodb_table_stats.ibd
160517 19:06:10 [01] ...done
160517 19:06:10 [01] Copying ./backup_test/test.ibd to /mysql/backup/2016-05-17_19-06-08/backup_test/test.ibd
160517 19:06:10 [01] ...done
160517 19:06:11 >>
log scanned up to (1634958)
160517 19:06:11 Executing
FLUSH NO_WRITE_TO_BINLOG TABLES...
160517 19:06:11 Executing
FLUSH TABLES WITH READ LOCK...
160517 19:06:11
Starting to backup non-InnoDB tables and files
160517 19:06:11 [01] Copying ./mysql/slow_log.CSV to /mysql/backup/2016-05-17_19-06-08/mysql/slow_log.CSV
160517 19:06:11 [01] ...done
160517 19:06:11 [01] Copying ./mysql/columns_priv.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/columns_priv.MYD
160517 19:06:11 [01] ...done
160517 19:06:11 [01] Copying ./mysql/innodb_index_stats.frm to /mysql/backup/2016-05-17_19-06-08/mysql/innodb_index_stats.frm
160517 19:06:11 [01] ...done
160517 19:06:11 [01] Copying ./mysql/time_zone.frm to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone.frm
160517 19:06:11 [01] ...done
160517 19:06:11 [01] Copying ./mysql/slave_master_info.frm to /mysql/backup/2016-05-17_19-06-08/mysql/slave_master_info.frm
160517 19:06:11 [01] ...done
160517 19:06:11 [01] Copying ./mysql/time_zone_transition_type.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_transition_type.MYD
160517 19:06:11 [01] ...done
160517 19:06:11 [01] Copying ./mysql/tables_priv.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/tables_priv.MYD
160517 19:06:11 [01] ...done
160517 19:06:11 [01] Copying ./mysql/proc.frm to /mysql/backup/2016-05-17_19-06-08/mysql/proc.frm
160517 19:06:11 [01] ...done
160517 19:06:11 [01] Copying ./mysql/servers.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/servers.MYI
160517 19:06:11 [01] ...done
160517 19:06:12 [01] Copying ./mysql/columns_priv.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/columns_priv.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/procs_priv.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/procs_priv.MYD
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/time_zone_transition.frm to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_transition.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/tables_priv.frm to /mysql/backup/2016-05-17_19-06-08/mysql/tables_priv.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/help_relation.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/help_relation.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/help_category.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/help_category.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/help_topic.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/help_topic.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/proc.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/proc.MYD
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/servers.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/servers.MYD
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/db.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/db.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/plugin.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/plugin.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/db.frm to /mysql/backup/2016-05-17_19-06-08/mysql/db.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/event.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/event.MYD
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/func.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/func.MYD
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/columns_priv.frm to /mysql/backup/2016-05-17_19-06-08/mysql/columns_priv.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/time_zone_name.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_name.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/servers.frm to /mysql/backup/2016-05-17_19-06-08/mysql/servers.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/time_zone.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/time_zone_transition_type.frm to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_transition_type.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/procs_priv.frm to /mysql/backup/2016-05-17_19-06-08/mysql/procs_priv.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/slave_relay_log_info.frm to /mysql/backup/2016-05-17_19-06-08/mysql/slave_relay_log_info.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/plugin.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/plugin.MYD
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/tables_priv.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/tables_priv.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/ndb_binlog_index.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/ndb_binlog_index.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/db.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/db.MYD
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/help_relation.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/help_relation.MYD
160517 19:06:12 [01] ...done
160517 19:06:12 >>
log scanned up to (1634958)
160517 19:06:12 [01] Copying ./mysql/user.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/user.MYD
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/func.frm to /mysql/backup/2016-05-17_19-06-08/mysql/func.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/innodb_table_stats.frm to /mysql/backup/2016-05-17_19-06-08/mysql/innodb_table_stats.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/general_log.frm to /mysql/backup/2016-05-17_19-06-08/mysql/general_log.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/help_keyword.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/help_keyword.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/ndb_binlog_index.frm to /mysql/backup/2016-05-17_19-06-08/mysql/ndb_binlog_index.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/event.frm to /mysql/backup/2016-05-17_19-06-08/mysql/event.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/help_topic.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/help_topic.MYD
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/slow_log.CSM to /mysql/backup/2016-05-17_19-06-08/mysql/slow_log.CSM
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/user.frm to /mysql/backup/2016-05-17_19-06-08/mysql/user.frm
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/time_zone_transition.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_transition.MYD
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/time_zone_transition_type.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_transition_type.MYI
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/general_log.CSV to /mysql/backup/2016-05-17_19-06-08/mysql/general_log.CSV
160517 19:06:12 [01] ...done
160517 19:06:12 [01] Copying ./mysql/slow_log.frm to /mysql/backup/2016-05-17_19-06-08/mysql/slow_log.frm
160517 19:06:12 [01] ...done
160517 19:06:13 [01] Copying ./mysql/time_zone.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone.MYD
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/help_category.frm to /mysql/backup/2016-05-17_19-06-08/mysql/help_category.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/user.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/user.MYI
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/plugin.frm to /mysql/backup/2016-05-17_19-06-08/mysql/plugin.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/help_keyword.frm to /mysql/backup/2016-05-17_19-06-08/mysql/help_keyword.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/help_category.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/help_category.MYD
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/time_zone_leap_second.frm to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_leap_second.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/event.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/event.MYI
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/help_topic.frm to /mysql/backup/2016-05-17_19-06-08/mysql/help_topic.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/proc.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/proc.MYI
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/func.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/func.MYI
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/general_log.CSM to /mysql/backup/2016-05-17_19-06-08/mysql/general_log.CSM
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/time_zone_leap_second.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_leap_second.MYI
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/proxies_priv.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/proxies_priv.MYI
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/proxies_priv.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/proxies_priv.MYD
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/time_zone_name.frm to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_name.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/slave_worker_info.frm to /mysql/backup/2016-05-17_19-06-08/mysql/slave_worker_info.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/proxies_priv.frm to /mysql/backup/2016-05-17_19-06-08/mysql/proxies_priv.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/help_relation.frm to /mysql/backup/2016-05-17_19-06-08/mysql/help_relation.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/procs_priv.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/procs_priv.MYI
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/help_keyword.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/help_keyword.MYD
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/time_zone_transition.MYI to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_transition.MYI
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/time_zone_leap_second.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_leap_second.MYD
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/time_zone_name.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/time_zone_name.MYD
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./mysql/ndb_binlog_index.MYD to /mysql/backup/2016-05-17_19-06-08/mysql/ndb_binlog_index.MYD
160517 19:06:13 [01] ...done
160517 19:06:13 [00] Writing test/db.opt
160517 19:06:13 [00] ...done
160517 19:06:13 >> log scanned up to (1634958)
160517 19:06:13 [01] Copying ./performance_schema/events_stages_summary_by_thread_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_stages_summary_by_thread_by_event_name.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/events_waits_summary_by_user_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_waits_summary_by_user_by_event_name.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/events_stages_history_long.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_stages_history_long.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/events_statements_summary_by_host_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_statements_summary_by_host_by_event_name.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/socket_summary_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/socket_summary_by_event_name.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/setup_consumers.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/setup_consumers.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/events_waits_summary_global_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_waits_summary_global_by_event_name.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/events_statements_history_long.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_statements_history_long.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/hosts.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/hosts.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/table_lock_waits_summary_by_table.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/table_lock_waits_summary_by_table.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/events_statements_current.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_statements_current.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/mutex_instances.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/mutex_instances.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/events_stages_summary_by_host_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_stages_summary_by_host_by_event_name.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/cond_instances.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/cond_instances.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/events_statements_summary_by_account_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_statements_summary_by_account_by_event_name.frm
160517 19:06:13 [01] ...done
160517 19:06:13 [01] Copying ./performance_schema/db.opt to /mysql/backup/2016-05-17_19-06-08/performance_schema/db.opt
160517 19:06:13 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_stages_summary_by_user_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_stages_summary_by_user_by_event_name.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_stages_summary_global_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_stages_summary_global_by_event_name.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/table_io_waits_summary_by_table.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/table_io_waits_summary_by_table.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/file_summary_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/file_summary_by_event_name.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/performance_timers.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/performance_timers.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/threads.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/threads.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_statements_summary_global_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_statements_summary_global_by_event_name.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/session_account_connect_attrs.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/session_account_connect_attrs.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_waits_current.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_waits_current.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/setup_instruments.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/setup_instruments.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_waits_history.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_waits_history.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/host_cache.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/host_cache.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_stages_history.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_stages_history.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/rwlock_instances.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/rwlock_instances.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/setup_timers.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/setup_timers.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/session_connect_attrs.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/session_connect_attrs.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_statements_summary_by_digest.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_statements_summary_by_digest.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/accounts.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/accounts.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_waits_summary_by_instance.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_waits_summary_by_instance.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_statements_summary_by_user_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_statements_summary_by_user_by_event_name.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_waits_summary_by_thread_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_waits_summary_by_thread_by_event_name.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_waits_history_long.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_waits_history_long.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/setup_actors.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/setup_actors.frm
160517 19:06:14 [01] ...done
160517 19:06:14 >> log scanned up to (1634958)
160517 19:06:14 [01] Copying ./performance_schema/socket_summary_by_instance.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/socket_summary_by_instance.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/setup_objects.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/setup_objects.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/table_io_waits_summary_by_index_usage.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/table_io_waits_summary_by_index_usage.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/file_summary_by_instance.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/file_summary_by_instance.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_statements_summary_by_thread_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_statements_summary_by_thread_by_event_name.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/file_instances.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/file_instances.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_statements_history.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_statements_history.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_waits_summary_by_host_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_waits_summary_by_host_by_event_name.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/objects_summary_global_by_type.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/objects_summary_global_by_type.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/users.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/users.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_stages_current.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_stages_current.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_waits_summary_by_account_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_waits_summary_by_account_by_event_name.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/socket_instances.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/socket_instances.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./performance_schema/events_stages_summary_by_account_by_event_name.frm to /mysql/backup/2016-05-17_19-06-08/performance_schema/events_stages_summary_by_account_by_event_name.frm
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./backup_test/db.opt to /mysql/backup/2016-05-17_19-06-08/backup_test/db.opt
160517 19:06:14 [01] ...done
160517 19:06:14 [01] Copying ./backup_test/test.frm to /mysql/backup/2016-05-17_19-06-08/backup_test/test.frm
160517 19:06:14 [01] ...done
160517 19:06:14 Finished backing up non-InnoDB tables and files
160517 19:06:14 [00] Writing xtrabackup_binlog_info
160517 19:06:14 [00] ...done
160517 19:06:14 Executing
FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
xtrabackup: The latest check point (for incremental): '1634958'
xtrabackup: Stopping log copying thread.
.160517 19:06:14 >> log scanned up to (1634958)
160517 19:06:15
Executing UNLOCK TABLES
160517 19:06:15 All tables unlocked
160517 19:06:15 Backup created in directory '/mysql/backup/2016-05-17_19-06-08'
MySQL binlog position: filename 'mysql-bin.000004', position '562'
160517 19:06:15 [00] Writing backup-my.cnf
160517 19:06:15 [00] ...done
160517 19:06:15 [00] Writing xtrabackup_info
160517 19:06:15 [00] ...done
xtrabackup: Transaction log of lsn (1634958) to (1634958) was copied.
160517 19:06:15 completed OK!
[root@mysql2 bin]#
1:innobackupex 在启动后,会先 fork 一个进程,启动 xtrabackup进程,然后就等待 xtrabackup 备份完 ibd 数据文件;
2:xtrabackup 在备份 InnoDB 相关数据时,是有2种线程的,1种是 redo 拷贝线程,负责拷贝 redo 文件,1种是 ibd 拷贝线程,负责拷贝 ibd 文件;
redo 拷贝线程只有一个,在 ibd 拷贝线程之前启动,在 ibd 线程结束后结束。xtrabackup 进程开始执行后,先启动 redo 拷贝线程,从最新的 checkpoint 点开始顺序拷贝 redo 日志;然后再启动 ibd 数据拷贝线程,在 xtrabackup 拷贝 ibd 过程中,innobackupex 进程一直处于等待状态(等待文件被创建)。
3:xtrabackup 拷贝完成idb后,通知 innobackupex(通过创建文件),同时自己进入等待(redo 线程仍然继续拷贝);
4:innobackupex 收到 xtrabackup 通知后,执行FLUSH TABLES WITH READ LOCK (FTWRL),取得一致性位点,然后开始备份非 InnoDB 文件
(包括 frm、MYD、MYI、CSV、opt、par等)。拷贝非 InnoDB 文件过程中,因为数据库处于全局只读状态,如果在业务的主库备份的话,要特别小心,
非 InnoDB 表(主要是MyISAM)比较多的话整库只读时间就会比较长,这个影响一定要评估到。
5:当 innobackupex 拷贝完所有非 InnoDB 表文件后,通知 xtrabackup(通过删文件) ,同时自己进入等待(等待另一个文件被创建);
6:xtrabackup 收到 innobackupex 备份完非 InnoDB 通知后,就停止 redo 拷贝线程,然后通知 innobackupex redo log 拷贝完成(通过创建文件);
7:innobackupex 收到 redo 备份完成通知后,就开始解锁,执行 UNLOCK TABLES;
8:最后 innobackupex 和 xtrabackup 进程各自完成收尾工作,如资源的释放、写备份元数据信息等,innobackupex 等待 xtrabackup 子进程结束后退出。
在上面描述的文件拷贝,都是备份进程直接通过操作系统读取数据文件的,只在执行 SQL 命令时和数据库有交互,基本不影响数据库的运行,在备份非 InnoDB 时会有一段时间只读(如果没有MyISAM表的话,只读时间在几秒左右),在备份 InnoDB 数据文件时,对数据库完全没有影响,是真正的热备。
InnoDB 和非 InnoDB 文件的备份都是通过拷贝文件来做的,但是实现的方式不同,前者是以page为粒度做的(xtrabackup),
后者是 cp 或者 tar 命令(innobackupex),xtrabackup 在读取每个page时会校验 checksum 值,保证数据块是一致的,
而 innobackupex 在 cp MyISAM 文件时已经做了flush(FTWRL),磁盘上的文件也是完整的,所以最终备份集里的数据文件都是写入完整的。
参考文档:http://mysql.taobao.org/monthly/2016/03/07/