4. XtraBackup 使用简介
包括:Linux、Debian、FreeBSD、Solaris、Windows 等。同时还提供源码,可
自行编译,因此实际可以支持更多平台。
3.2 XtraBackup 使用方法
XtraBackup 一般的用法为:
备份:xtrabackup [DEFAULTS OPTION] –backup
恢复:xtrabackup [DEFAULTS OPTION] –prepare] [OPTIONS]
上面提到的 DEFAULTS OPTION 选项,默认从以下顺序的配置文件中读取:
/etc/my.cnf
/opt/mysql-5.0.xx/etc/my.cnf
~/.my.cnf
只读取配置文件的“mysqld”和“xtrabackup”部分。
另外,下面的选项列表作为 XtraBackup 的第一参数:
(The following 4 options may be given as the first argument)
--print-defaults Print the program argument list and exit
--no-defaults Don't read default options from any options file
--defaults-file=# Only read default options from the given file #
--defaults-extra-file=# Read this file after the global files are read
--target-dir=name destination directory
--backup take backup to target-dir
5. XtraBackup 使用简介
--stats calc statistic of datadir (offline mysqld is recommended)
--prepare prepare a backup for starting mysql server on the backup.
--export create files to import to another database when prepare.
--print-param print parameter of mysqld needed for copyback.
--use-memory=# The value is used instead of buffer_pool_size
--suspend-at-end creates a file 'xtrabackup_suspended' and waits until the
user deletes that file at the end of '--backup'
--throttle=# limit count of IO operations (pairs of read&write) per
second to IOS values (for '--backup')
--log-stream outputs the contents of 'xtrabackup_logfile' to stdout
only until the file 'xtrabackup_suspended' deleted (for
'--backup').
--incremental-lsn=name
(for --backup): copy only .ibd pages newer than specified
LSN 'high:low'. ##ATTENTION##: checkpoint lsn must be
used. anyone can detect your mistake. be carefully!
--incremental-basedir=name
(for --backup): copy only .ibd pages newer than backup at
specified directory.
--incremental-dir=name
(for --prepare): apply .delta files and logfile in the
specified directory.
6. XtraBackup 使用简介
--tables=name filtering by regexp for table names.
--create-ib-logfile ** not work for now** creates ib_logfile* also after
'--prepare'. ### If you want create ib_logfile*, only
re-execute this command in same options. ###
-h, --datadir=name Path to the database root.
-t, --tmpdir=name Path for temporary files. Several paths may be specified,
separated by a colon (:), in this case they are used in a
round-robin fashion.
throttle–限制每秒的 IOS 数量,以避免瞬间对服务器性能产生较大影响。
不过,设置太小的话,可能会导致备份进度太慢(比如跟不上事务日志的更新速
度)。
target-dir–数据备份目标目录
Datadir 选项必须在命令行或 my.cnf 配置文件的[mysqld] 中体现
可以设置 my.cnf 文件中[xtrabackup]这个分区的全部选项(如果配置文件
中,[xtrabackup]放在[mysqld]后面,则这些选项会覆盖前面的值)。
3.3 XtraBackup 配置选项详解
详细的选项不再逐个解释,可自行查看。
Options for xtrabackup. The All options are read from [mysqld] and
[xtrabackup] section of my.cnf.
7. XtraBackup 使用简介
--datadir
[required]: This option is same for mysqld. And this shuld be same to
mysqld. So, you should set datadir at [mysqld] section of my.cnf .
--target-dir
[required]: This option specifies the target directory to put the backup files.
If not exist, ”–backup” option creates the directory.
attention: We must use fullpath expression.
--backup
stores the backup data files (*.ibd) and a backup log file (named
'xtrabackup_logfile') in the directory specified in target-dir
--prepare
prepares a backup for starting mysqld from the backup files stored
by ”–backup” option. It applies the log records in 'xtrabackup_logfile' to the data
files.
attention: In current version, you should re-execute ”–prepare”, if you want
ib_logfile* here. (This is restriction of the alpha version)
--print-param
This option is used by innobackup script. It generates target mysqld
8. XtraBackup 使用简介
information for “innobackup –copy-back” like this.
# This MySQL options file was generated by XtraBackup.
[mysqld]
datadir = /opt/mysql-5.0.67/data
innodb_data_home_dir = /opt/mysql-5.0.67/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/mysql-5.0.67/data
--defaults-file=#
This option is same to the other MySQL tools. It can specify the my.cnf
only read.
--defaults-extra-file=#
This option is also same to the other MySQL tools. It can specify the
my.cnf additionally read.
--use-memory=#
This option is for ”–prepare”. This is not same to the same named option of
ibbackup. It is used as innodb_buffer_pool_size of the InnoDB instance
of ”–prepare”. The default value is 100M bytes. But 1G or 2G bytes are
recommended if you can.
9. XtraBackup 使用简介
--export
This option is for ”–prepare”. It makes to output “clean” .ibd files and .exp
files for 'ALTER TABLE … IMPORT TABLESPACE' command
innodb_expand_import option enabled XtraDB. .exp file is generated at the
same place of the each .ibd file
--suspend-at-end
This option is for ”–backup”. creates a file 'xtrabackup_suspended' and
waits until the user deletes that file at the end. It is used in backup scripts for
synchronizing the end position of the backup transaction log file to the another
backup.
--log-stream
This option is for ”–backup”. outputs the contents of 'xtrabackup_logfile' to
stdout only, –suspend-at-end is added automatically. It may be useful when
you use your own backup tool. (innobackupex –stream mode also uses this
option.)
--incremental-lsn=LSN_HIGH:LSN_LOW
This option is for ”–backup”. Copy only .ibd pages newer than specified
LSN 'high:low'.
The checkpoint LSN must be used. (The checkpoint LSN of the previous
10. XtraBackup 使用简介
backup is printed out when ”–backup”, and stored at 'xtrabackup_checkpoints'
file)
--incremental-basedir=name
This option is for ”–backup”. Copy only .ibd pages newer than backup at
specified directory. ('xtrabackup_checkpoints' of the directory is read and the
LSN is used automatically.)
--incremental-dir=name
This option is for ”–prepare”. Apply the incremental backup files (*.delta &
xtrabackup_logfile) in the specified directory.
--tables=REGEXP
This option only backup the file-per-table datafiles whose table name
“db_name.table_name” is matching to the regular expression REGEXP.
--throttle=#
This option is for ”–backup”. limits count of IO operations (pairs of
read&write) per second to IOS values. (At ”–incremental” mode, it is based on
rather read IO)
11. XtraBackup 使用简介
--create-ib-logfile
This option is for ”–prepare”. no effect for now
attention: In current version, you should re-execute ”–prepare”, if you want
ib_logfile* here.
--tmpdir
It is read from my.cnf. But it is not used by xtrabackup for now.
--innodb_*
InnoDB options for the target mysqld. Ordinarily, they are read from my.cnf
and we don't care about their settings.
3.4 XtraBackup 实际案例
3.4.1 做一次数据全备
[@test20110427]# xtrabackup --target-dir=/path/20110427/ --backup --throttle=100
xtrabackup Ver 1.5 Rev undefined for 5.1.53 unknown-linux-gnu (x86_64)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /home/mysql
xtrabackup: Target instance is assumed as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:1G:autoextend
12. XtraBackup 使用简介
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 268435456
xtrabackup: use O_DIRECT
110427 11:43:04 InnoDB: Warning: allocated tablespace 27, old maximum was 9
>> log scanned up to (13670891)
[01] Copying ./ibdata1
to /home/databak/20110427//ibdata1
>> log scanned up to (13670891)
>> log scanned up to (13670891)
>> log scanned up to (13670891)
>> log scanned up to (13670891)
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_money_etc.ibd
to /home/databak/20110427//cyou_monitor_ldj/tb_money_etc.ibd
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_service_metric.ibd
to /home/databak/20110427//cyou_monitor_ldj/tb_service_metric.ibd
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_host_status.ibd
to /home/databak/20110427//cyou_monitor_ldj/tb_host_status.ibd
[01] ...done
13. XtraBackup 使用简介
[01] Copying ./cyou_monitor_ldj/tb_money_work.ibd
to /home/databak/20110427//cyou_monitor_ldj/tb_money_work.ibd
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_exp_profession.ibd
to /home/databak/20110427//cyou_monitor_ldj/tb_exp_profession.ibd
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_money_life.ibd
to /home/databak/20110427//cyou_monitor_ldj/tb_money_life.ibd
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_service_status.ibd
to /home/databak/20110427//cyou_monitor_ldj/tb_service_status.ibd
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_service_metric_data.ibd
to /home/databak/20110427//cyou_monitor_ldj/tb_service_metric_data.ibd
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_host.ibd
to /home/databak/20110427//cyou_monitor_ldj/tb_host.ibd
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_exp_pet.ibd
to /home/databak/20110427//cyou_monitor_ldj/tb_exp_pet.ibd
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_service.ibd
14. XtraBackup 使用简介
to /home/databak/20110427//cyou_monitor_ldj/tb_service.ibd
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_exp_player.ibd
to /home/databak/20110427//cyou_monitor_ldj/tb_exp_player.ibd
[01] ...done
xtrabackup: The latest check point (for incremental): '6742998'
>> log scanned up to (13670891)
xtrabackup: Stopping log copying thread.
xtrabackup: Transaction log of lsn (13670891) to (13670891) was copied.
可以看到,默认地,把所有的 InnoDB 引擎表备份到指定目录下,同时记录
了最后的事务编号,当前是:13670891。便于下一次做增备,以及后续的数据
恢复。
3.4.2 做一次数据增备
[@test 20110427]# xtrabackup --backup --throttle=100
--target-dir=/home/databak/20110427/2011042712/
--incremental-basedir=/home/databak/20110427
xtrabackup Ver 1.5 Rev undefined for 5.1.53 unknown-linux-gnu (x86_64)
incremental backup from 13670891is enabled.
xtrabackup: uses posix_fadvise().
15. XtraBackup 使用简介
xtrabackup: cd to /home/mysql
xtrabackup: Target instance is assumed as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:1G:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 268435456
xtrabackup: use O_DIRECT
110427 11:52:13 InnoDB: Warning: allocated tablespace 27, old maximum was 9
>> log scanned up to (13670891)
[01] Copying ./ibdata1
to /home/databak/20110427/2011042712//ibdata1.delta
>> log scanned up to (13670891)
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_money_etc.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_money_etc.ibd.delta
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_service_metric.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_service_metric.ibd.delta
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_host_status.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_host_status.ibd.delta
16. XtraBackup 使用简介
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_money_work.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_money_work.ibd.delta
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_exp_profession.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_exp_profession.ibd.delta
>> log scanned up to (13719595)
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_money_life.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_money_life.ibd.delta
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_service_status.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_service_status.ibd.delta
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_service_metric_data.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_service_metric_data.ibd.delta
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_host.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_host.ibd.delta
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_exp_pet.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_exp_pet.ibd.delta
17. XtraBackup 使用简介
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_service.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_service.ibd.delta
[01] ...done
[01] Copying ./cyou_monitor_ldj/tb_exp_player.ibd
to /home/databak/20110427/2011042712//cyou_monitor_ldj/tb_exp_player.ibd.delta
[01] ...done
xtrabackup: The latest check point (for incremental): '13724040'
>> log scanned up to (13724040)
xtrabackup: Stopping log copying thread..
xtrabackup: Transaction log of lsn (13670891) to (13724040) was copied.
可以看到,增备数据的事务编号更新到了:13724040。
3.4.3 做一次数据恢复
3.4.3.1 只有一次全备
[@test 20110427]# xtrabackup --prepare --target-dir=/home/databak/20110427
xtrabackup Ver 1.5 Rev undefined for 5.1.53 unknown-linux-gnu (x86_64)
xtrabackup: cd to /home/databak/20110427
xtrabackup: This target seems to be already prepared.
xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.
18. XtraBackup 使用简介
xtrabackup: Temporary instance for recovery is set as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:1G:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 268435456
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Warning: innodb_file_io_threads is deprecated. Please use innodb_read_io_threads and
innodb_write_io_threads instead
mysqladmin pr110428 15:45:26 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 256 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100 200
110428 15:45:28 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 256 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100 200
19. XtraBackup 使用简介
110428 15:45:29 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
110428 15:45:29 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Last MySQL binlog file position 0 6639763, file name /home/binlog/binlog.000009
110428 15:45:30 Percona XtraDB (http://www.percona.com) 1.0.13-12.4 started; log sequence
number 13670891
[notice (again)]
If you use binary log and don't use any hack of group commit,
the binary log position seems to be:
InnoDB: Last MySQL binlog file position 0 6639763, file name /home/binlog/binlog.000009
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
110428 15:45:30 InnoDB: Starting shutdown...
110428 15:45:31 InnoDB: Shutdown completed; log sequence number 13670891
可以看到,如果只应用全备数据的话,那么事务序号只恢复到了:13670891,
而不是最新的:13724040。
20. XtraBackup 使用简介
3.4.3.2 同时应用增备
恢复增备数据时,要先对全备数据做一次应用,再做一次增备数据应用。
#先应用全备数据
[@test 20110427]# cd /home/databak/20110427
[@test 20110427]# xtrabackup --prepare --target-dir=./
xtrabackup Ver 1.5 Rev undefined for 5.1.53 unknown-linux-gnu (x86_64)
xtrabackup: cd to ./
xtrabackup: This target seems to be not prepared yet.
xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(6742998)
xtrabackup: Temporary instance for recovery is set as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:1G:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 2097152
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Warning: innodb_file_io_threads is deprecated. Please use innodb_read_io_threads and
21. XtraBackup 使用简介
innodb_write_io_threads instead
110427 13:50:05 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
110427 13:50:05 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Last MySQL binlog file position 0 6591484, file name /home/binlog/binlog.000009
110427 13:50:05 Percona XtraDB (http://www.percona.com) 1.0.13-12.4 started; log sequence
number 13670891
[notice (again)]
If you use binary log and don't use any hack of group commit,
the binary log position seems to be:
InnoDB: Last MySQL binlog file position 0 6591484, file name /home/binlog/binlog.000009
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
110427 13:50:05 InnoDB: Starting shutdown...
110427 13:50:06 InnoDB: Shutdown completed; log sequence number 13670891
#再次应用增备数据
[@test 20110427]# xtrabackup --prepare --target-dir=./ --incremental-dir=./2011042712/
22. XtraBackup 使用简介
xtrabackup Ver 1.5 Rev undefined for 5.1.53 unknown-linux-gnu (x86_64)
incremental backup from 13670891is enabled. #增备开始恢复的点
xtrabackup: cd to ./
xtrabackup: This target seems to be already prepared.
xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(13670891)
#应用增备数据
Applying ./2011042712//ibdata1.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_exp_pet.ibd.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_exp_player.ibd.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_exp_profession.ibd.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_host.ibd.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_money_work.ibd.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_service_metric.ibd.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_money_life.ibd.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_money_etc.ibd.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_service.ibd.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_service_metric_data.ibd.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_host_status.ibd.delta ...
Applying ./2011042712//cyou_monitor_ldj/tb_service_status.ibd.delta ...
xtrabackup: Temporary instance for recovery is set as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:1G:autoextend
23. XtraBackup 使用简介
xtrabackup: innodb_log_group_home_dir = ./2011042712/
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 2097152
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Warning: innodb_file_io_threads is deprecated. Please use innodb_read_io_threads and
innodb_write_io_threads instead
110427 13:50:12 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
110427 13:50:12 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Last MySQL binlog file position 0 6639763, file name /home/binlog/binlog.000009
110427 13:50:12 Percona XtraDB (http://www.percona.com) 1.0.13-12.4 started; log sequence
number 13724040 #应用到最新的日志点
[notice (again)]
If you use binary log and don't use any hack of group commit,
24. XtraBackup 使用简介
the binary log position seems to be:
InnoDB: Last MySQL binlog file position 0 6639763, file name /home/binlog/binlog.000009
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
110427 13:50:12 InnoDB: Starting shutdown...
110427 13:50:13 InnoDB: Shutdown completed; log sequence number 13724040
可以看到,这时候事务日志点更新到了:13724040,已经是最新的了。
3.5 innobackup 实际案例
3.5.1 准备配置文件
Xtrabackup 可以预先读取配置文件,根据配置文件定义的规则执行备份,下
面是一个配置文件的案例:
#
#xtrabackup / innobackupex
#
[client]
socket = /home/mysql_DBPORT/mysql.sock
[xtrabackup]
#设定数据源
datadir = /home/mysql_DBPORT
26. XtraBackup 使用简介
--safe-slave-backup
#不锁表,针对 myisam 表引擎
--no-lock
#指定备份文件存储目标路径
/home/databak/3001/20110715
#开始发起备份
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona Inc 2009-2011. All Rights Reserved.
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
#开始准备,连接到 mysql 中,查看 binlog,slave 等信息
110715 19:34:10 innobackupex: Starting mysql with options:
--defaults-file='/home/databak/bm_3307/xtrabackup.cnf' --unbuffered --
110715 19:34:10 innobackupex: Connected to database with mysql child process (pid=27240)
110715 19:34:16 innobackupex: Connection to database server closed
IMPORTANT: Please check that the backup run completes successfully.
At the end of a successful backup run innobackupex
prints "completed OK!".
innobackupex: Using Logging to file '/home/mysql/query.log'
27. XtraBackup 使用简介
innobackupex: Using mysql server version Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems,
Inc.
#确定要备份的数据表清单
xtrabackup: tables regcomp(ip_blacklist|ip_limitdef|ip_whitelist|ip_logs|ip_entity_task|ip_entity_login_7):
Success
innobackupex: Created backup directory /home/databak/test/20110715
110715 19:34:16 innobackupex: Starting mysql with options:
--defaults-file='/home/databak/bm_3307/xtrabackup.cnf' --unbuffered --
110715 19:34:16 innobackupex: Connected to database with mysql child process (pid=27263)
110715 19:34:20 innobackupex: Connection to database server closed
110715 19:34:20 innobackupex: Starting ibbackup with command: xtrabackup
--defaults-file="/home/databak/bm_3307/xtrabackup.cnf" --backup --suspend-at-end
--target-dir=/home/databak/test/20110715 --throttle=100
innobackupex: Waiting for ibbackup (pid=27279) to suspend
innobackupex: Suspend file '/home/databak/test/20110715/xtrabackup_suspended'
#开始备份共享表空间,备份各 InnoDB 表,第一次记录 redo log 信息
xtrabackup: tables regcomp(ip_blacklist|ip_limitdef|ip_whitelist|ip_logs|ip_entity_task|ip_entity_login_7):
Success
xtrabackup Ver 1.6 Rev 245 for 5.1.55 unknown-linux-gnu (x86_64)
28. XtraBackup 使用简介
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /home/mysql_3307
xtrabackup: Target instance is assumed as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:1G:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 268435456
110715 19:34:20 InnoDB: Warning: allocated tablespace 10, old maximum was 9
>> log scanned up to (13919335100)
[01] Copying ./ibdata1
to /home/databak/test/20110715/ibdata1
>> log scanned up to (13919335366)
>> log scanned up to (13919335366)
[01] ...done
[01] Copying ./billing_mother/ip_blacklist.ibd
to /home/databak/test/20110715/billing_mother/ip_blacklist.ibd
[01] ...done
[01] ...done
[01] Copying ./bm_tlbb/ip_whitelist.ibd
to /home/databak/test/20110715/bm_tlbb/ip_whitelist.ibd
[01] ...done
29. XtraBackup 使用简介
#开始备份其他非 InnoDB 表
110715 19:34:58 innobackupex: Continuing after ibbackup has suspended
110715 19:34:58 innobackupex: Starting mysql with options:
--defaults-file='/home/databak/bm_3307/xtrabackup.cnf' --unbuffered --
110715 19:34:58 innobackupex: Connected to database with mysql child process (pid=27303)
>> log scanned up to (13919335641)
>> log scanned up to (13919335641)
innobackupex:: Slave open temp tables: 0
110715 19:35:08 innobackupex: Starting to backup .frm, .MRG, .MYD, .MYI,
innobackupex: .TRG, .TRN, .ARM, .ARZ, .CSM, .CSV and .opt files in
innobackupex: subdirectories of '/home/mysql_3307'
innobackupex: Backing up files
'/home/mysql_3307/mysql/*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (69 files)
innobackupex: Backing up files
'/home/mysql_3307/billing_mother/*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (18
files)
innobackupex: Backing up files
'/home/mysql_3307/bm_dj/*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (18 files)
innobackupex: Backing up files
'/home/mysql_3307/bm_dj1_xyj/*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (18 files)
30. XtraBackup 使用简介
innobackupex: Backing up files
'/home/mysql_3307/bm_dj1_zwj/*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (18
files)
innobackupex: Backing up files
'/home/mysql_3307/bm_tlbb/*.{frm,MYD,MYI,MRG,TRG,TRN,ARM,ARZ,CSM,CSV,opt,par}' (18 files)
110715 19:35:09 innobackupex: Finished backing
up .frm, .MRG, .MYD, .MYI, .TRG, .TRN, .ARM, .ARZ, .CSV, .CSM and .opt files
innobackupex: Resuming ibbackup
#第二次记录 redo log 信息,记录 binlog 信息
xtrabackup: The latest check point (for incremental): '13919335641'
>> log scanned up to (13919335641)
xtrabackup: Stopping log copying thread.
xtrabackup: Transaction log of lsn (13919335100) to (13919335641) was copied.
innobackupex:: Starting slave SQL thread
110715 19:35:11 innobackupex: Connection to database server closed
innobackupex: Backup created in directory '/home/databak/test/20110715'
110715 19:35:11 innobackupex: completed OK!
至此,innobackupex 做数据库全备完毕。
32. XtraBackup 使用简介
3.5.4 做一次数据恢复
3.5.4.1 只有一次全备
做数据恢复时,和用 xtrabackup 备份的文件恢复相似,还更简单。
#1. 恢复全备
#直接进入备份文件所在目录,执行 –apply-log 操作即可
[@tc_19_66 20110714]# cd /home/databak/20110714
[@tc_19_66 20110714]# innobackupex --apply-log .
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona Inc 2009-2011. All Rights Reserved.
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
IMPORTANT: Please check that the apply-log run completes successfully.
At the end of a successful apply-log run innobackupex
prints "completed OK!".
110714 17:46:48 innobackupex: Starting ibbackup with command: xtrabackup --prepare
33. XtraBackup 使用简介
--target-dir=/opt/home/databak/20110714
xtrabackup Ver 1.6 Rev undefined for 5.1.55 unknown-linux-gnu (x86_64)
xtrabackup: cd to /opt/home/databak/20110714
xtrabackup: This target seems to be not prepared yet.
xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(13916925521)
xtrabackup: Temporary instance for recovery is set as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:1G:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 2097152
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Warning: innodb_file_io_threads is deprecated. Please use innodb_read_io_threads and
innodb_write_io_threads instead
110714 17:46:49 InnoDB: Initializing buffer pool, size = 100.0M
110714 17:46:49 InnoDB: Completed initialization of buffer pool
110714 17:46:49 InnoDB: highest supported file format is Barracuda.
34. XtraBackup 使用简介
InnoDB: Log scan progressed past the checkpoint lsn 13916925521
110714 17:46:49 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Doing recovery: scanned up to log sequence number 13916926358 (0 %)
110714 17:46:49 InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
95 96 97 98 99
InnoDB: Apply batch completed
InnoDB: In a MySQL replication slave the last master binlog file
InnoDB: position 0 480763006, file name bm153_binlog.000032
InnoDB: and relay log file
InnoDB: position 0 480763154, file name /home/binlog/bm_relay_3307.000046
InnoDB: Last MySQL binlog file position 0 279128696, file name /home/binlog/bm_binlog_3307.000015
[notice (again)]
If you use binary log and don't use any hack of group commit,
the binary log position seems to be:
InnoDB: Last MySQL binlog file position 0 279128696, file name /home/binlog/bm_binlog_3307.000015
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
110714 17:46:50 InnoDB: Starting shutdown...
35. XtraBackup 使用简介
110714 17:46:50 InnoDB: Shutdown completed; log sequence number 13917110931
110714 17:46:50 innobackupex: Restarting xtrabackup with command: xtrabackup --prepare
--target-dir=/opt/home/databak/20110714
for creating ib_logfile*
xtrabackup Ver 1.6 Rev undefined for 5.1.55 unknown-linux-gnu (x86_64)
xtrabackup: cd to /opt/home/databak/20110714
xtrabackup: This target seems to be already prepared.
xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.
xtrabackup: Temporary instance for recovery is set as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:1G:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 268435456
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Warning: innodb_file_io_threads is deprecated. Please use innodb_read_io_threads and
36. XtraBackup 使用简介
innodb_write_io_threads instead
110714 17:46:50 InnoDB: Initializing buffer pool, size = 100.0M
110714 17:46:50 InnoDB: Completed initialization of buffer pool
110714 17:46:50 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 256 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100 200
110714 17:46:52 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 256 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Progress in MB: 100 200
110714 17:46:54 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
110714 17:46:54 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: In a MySQL replication slave the last master binlog file
InnoDB: position 0 480763006, file name bm153_binlog.000032
InnoDB: and relay log file
InnoDB: position 0 480763154, file name /home/binlog/bm_relay_3307.000046
InnoDB: Last MySQL binlog file position 0 279128696, file name /home/binlog/bm_binlog_3307.000015
37. XtraBackup 使用简介
110714 17:46:55 Percona XtraDB (http://www.percona.com) 1.0.15-12.5 started; log sequence number
13917111308
[notice (again)]
If you use binary log and don't use any hack of group commit,
the binary log position seems to be:
InnoDB: Last MySQL binlog file position 0 279128696, file name /home/binlog/bm_binlog_3307.000015
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
110714 17:46:55 InnoDB: Starting shutdown...
110714 17:46:55 InnoDB: Shutdown completed; log sequence number 13917111308
110714 17:46:55 innobackupex: completed OK!
3.5.4.2 同时应用增备
#2. 恢复增备
#进入全备文件所在目录,也是执行—apply-log,同时指定增备文件对应的路径即可
[@tc_19_66 20110714]# cd /home/databak/20110714
[@tc_19_66 20110714]# innobackupex --apply-log /home/databak/20110714
--incremental-dir=/home/databak/20110714/2011071415/
InnoDB Backup Utility v1.5.1-xtrabackup; Copyright 2003, 2009 Innobase Oy
and Percona Inc 2009-2011. All Rights Reserved.
38. XtraBackup 使用简介
This software is published under
the GNU GENERAL PUBLIC LICENSE Version 2, June 1991.
IMPORTANT: Please check that the apply-log run completes successfully.
At the end of a successful apply-log run innobackupex
prints "completed OK!".
110714 19:50:30 innobackupex: Starting ibbackup with command: xtrabackup --prepare
--target-dir=/home/databak/20110714 --incremental-dir=/home/databak/20110714/2011071415/
xtrabackup Ver 1.6 Rev undefined for 5.1.55 unknown-linux-gnu (x86_64)
incremental backup from 13916926358 is enabled.
xtrabackup: cd to /home/databak/20110714
xtrabackup: This target seems to be already prepared.
xtrabackup: xtrabackup_logfile detected: size=2359296, start_lsn=(13917151324)
xtrabackup: page size for /home/databak/20110714/2011071415//ibdata1.delta is 16384 bytes
Applying /home/databak/20110714/2011071415//ibdata1.delta ...
...
xtrabackup: page size for /home/databak/20110714/2011071415//billing_mother/ip_entity_task.ibd.delta
39. XtraBackup 使用简介
is 16384 bytes
Applying /home/databak/20110714/2011071415//billing_mother/ip_entity_task.ibd.delta ...
xtrabackup: Temporary instance for recovery is set as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:1G:autoextend
xtrabackup: innodb_log_group_home_dir = /home/databak/20110714/2011071415/
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 2359296
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Warning: innodb_file_io_threads is deprecated. Please use innodb_read_io_threads and
innodb_write_io_threads instead
110714 19:50:31 InnoDB: Initializing buffer pool, size = 100.0M
110714 19:50:31 InnoDB: Completed initialization of buffer pool
110714 19:50:31 InnoDB: highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 13917151324
110714 19:50:31 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
40. XtraBackup 使用简介
InnoDB: Doing recovery: scanned up to log sequence number 13917151604 (0 %)
110714 19:50:31 InnoDB: Starting an apply batch of log records to the database...
InnoDB: Progress in percents: 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
88 89 90 91 92 93 94 95 96 97 98 99
InnoDB: Apply batch completed
InnoDB: In a MySQL replication slave the last master binlog file
InnoDB: position 0 481059264, file name bm153_binlog.000032
InnoDB: and relay log file
InnoDB: position 0 481059412, file name /home/binlog/bm_relay_3307.000046
InnoDB: Last MySQL binlog file position 0 279409214, file name /home/binlog/bm_binlog_3307.000015
110714 19:50:31 Percona XtraDB (http://www.percona.com) 1.0.15-12.5 started; log sequence number
13917151604
[notice (again)]
If you use binary log and don't use any hack of group commit,
the binary log position seems to be:
InnoDB: Last MySQL binlog file position 0 279409214, file name /home/binlog/bm_binlog_3307.000015
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
110714 19:50:31 InnoDB: Starting shutdown...
110714 19:50:32 InnoDB: Shutdown completed; log sequence number 13917151604
110714 19:50:32 innobackupex: completed OK!