xtrabackup原理
- xtrabackup_suspended_1
- xtrabackup_suspended_2
- xtrabackup_log_copied
- innobackupex 在启动后,会先 fork 一个进程,启动 xtrabackup进程,然后就等待 xtrabackup 备份完 ibd 数据文件;
- xtrabackup 在备份 InnoDB 相关数据时,是有2种线程的,一种是 redo 拷贝线程,负责拷贝 redo 文件,一种是 ibd 拷贝线程,负责拷贝 ibd 文件;redo 拷贝线程只有一个,在 ibd 拷贝线程之前启动,在 ibd 线程结束后结束。xtrabackup 进程开始执行后,先启动 redo 拷贝线程,从最新的 checkpoint 点开始顺序拷贝 redo 日志;然后再启动 ibd 数据拷贝线程,在 xtrabackup 拷贝 ibd 过程中,innobackupex 进程一直处于等待状态(等待文件被创建)。
- xtrabackup 拷贝完成idb后,通知 innobackupex(通过创建文件),同时自己进入等待(redo 线程仍然继续拷贝);
- innobackupex 收到 xtrabackup 通知后,执行FLUSH TABLES WITH READ LOCK (FTWRL),取得一致性位点,然后开始备份非 InnoDB 文件(包括 frm、MYD、MYI、CSV、opt、par等)。拷贝非 InnoDB 文件过程中,因为数据库处于全局只读状态,如果在业务的主库备份的话,要特别小心,非 InnoDB 表(主要是MyISAM)比较多的话整库只读时间就会比较长,这个影响一定要评估到。
- 当 innobackupex 拷贝完所有非 InnoDB 表文件后,通知 xtrabackup(通过删文件) ,同时自己进入等待(等待另一个文件被创建);
- xtrabackup 收到 innobackupex 备份完非 InnoDB 通知后,就停止 redo 拷贝线程,然后通知 innobackupexredo log 拷贝完成(通过创建文件);
- innobackupex 收到 redo 备份完成通知后,就开始解锁,执行 UNLOCK TABLES;
- 最后 innobackupex 和 xtrabackup 进程各自完成收尾工作,如资源的释放、写备份元数据信息等,innobackupex 等待 xtrabackup 子进程结束后退出。
附:备份过程
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona LLC and/or its affiliates 2009-2013. All Rights Reserved.
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
171115 15:29:57 innobackupex_56: Executing a version check against the server...
171115 15:29:57 innobackupex_56: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/home/mysql/mysql/etc/my.cnf;mysql_read_default_group=xtrabackup;mysql_socket=/home/mysql/mysql/tmp/mysql.sock' as 'root' (using password: YES).
171115 15:29:57 innobackupex_56: Connected to MySQL server
171115 15:29:57 innobackupex_56: Done.
171115 15:29:57 innobackupex_56: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/home/mysql/mysql/etc/my.cnf;mysql_read_default_group=xtrabackup;mysql_socket=/home/mysql/mysql/tmp/mysql.sock' as 'root' (using password: YES).
171115 15:29:57 innobackupex_56: Connected to MySQL server
171115 15:29:57 innobackupex_56: Starting the backup operation
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex_56
prints "completed OK!".
innobackupex_56: Using server version 5.6.23-baidu-trunk-2.2.2.1-log
innobackupex_56: Created backup directory /home/mysql/opbin/xtrabackup/2017-11-15_15-29-57
171115 15:29:57 innobackupex_56: Starting ibbackup with command: /home/mysql/opbin/xtrabackup/xtrabackup_56 --defaults-file="/home/mysql/mysql/etc/my.cnf" --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/home/mysql/opbin/xtrabackup/2017-11-15_15-29-57 --tmpdir=/home/mysql/mysql --extra-lsndir='/home/mysql/mysql'
innobackupex_56: Waiting for ibbackup (pid=29999) to suspend
innobackupex_56: Suspend file '/home/mysql/opbin/xtrabackup/2017-11-15_15-29-57/xtrabackup_suspended_2'
/home/mysql/opbin/xtrabackup/xtrabackup_56 version 2.1.7 for MySQL server 5.6.15 Linux (x86_64) (revision id: undefined)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /home/mysql/mysql/var
xtrabackup: using the following InnoDB configuration:
xtrabackup: innodb_data_home_dir = /home/mysql/mysql/var
xtrabackup: innodb_data_file_path = ibdata1:1G:autoextend
xtrabackup: innodb_log_group_home_dir = /home/mysql/mysql/var
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 1992294400
>> log scanned up to (20735405)
InnoDB: Allocated tablespace 16, old maximum was 0
[01] Copying /home/mysql/mysql/var/ibdata1 to /home/mysql/opbin/xtrabackup/2017-11-15_15-29-57/ibdata1
>> log scanned up to (20735405)
>> log scanned up to (20735405)
>> log scanned up to (20735405)
>> log scanned up to (20735405)
>> log scanned up to (20735405)
>> log scanned up to (20735405)
>> log scanned up to (20735405)
>> log scanned up to (20735405)
>> log scanned up to (20739120)
>> log scanned up to (20739120)
>> log scanned up to (20742705)
>> log scanned up to (20742705)
>> log scanned up to (20746290)
>> log scanned up to (20746290)
>> log scanned up to (20746290)
>> log scanned up to (20749875)
>> log scanned up to (20749875)
>> log scanned up to (20749875)
>> log scanned up to (20749875)
>> log scanned up to (20749875)
>> log scanned up to (20749875)
>> log scanned up to (20749875)
>> log scanned up to (20749875)
>> log scanned up to (20753460)
>> log scanned up to (20753460)
>> log scanned up to (20753460)
>> log scanned up to (20757778)
[01] ...done
[01] Copying ./percona/checksums.ibd to /home/mysql/opbin/xtrabackup/2017-11-15_15-29-57/percona/checksums.ibd
[01] ...done
[01] Copying ./mysql/innodb_table_stats.ibd to /home/mysql/opbin/xtrabackup/2017-11-15_15-29-57/mysql/innodb_table_stats.ibd
[01] ...done
[01] Copying ./mysql/innodb_index_stats.ibd to /home/mysql/opbin/xtrabackup/2017-11-15_15-29-57/mysql/innodb_index_stats.ibd
[01] ...done
[01] Copying ./mysql/slave_worker_info.ibd to /home/mysql/opbin/xtrabackup/2017-11-15_15-29-57/mysql/slave_worker_info.ibd
[01] ...done
[01] Copying ./mysql/slave_relay_log_info.ibd to /home/mysql/opbin/xtrabackup/2017-11-15_15-29-57/mysql/slave_relay_log_info.ibd
[01] ...done
[01] Copying ./mysql/slave_master_info.ibd to /home/mysql/opbin/xtrabackup/2017-11-15_15-29-57/mysql/slave_master_info.ibd
[01] ...done
>> log scanned up to (20757778)
xtrabackup: Creating suspend file '/home/mysql/opbin/xtrabackup/2017-11-15_15-29-57/xtrabackup_suspended_2' with pid '29999'
171115 15:30:26 innobackupex_56: Continuing after ibbackup has suspended
171115 15:30:26 innobackupex_56: Executing FLUSH TABLES...
171115 15:30:26 innobackupex_56: Executing FLUSH TABLES WITH READ LOCK...
171115 15:30:26 innobackupex_56: All tables locked and flushed to disk
171115 15:30:26 innobackupex_56: Starting to backup non-InnoDB tables and files
innobackupex_56: in subdirectories of '/home/mysql/mysql/var/'
innobackupex_56: Backing up files '/home/mysql/mysql/var//performance_schema/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (53 files)
innobackupex_56: Backing up file '/home/mysql/mysql/var//percona/db.opt'
>> log scanned up to (20762096)
innobackupex_56: Backing up file '/home/mysql/mysql/var//percona/checksums.frm'
innobackupex_56: Backing up file '/home/mysql/mysql/var//baidu_dba/db.opt'
innobackupex_56: Backing up file '/home/mysql/mysql/var//baidu_dba/heartbeat.frm'
innobackupex_56: Backing up file '/home/mysql/mysql/var//baidu_dba/heartbeat.MYI'
innobackupex_56: Backing up file '/home/mysql/mysql/var//baidu_dba/heartbeat.MYD'
innobackupex_56: Backing up file '/home/mysql/mysql/var//DB/db.opt'
innobackupex_56: Backing up file '/home/mysql/mysql/var//DB/t6.frm'
innobackupex_56: Backing up file '/home/mysql/mysql/var//DB/t4.frm'
innobackupex_56: Backing up file '/home/mysql/mysql/var//DB/t2.frm'
innobackupex_56: Backing up file '/home/mysql/mysql/var//DB/t7.frm'
innobackupex_56: Backing up file '/home/mysql/mysql/var//DB/t3.frm'
innobackupex_56: Backing up file '/home/mysql/mysql/var//DB/t1.frm'
innobackupex_56: Backing up file '/home/mysql/mysql/var//DB/t5.frm'
innobackupex_56: Backing up files '/home/mysql/mysql/var//mysql/*.{frm,isl,MYD,MYI,MAD,MAI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (74 files)
171115 15:30:26 innobackupex_56: Finished backing up non-InnoDB tables and files
171115 15:30:26 innobackupex_56: Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
171115 15:30:26 innobackupex_56: Waiting for log copying to finish
xtrabackup: The latest check point (for incremental): '20757778'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (20762096)
xtrabackup: Creating suspend file '/home/mysql/opbin/xtrabackup/2017-11-15_15-29-57/xtrabackup_log_copied' with pid '29999'
xtrabackup: Transaction log of lsn (20735405) to (20762096) was copied.
171115 15:30:27 innobackupex_56: All tables unlocked
innobackupex_56: Backup created in directory '/home/mysql/opbin/xtrabackup/2017-11-15_15-29-57'
innobackupex_56: MySQL binlog position: filename 'mysql-bin.000005', position 9359350
171115 15:30:27 innobackupex_56: Connection to database server closed
171115 15:30:27 innobackupex_56: completed OK!