Xtrabackup 安装使用
一 简介:
Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品。它能对InnoDB和XtraDB存储引擎的数据库非阻塞地备份(对于MyISAM的备份同样需要加表锁)。XtraBackup支持所有的Percona Server、MySQL、MariaDB和Drizzle。几年前使用过,但现在忘记的差不多了,所以就重新拾起看看。
xtrabackup有两个主要的工具:xtrabackup、innobackupex
().xtrabackup只能备份InnoDB和XtraDB 两种数据表 ().innobackupex则封装了xtrabackup,同时可以备份MyISAM数据表
xtrabackup_binlog_info:记录当前最新的LOG Position xtrabackup_binlog_pos_innodb:innodb log postion xtrabackup_checkpoints: 存放备份的起始位置beginlsn和结束位置endlsn,增量备份需要这个lsn[增量备份可以在这里面看from和to两个值的变化]
()备份过程快速、可靠 ()备份过程不会打断正在执行的事务 ()能够基于压缩等功能节约磁盘空间和流量 ()自动实现备份检验 ()还原速度快
二 安装: http://www.percona.com/downloads/
下载安装:
1)直接下载二进制包,不编译,编译需要和MySQL源码包配合。
wget http://www.percona.com/downloads/XtraBackup/XtraBackup-2.1.9/binary/Linux/x86_64/percona-xtrabackup-2.1.9-744-Linux-x86_64.tar.gz
)tar zxvf percona-xtrabackup-2.1.--Linux-x86_64.tar.gz )ls -lh
drwxr-xr-x root root .0K 5月 bin
drwxr-xr-x root root .0K 5月 share )
ls -lh bin/
-rwxr-xr-x root root 165K 5月 innobackupex
lrwxrwxrwx root root 5月 innobackupex-1.5. -> innobackupex
-rwxr-xr-x root root 2.2M 5月 xbcrypt
-rwxr-xr-x root root 2.2M 5月 xbstream
-rwxr-xr-x root root 13M 5月 xtrabackup
-rwxr-xr-x root root 16M 5月 xtrabackup_55
-rwxr-xr-x root root 79M 5月 xtrabackup_56 )
cp innobackupex-1.5. /usr/bin/innobackupex
cp xtrabackup_55 /usr/bin/xtrabackup
#cp xtrabackup /usr/bin
2)Ubuntu 下的安装:http://www.percona.com/doc/percona-xtrabackup/2.1/installation/apt_repo.html
:执行
apt-key adv --keyserver keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A :在 vi /etc/apt/sources.list 添加
deb http://repo.percona.com/apt VERSION main
deb-src http://repo.percona.com/apt VERSION main :安装
$ apt-get update
$ apt-get install percona-xtrabackup
支持的版本有:
Debian
6.0 (squeeze)
7.0 (wheezy)
Ubuntu
10.04LTS (lucid)
12.04LTS (precise)
12.10 (quantal)
13.04 (raring)
13.10 (saucy)
把2中的 VERSION 按照自己的系统把上面的代入。
deb http://repo.percona.com/apt precise main
deb-src http://repo.percona.com/apt precise main
# precise是Ubuntu-12.04的版本代号,如果是其它系统版本,需要更换。
三 使用说明:
安装完之后会生成几个工具:http://www.percona.com/doc/percona-xtrabackup/2.1/manual.html
innobackupex:这个是其实是下面三个工具的一个perl脚本封装,可以备份MyISAM, InnoDB, XtraDB表。但在处理Myisam时需要加一个读锁。 xtrabackup:一个由C编译而来的二进制文件,只能备份InnoDB和XtraDB数据。 xbcrypt:用来加密或解密备份的数据。 xbstream:用来解压或压缩xbstream格式的压缩文件。
innobackupex :
xtrabackup命令只备份数据文件,并不备份数据表结构(.frm),所以使用xtrabackup恢复的时候必须有对应表结构文件(.frm)。用innobackupex命令,此命令相当于冷备份,复制数据目录的索引,数据,结构文件,但会有短暂的锁表(时间依赖于MyISAM大小)。
参数:
--defaults-file:指定my.cnf参数文件的位置[此配置文件里必须指定datadir]
--apply-log:同xtrabackup的--prepare参数,一般情况下,在备份完成后,数据尚且不能用于恢复操作,因为备份的数据中可能会包含尚未提交的事务或已经提交但尚未同步至数据文件中的事务。因此,此时数据 文件仍处理不一致状态。--apply-log的作用是通过回滚未提交的事务及同步已经提交的事务至数据文件使数据文件处于一致性状态。
--copy-back:做数据恢复时将备份数据文件拷贝到MySQL服务器的datadir
--remote-host=HOSTNAME: 通过ssh将备份数据存储到进程服务器上
--stream=[tar]:备份文件输出格式, 该文件可在XtarBackup binary文件中获得. 在使用参数stream=tar备份的时候,你的xtrabackup_logfile可能会临时放在/tmp目录下,如果你备份的时候并发写入较大的话,xtrabackup_logfile可能会很大(5G+),很可能会撑满你的/tmp目录,可以通过参数--tmpdir指定目录来解决这个问题.
--tmpdir=DIRECTORY:当有指定--remote-host or --stream时, 事务日志临时存储的目录, 默认采用MySQL配置文件中所指定的临时目录tmpdir
--redo-only --apply-log:强制备份日志时只redo,跳过rollback,这在做增量备份时非常必要
--use-memory=*:该参数在prepare的时候使用,控制prepare时innodb实例使用的内存
--databases=LIST:列出需要备份的databases,如果没有指定该参数,所有包含MyISAM和InnoDB表的database都会被备份
--slave-info:备份从库, 加上--slave-info备份目录下会多生成一个xtrabackup_slave_info 文件, 这里会保存主日志文件以及偏移, 文件内容类似于:CHANGE MASTER TO MASTER_LOG_FILE='', MASTER_LOG_POS=
--socket=SOCKET:指定mysql.sock所在位置,以便备份进程登录mysql.
更多参数见:http://www.percona.com/doc/percona-xtrabackup/2.1/innobackupex/innobackupex_option_reference.html
四 测试:
1)全量备份&还原
#初始化
mysql> create database xtra_test default charset utf8;
Query OK, 1 row affected (0.00 sec) mysql> use xtra_test
Database changed
mysql> create table M(id int,name varchar(10))engine=myisam;
Query OK, 0 rows affected (0.00 sec) mysql> create table I(id int,name varchar(10))engine=innodb;
Query OK, 0 rows affected (0.00 sec) mysql> insert into M values(1,'a'),(2,'b'),(3,'c'),(4,'d'),(5,'e');
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0 mysql> insert into I values(11,'A'),(22,'B'),(33,'C'),(44,'D'),(55,'E');
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0 mysql> select * from M;
+------+------+
| id | name |
+------+------+
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
| 5 | e |
+------+------+
5 rows in set (0.00 sec) mysql> select * from I;
+------+------+
| id | name |
+------+------+
| 11 | A |
| 22 | B |
| 33 | C |
| 44 | D |
| 55 | E |
+------+------+
5 rows in set (0.00 sec)
#备份
root@ha1:~# innobackupex --user=zjy --password=123456# --host=192.168.200.51 --defaults-file=/etc/mysql/my.cnf --databases=xtra_test /home/zhoujy/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. Get the latest version of Percona XtraBackup, documentation, and help resources:
http://www.percona.com/xb/p 141111 11:56:58 innobackupex: Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_file=/etc/mysql/my.cnf;mysql_read_default_group=xtrabackup;host=192.168.200.51' as 'zjy' (using password: YES).
141111 11:56:58 innobackupex: Connected to MySQL server
141111 11:56:58 innobackupex: Executing a version check against the server...
141111 11:56:58 innobackupex: Done.
141111 11:56:58 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!". innobackupex: Using server version 5.5.38-0ubuntu0.12.04.1-log innobackupex: Created backup directory /home/zhoujy/xtrabackup/2014-11-11_11-56-58 141111 11:56:58 innobackupex: Starting ibbackup with command: xtrabackup --defaults-file="/etc/mysql/my.cnf" --defaults-group="mysqld" --backup --suspend-at-end --target-dir=/home/zhoujy/xtrabackup/2014-11-11_11-56-58 --innodb_log_file_size="5242880" --innodb_data_file_path="ibdata1:10M:autoextend" --tmpdir=/tmp --extra-lsndir='/tmp' --databases='xtra_test'
innobackupex: Waiting for ibbackup (pid=10539) to suspend
innobackupex: Suspend file '/home/zhoujy/xtrabackup/2014-11-11_11-56-58/xtrabackup_suspended_2' xtrabackup version 2.2.6 based on MySQL server 5.6.21 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
>> log scanned up to (7363097930)
xtrabackup: Generating a list of tablespaces
[] Copying ./ibdata1 to /home/zhoujy/xtrabackup/2014-11-11_11-56-58/ibdata1
>> log scanned up to (7363097930)
>> log scanned up to (7363097930)
>> log scanned up to (7363097930)
>> log scanned up to (7363097930)
>> log scanned up to (7363097930)
>> log scanned up to (7363097930)
>> log scanned up to (7363097930)
>> log scanned up to (7363097930)
>> log scanned up to (7363097930)
>> log scanned up to (7363097930)
>> log scanned up to (7363097930)
[] ...done
>> log scanned up to (7363097930)
xtrabackup: Creating suspend file '/home/zhoujy/xtrabackup/2014-11-11_11-56-58/xtrabackup_suspended_2' with pid '' 141111 11:57:11 innobackupex: Continuing after ibbackup has suspended
141111 11:57:11 innobackupex: Executing FLUSH TABLES WITH READ LOCK...
141111 11:57:11 innobackupex: All tables locked and flushed to disk 141111 11:57:11 innobackupex: Starting to backup non-InnoDB tables and files
innobackupex: in subdirectories of '/var/lib/mysql/'
innobackupex: Backing up file '/var/lib/mysql//xtra_test/db.opt'
innobackupex: Backing up file '/var/lib/mysql//xtra_test/M.MYI'
>> log scanned up to (7363097930)
innobackupex: Backing up file '/var/lib/mysql//xtra_test/M.frm'
innobackupex: Backing up file '/var/lib/mysql//xtra_test/I.frm'
innobackupex: Backing up file '/var/lib/mysql//xtra_test/M.MYD'
141111 11:57:11 innobackupex: Finished backing up non-InnoDB tables and files 141111 11:57:11 innobackupex: Executing FLUSH ENGINE LOGS...
141111 11:57:11 innobackupex: Waiting for log copying to finish xtrabackup: The latest check point (for incremental): ''
xtrabackup: Stopping log copying thread.
.>> log scanned up to (7363097930) xtrabackup: Creating suspend file '/home/zhoujy/xtrabackup/2014-11-11_11-56-58/xtrabackup_log_copied' with pid ''
xtrabackup: Transaction log of lsn (7363097930) to (7363097930) was copied.
141111 11:57:12 innobackupex: All tables unlocked innobackupex: Backup created in directory '/home/zhoujy/xtrabackup/2014-11-11_11-56-58'
innobackupex: MySQL binlog position: filename 'mysql-bin51.000001', position 967
141111 11:57:12 innobackupex: Connection to database server closed
141111 11:57:12 innobackupex: completed OK!
查看备份出来的文件:
ls -lh 2014-11-11_11-56-58/
total 1.2G
-rw-r--r-- 1 root root 188 11月 11 11:56 backup-my.cnf
-rw-r----- 1 root root 1.2G 11月 11 11:57 ibdata1
-rw-r--r-- 1 root root 25 11月 11 11:57 xtrabackup_binlog_info
-rw-r----- 1 root root 95 11月 11 11:57 xtrabackup_checkpoints
-rw-r--r-- 1 root root 666 11月 11 11:57 xtrabackup_info
-rw-r----- 1 root root 2.5K 11月 11 11:57 xtrabackup_logfile
drwxr-xr-x 2 root root 4.0K 11月 11 11:57 xtra_test
/home/zhoujy/xtrabackup/ 备份存放的位置,备份会在该目录下生成一个按照时间命名的文件夹。用--no-timestamp参数可以指定到自己想要的备份文件夹,不受时间命名的文件夹限制。
利用 --apply-log的作用是通过回滚未提交的事务及同步已经提交的事务至数据文件使数据文件处于一致性状态。
root@ha1:/home/zhoujy/xtrabackup# innobackupex --apply-log /home/zhoujy/xtrabackup/2014-11-11_11-56-58/ InnoDB Backup Utility v1.5.1-xtrabackup; Copyright , Innobase Oy
and Percona LLC and/or its affiliates -. All Rights Reserved. This software is published under
the GNU GENERAL PUBLIC LICENSE Version , June . Get the latest version of Percona XtraBackup, documentation, and help resources:
http://www.percona.com/xb/p :: 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: Starting ibbackup with command: xtrabackup --defaults-file="/home/zhoujy/xtrabackup/2014-11-11_11-56-58/backup-my.cnf" --defaults-group="mysqld" --prepare --target-dir=/home/zhoujy/xtrabackup/--11_11-- xtrabackup version 2.2. based on MySQL server 5.6. Linux (x86_64) (revision id: )
xtrabackup: cd to /home/zhoujy/xtrabackup/--11_11--
xtrabackup: This target seems to be not prepared yet.
xtrabackup: xtrabackup_logfile detected: size=, start_lsn=()
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group =
xtrabackup: innodb_log_file_size =
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group =
xtrabackup: innodb_log_file_size =
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using bytes for buffer pool (set by --use-memory parameter)
InnoDB: Using atomics to ref count buffer pool pages
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Memory barrier is not used
InnoDB: Compressed tables use zlib 1.2.3.4
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, size = 100.0M
InnoDB: Completed initialization of buffer pool
InnoDB: Highest supported file format is Barracuda.
InnoDB: The log sequence numbers and in ibdata files do not match the log sequence number in the ib_logfiles!
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages
InnoDB: from the doublewrite buffer...
InnoDB: Last MySQL binlog file position , file name /var/log/mysql/mysql-bin51.
InnoDB: rollback segment(s) are active.
InnoDB: Waiting for purge to start
InnoDB: 5.6. started; log sequence number [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 , file name /var/log/mysql/mysql-bin51. xtrabackup: starting shutdown with innodb_fast_shutdown =
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number :: innobackupex: Restarting xtrabackup with command: xtrabackup --defaults-file="/home/zhoujy/xtrabackup/2014-11-11_11-56-58/backup-my.cnf" --defaults-group="mysqld" --prepare --target-dir=/home/zhoujy/xtrabackup/--11_11--
for creating ib_logfile* xtrabackup version 2.2. based on MySQL server 5.6. Linux (x86_64) (revision id: )
xtrabackup: cd to /home/zhoujy/xtrabackup/--11_11--
xtrabackup: This target seems to be already prepared.
xtrabackup: notice: xtrabackup_logfile was already used to '--prepare'.
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group =
xtrabackup: innodb_log_file_size =
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group =
xtrabackup: innodb_log_file_size =
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using bytes for buffer pool (set by --use-memory parameter)
InnoDB: Using atomics to ref count buffer pool pages
InnoDB: The InnoDB memory heap is disabled
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Memory barrier is not used
InnoDB: Compressed tables use zlib 1.2.3.4
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, size = 100.0M
InnoDB: Completed initialization of buffer pool
InnoDB: Setting log file ./ib_logfile101 size to MB
InnoDB: Setting log file ./ib_logfile1 size to MB
InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
InnoDB: New log files created, LSN=
InnoDB: Highest supported file format is Barracuda.
InnoDB: rollback segment(s) are active.
InnoDB: Waiting for purge to start
InnoDB: 5.6. started; log sequence number [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 , file name /var/log/mysql/mysql-bin51. xtrabackup: starting shutdown with innodb_fast_shutdown =
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number
:: innobackupex: completed OK!
应用完之后再查看备份文件看是否有变化:
root@ha1:/home/zhoujy/xtrabackup# ls -lh --11_11--/
total .2G
-rw-r--r-- root root 11月 : backup-my.cnf
-rw-r----- root root .2G 11月 : ibdata1
-rw-r--r-- root root 5.0M 11月 : ib_logfile0
-rw-r--r-- root root 5.0M 11月 : ib_logfile1
-rw-r--r-- root root 11月 : xtrabackup_binlog_info
-rw-r--r-- root root 11月 : xtrabackup_binlog_pos_innodb
-rw-r----- root root 11月 : xtrabackup_checkpoints
-rw-r--r-- root root 11月 : xtrabackup_info
-rw-r----- root root 2.0M 11月 : xtrabackup_logfile
drwxr-xr-x root root .0K 11月 : xtra_test
看到redo log已经出现。xtrabackup_开头的几个文件记录了一些日志偏移量的信息和日志名和时间等信息。在xtrabackup_checkpoints中记录了备份的模式:
backup_type = full-backuped。
xtrabackup_binlog_info:记录当前最新的LOG Position
xtrabackup_binlog_pos_innodb:innodb log postion
xtrabackup_checkpoints: 存放备份的起始位置beginlsn和结束位置endlsn,增量备份需要这个lsn[增量备份可以在这里面看from和to两个值的变化
xtrabackup_info:备份的一些具体信息日志
#还原
mysql> drop database xtra_test;
Query OK, 2 rows affected (0.00 sec)
1) 删除原始目录里的文件:
root@ha1:/var/lib/mysql# rm ib_logfile0 ib_logfile1 ibdata1
关闭数据库:
) root@ha1:/var/lib/mysql# /etc/init.d/mysql stop 开始恢复
) :innobackupex --defaults-file=/etc/mysql/my.cnf --copy-back /home/zhoujy/xtrabackup/--11_11--/
执行上面的命令需要保证数据库目录是空的,否则会失败,因为目录里有binlog日志,要么移走,要么就用手动复制需要的文件。所以说日志不要和数据放在一起!
:cp ib_logfile0 ib_logfile1 ibdata1 /var/lib/mysql/
cp -R xtra_test /var/lib/mysql/
修改权限和开启数据库
) root@ha1:/var/lib/mysql# chown -R mysql.mysql ib*
root@ha1:/var/lib/mysql# chown -R mysql.mysql xtra_test/
开启数据库
root@ha1:/var/lib/mysql# /etc/init.d/mysql start
...
mysql start/running, process
数据已恢复:
mysql> use xtra_test
Database changed
mysql> select * from I;
+------+------+
| id | name |
+------+------+
| 11 | A |
| 22 | B |
| 33 | C |
| 44 | D |
| 55 | E |
+------+------+
5 rows in set (0.00 sec)
2)增量备份&还原
#备份
在做增量备份的时候需要做一次全量备份,和上面一样,只是针对所有库的备份:
root@ha1:~# innobackupex --user=zjy --password=123456# --host=192.168.200.51 --defaults-file=/etc/mysql/my.cnf /home/zhoujy/xtrabackup/
...
innobackupex: MySQL binlog position: filename 'mysql-bin51.000002', position
:: innobackupex: Connection to database server closed
:: innobackupex: completed OK!
增量备份这里开始
1.数据库操作:
mysql> select * from I;
+------+------+
| id | name |
+------+------+
| 11 | A |
| 22 | B |
| 33 | C |
| 44 | D |
| 55 | E |
+------+------+
5 rows in set (0.00 sec) mysql> insert into I values(111,'A'),(222,'B'),(333,'C'),(444,'D'),(555,'E');
Query OK, 5 rows affected (0.01 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from M;
+------+------+
| id | name |
+------+------+
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
| 5 | e |
+------+------+
5 rows in set (0.00 sec)
mysql> update M set name = upper(name);
Query OK, 5 rows affected (0.00 sec)
Rows matched: 5 Changed: 5 Warnings: 0 mysql> create table X(name varchar(20))default charset utf8;
Query OK, 0 rows affected (0.01 sec) mysql> insert into X values('zjy');
Query OK, 1 row affected (0.00 sec)
2:增量备份(基于全量的增量备份)
root@ha1:~# innobackupex --user=zjy --password=123456# --host=192.168.200.51 --defaults-file=/etc/mysql/my.cnf --incremental --incremental-basedir=/home/zhoujy/xtrabackup/2014-11-11_13-57-11/ /home/zhoujy/increment_data/
...
...
trabackup: Creating suspend file '/home/zhoujy/increment_data/2014-11-11_14-14-56/xtrabackup_log_copied' with pid ''
xtrabackup: Transaction log of lsn () to () was copied.
:: innobackupex: All tables unlocked innobackupex: Backup created in directory '/home/zhoujy/increment_data/2014-11-11_14-14-56'
innobackupex: MySQL binlog position: filename 'mysql-bin51.000002', position
:: innobackupex: Connection to database server closed
:: innobackupex: completed OK!
其中,--incremental指明是增量备份,--incremental-basedir指定上次完整备份或者增量备份文件的位置。这里的增量备份其实只针对的是InnoDB,对于MyISAM来说,还是完整备份。
增量备份的文件:
root@ha1:/home/zhoujy/increment_data# ls -lh --11_14--/
total 440K
-rw-r--r-- root root 11月 : backup-my.cnf
-rw-r----- root root 400K 11月 : ibdata1.delta
-rw-r----- root root 11月 : ibdata1.meta
drwxr-xr-x root root .0K 11月 : mha_test
drwxr-xr-x root root .0K 11月 : mysql
drwxr-xr-x root root .0K 11月 : performance_schema
-rw-r--r-- root root 11月 : xtrabackup_binlog_info
-rw-r----- root root 11月 : xtrabackup_checkpoints
-rw-r--r-- root root 11月 : xtrabackup_info
-rw-r----- root root .5K 11月 : xtrabackup_logfile
drwxr-xr-x root root .0K 11月 : xtra_test root@ha1:/home/zhoujy/increment_data# cat --11_14--/xtrabackup_checkpoints
backup_type = incremental
from_lsn = 7363103427 对应增量中的to_lsn
to_lsn =
last_lsn =
compact =
3:继续增量备份
数据库操作
mysql> insert into X values('dxy');
Query OK, 1 row affected (0.01 sec) mysql> insert into X values('浙江');
Query OK, 1 row affected (0.01 sec)
增量备份(基于增量的增量备份)
root@ha1:~# innobackupex --user=zjy --password=123456# --host=192.168.200.51 --defaults-file=/etc/mysql/my.cnf --incremental --incremental-basedir=/home/zhoujy/increment_data/2014-11-11_14-14-56/ /home/zhoujy/increment_data/ :: innobackupex: Connection to database server closed
:: innobackupex: completed OK!
增量备份的文件
root@ha1:/home/zhoujy/increment_data# cat --11_14--/xtrabackup_checkpoints
backup_type = incremental
from_lsn = 7363106612 对应上一个备份的to_lsn
to_lsn =
last_lsn =
compact =
要是在第2次做增量备份的时候 --incremental-basedir 指向全量备份,则第一次增量备份中的数据会被第2次包含,只需要还原一次就可以恢复,现在则需要还原2次增量备份。
#还原
#还原全量备份:
root@ha1:/home/zhoujy# innobackupex --apply-log /home/zhoujy/xtrabackup/--11_13--/ #第一次的增量备份应用日志,应用完日志后,将合并到全备上,恢复使用全备恢复
root@ha1:~# innobackupex --apply-log /home/zhoujy/xtrabackup/--11_13--/ --incremental-dir=/home/zhoujy/increment_data/--11_14--/ #第二次的增量备份应用日志,应用完日志后,将合并到全备上,恢复使用全备恢复
root@ha1:~# innobackupex --apply-log /home/zhoujy/xtrabackup/--11_13--/ --incremental-dir=/home/zhoujy/increment_data/--11_14--/ 此时两次增量备份其实都合并到全备上了,恢复是只需要使用全备进行恢复就可以了
还原操作执行完之后,查看其lsn的信息:
root@ha1:/home/zhoujy/xtrabackup/--11_13--# cat xtrabackup_checkpoints
backup_type = full-prepared
from_lsn =
to_lsn =
last_lsn =
compact =
说明了,还原操作执行没问题。按照之前还原操作的步骤来恢复数据:先删除数据,再把文件复制过去,看看是否成功。测试下来,还原成功。
3)压缩备份:必须使用-i参数拆包解压
打包(Tar)备份
innobackupex --user=zjy --password=123456# --host=192.168.200.51 --defaults-file=/etc/mysql/my.cnf --databases=xtra_test --stream=tar /home/zhoujy/xtrabackup/ >/home/zhoujy/xtrabackup/xtra_test.tar
拆包还原
root@ha1:/home/zhoujy/xtrabackup# tar ixvf xtra_test.tar
./backup-my.cnf
ibdata1
xtra_test/db.opt
xtra_test/M.MYI
xtra_test/M.frm
xtra_test/I.frm
xtra_test/M.MYD
./xtrabackup_binlog_info
xtrabackup_logfile
xtrabackup_checkpoints
./xtrabackup_info
还原方法和上面一样,就不多做说明了。
打包压缩:
root@ha1:/home/zhoujy/xtrabackup# innobackupex --user=zjy --password=123456# --host=192.168.200.51 --defaults-file=/etc/mysql/my.cnf --databases=xtra_test --stream=tar /home/zhoujy/xtrabackup/ | gzip >/home/zhoujy/xtrabackup/xtra_test.tar.gz
解压:
root@ha1:/home/zhoujy/xtrabackup# tar izxvf xtra_test.tar.gz
./backup-my.cnf
ibdata1
xtra_test/db.opt
xtra_test/M.MYI
xtra_test/M.frm
xtra_test/I.frm
xtra_test/M.MYD
./xtrabackup_binlog_info
xtrabackup_logfile
xtrabackup_checkpoints
./xtrabackup_info
还原方法和上面一样。
更多信息见:
http://mysql.taobao.org/monthly/2016/03/07/
http://op.baidu.com/2014/07/xtrabackup%E5%8E%9F%E7%90%86%E5%8F%8A%E5%AE%9E%E6%96%BD/
http://www.drupal001.com/2014/02/percona-xtrabackup-mysql/
http://www.xuchanggang.cn/archives/700.html
http://blog.csdn.net/mr_mablevi/article/details/5860571
http://blog.csdn.net/yongsheng0550/article/details/6682162
Xtrabackup 安装使用的更多相关文章
- mysql 开发进阶篇系列 45 物理备份与恢复(xtrabackup 安装,用户权限,配置)
一. 安装说明 安装XtraBackup 2.4 版本有三种方式: (1) 存储库安装Percona XtraBackup(推荐) (2 )下载的rpm或apt包安装Percona XtraBacku ...
- Percona XtraBackup 安装介绍篇
XtraBackup介绍 XtraBackup是Percona公司的开源项目,用以实现类似Innodb官方的热备份工具InnoDB Hot Backup的功能,它支持在线热备份(备份时不影响数据读写) ...
- mysql备份学习笔记及xtrabackup安装
(参考书籍:<深入浅出MySQL>) 一.备份恢复策略 a) 确定要备份的表的存储引擎是事务型还是非事务型 b) 确定使用全备份还是增量备份 c) 定期做备份 ...
- xtrabackup 安装
xtrabackup 安装 yum install -y perl-DBI perl-DBD-MySQL perl-Time-HiRes perl-IO-Socket-SSL perl-Dige ...
- XtraBackup安装
1.从官网下载XtraBackup2.4.4. percona-xtrabackup-24-2.4.4-1.el6.x86_64.rpm 2.安装依赖包 yum -y install perl per ...
- xtrabackup 安装、备份、还原及错误处理 教程
xtrabackup 是MYSQL的一个备份软件 Xtrabackup是一个对InnoDB做数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个 ...
- 备份恢复工具xtrabackup安装和使用的记录
一.安装 下面的方法是在测试环境可以上网的情况下安装的: 提供的是在centos7上安装的方法: 包下载: wget https://www.percona.com/downloads/percona ...
- xtrabackup安装使用及原理
Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtradb数据库进行热备的工具.Xtrabackup中主要包含两个工具 ...
- xtrabackup安装部署(二)
在官网中,复制相关链接下载最新版本(建议使用当前发布版本前6个月左右的稳定版本) https://www.percona.com/downloads/XtraBackup/LATEST/ 1.下载和安 ...
随机推荐
- Android 自定义Dialog类,并在Activity中实现按钮监听。
实际开发中,经常会用到Dialog,比如退出时候会弹出是否退出,或者还有一些编辑框也会用Dialog实现,效果图如下: 开发中遇到的问题无非在于如果在Activity中监听这个Dialog中实现的 ...
- 种子填充算法描述及C++代码实现
项目需要看了种子填充算法,改进了算法主要去除面积小的部分.种子填充算法分为两种,简单的和基于扫描线的方法,简单的算法如下描述(笔者针对的是二值图像): (1)从上到下,从左到有,依次扫描每个像素: ( ...
- 【原】python中文文本挖掘资料集合
这些网址是我在学习python中文文本挖掘时觉得比较好的网站,记录一下,后期也会不定期添加: 1.http://www.52nlp.cn/python-%E7%BD%91%E9%A1%B5%E7% ...
- 让Web API支持Protocol Buffers
简介 现在我们Web API项目基本上都是使用的Json作为通信的格式,随着移动互联网的兴起,Web API不仅其他系统可以使用,手机端也可以使用,但是手机端也有相对特殊的地方,网络通信除了wifi, ...
- 了解EF CodeFirst的Migrator功能与Migrator.Net对比
在上一篇[数据库迁移利器:Migrator.Net]中,很多朋友提到了EF的CodeFirst也有数据库的迁移功能,说来真惭愧,玩了那么多年,至今还未去了解EF,今天来了解下CodeFirst然后与M ...
- jquery-自适应全屏背景轮播动画
实时自适应浏览器窗口大小的全屏背景轮播动画 <!DOCTYPE html> <html> <head> <meta http-equiv="Cont ...
- iOS中UI阶段常用的一些方法
UI 即 UserInterface(用户界面 1.iOS系统版本,每年都有更新.对我们开发者而言,主要的是观察API的变化. 2.iPhone新手机发布,会产生不同尺寸的屏幕,现在市面上有4种尺寸, ...
- 修改httpd默认端口号
Tomcat: vim /etc/httpd/conf/httpd.conf//别忘了service httpd restart Nginx: vim /etc/nginx/nginx.conf//完 ...
- AudioRecord类获取录音音量分贝数
转自:http://www.jb51.net/article/64806.htm public class AudioRecordDemo { private static final S ...
- 【51Nod 1622】【算法马拉松 19C】集合对
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1622 简单题..直接暴力快速幂 #include<cstdio&g ...