您的位置:首页 > 其它

Xtrabackup--增量备份及恢复(三)

2012-09-02 17:06 423 查看
在一次全备的基础上,对新插入的数据另进行的备份
具体操作看本文内容

[root@acong data]# mkdir /test/xtr
[root@acong data]# netstat -lnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
tcp 0 0 :::22 :::*
[root@acong data]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.52 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database xtr;
Query OK, 1 row affected (0.00 sec)
mysql> use xtr;
Database changed
mysql> create table xtr(id int);
Query OK, 0 rows affected (0.02 sec)
mysql> insert into xtr value(1);
Query OK, 1 row affected (0.01 sec)
mysql> insert into xtr value(2);
Query OK, 1 row affected (0.01 sec)
mysql> insert into xtr value(3);
Query OK, 1 row affected (0.00 sec)
mysql> select * from xtr;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)

[root@acong data]# xtrabackup --default-file=/etc/my.cnf --backup --target-dir=/test/xtr/    ##全量备份

xtrabackup version 2.0.2 for Percona Server 5.1.59 pc-linux-gnu (i686) (revision id: undefined)
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /usr/local/mysql/data
xtrabackup: Target instance is assumed as followings.
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 (51928)
[01] Copying ./ibdata1 to /test/xtr/ibdata1
[01] ...done
xtrabackup: The latest check point (for incremental): '51928'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (51928)
xtrabackup: Transaction log of lsn (51928) to (51928) was copied.
[root@acong data]# ll /test/xtr/
total 10264
-rw-r----- 1 root root 10485760 Aug 26 19:47 ibdata1
-rw-r----- 1 root root 73 Aug 26 19:47 xtrabackup_checkpoints
-rw-r----- 1 root root 2560 Aug 26 19:47 xtrabackup_logfile
[root@acong data]# mkdir /test/xtr1

[root@acong data]# mysql -uroot -p123456     ##进入数据库插入几条数据,在进行增量备份

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.52 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use xtr;
Database changed
mysql> select * from xtr;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
mysql> insert into xtr value(4);
Query OK, 1 row affected (0.01 sec)
mysql> insert into xtr value(5);
Query OK, 1 row affected (0.00 sec)
mysql> insert into xtr value(6);
Query OK, 1 row affected (0.00 sec)
mysql> select * from xtr;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
+------+
6 rows in set (0.00 sec)

[root@acong data]# xtrabackup --defaults-file=/etc/my.cnf --backup --target-dir=/test/xtr1/ --incremental-basedir=/test/xtr    ##/test/xtr1/这是增量备份的目录,在做增量时就要变成xtr2

xtrabackup version 2.0.2 for Percona Server 5.1.59 pc-linux-gnu (i686) (revision id: undefined)
incremental backup from 51928 is enabled.
xtrabackup: uses posix_fadvise().
xtrabackup: cd to /usr/local/mysql/data
xtrabackup: Target instance is assumed as followings.
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 (52189)
[01] Copying ./ibdata1 to /test/xtr1/ibdata1.delta
[01] ...done
xtrabackup: The latest check point (for incremental): '52189'
xtrabackup: Stopping log copying thread.
.>> log scanned up to (52189)
xtrabackup: Transaction log of lsn (52189) to (52189) was copied.
[root@acong data]# ll /test/xtr1/
total 160
-rw-r----- 1 root root 147456 Aug 26 20:05 ibdata1.delta
-rw-r----- 1 root root 31 Aug 26 20:05 ibdata1.meta
-rw-r----- 1 root root 75 Aug 26 20:05 xtrabackup_checkpoints
-rw-r----- 1 root root 2560 Aug 26 20:05 xtrabackup_logfile
==============================================================================
恢复。(步骤同全量恢复,只是在执行恢复命令的时候中间多一步)
[root@acong data]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.1.52 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use xtr;
Database changed
mysql> select * from xtr;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
+------+
6 rows in set (0.01 sec)
mysql> delete from xtr where id>3;
Query OK, 3 rows affected (0.01 sec)
mysql> select * from xtr;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.00 sec)
mysql> \q
Bye
[root@acong data]# /etc/init.d/mysqld stop
Shutting down MySQL...... [ OK ]
[root@acong data]# pwd
/usr/local/mysql/data
[root@acong data]# ll
total 20564
drwx------ 2 mysql mysql 4096 Aug 26 18:47 aa
drwx------ 2 mysql mysql 4096 Aug 26 18:15 acong
-rw-rw---- 1 mysql root 16841 Aug 26 21:25 acong.err
-rw-r----- 1 mysql mysql 10485760 Aug 26 21:25 ibdata1
-rw-r--r-- 1 mysql mysql 5242880 Aug 26 21:25 ib_logfile0
-rw-r--r-- 1 mysql mysql 5242880 Aug 26 18:55 ib_logfile1
drwx------ 2 mysql mysql 4096 Aug 26 18:11 lincong
drwx------ 2 mysql root 4096 Aug 24 05:47 mysql
drwx------ 2 mysql root 4096 Aug 24 05:22 test
drwx------ 2 mysql mysql 4096 Aug 26 19:43 xtr
[root@acong data]# rm -rf ib*
[root@acong data]# ll
total 44
drwx------ 2 mysql mysql 4096 Aug 26 18:47 aa
drwx------ 2 mysql mysql 4096 Aug 26 18:15 acong
-rw-rw---- 1 mysql root 16841 Aug 26 21:25 acong.err
drwx------ 2 mysql mysql 4096 Aug 26 18:11 lincong
drwx------ 2 mysql root 4096 Aug 24 05:47 mysql
drwx------ 2 mysql root 4096 Aug 24 05:22 test
drwx------ 2 mysql mysql 4096 Aug 26 19:43 xtr

[root@acong data]# xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/test/xtr       ##增量恢复

xtrabackup version 2.0.2 for Percona Server 5.1.59 pc-linux-gnu (i686) (revision id: undefined)
xtrabackup: cd to /test/xtr
xtrabackup: This target seems to be not prepared yet.
xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(51928)
xtrabackup: Temporary instance for recovery is set as followings.
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 = 1
xtrabackup: innodb_log_file_size = 2097152
xtrabackup: Temporary instance for recovery is set as followings.
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 = 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
120826 21:34:53 InnoDB: Initializing buffer pool, size = 100.0M
120826 21:34:53 InnoDB: Completed initialization of buffer pool
120826 21:34:53 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!
120826 21:34:53 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
120826 21:34:53 Percona XtraDB (http://www.percona.com) 1.0.17-12.5 started; log sequence number 51928
[notice (again)]
If you use binary log and don't use any hack of group commit,
the binary log position seems to be:
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
120826 21:34:53 InnoDB: Starting shutdown...
120826 21:34:54 InnoDB: Shutdown completed; log sequence number 51928

[root@acong data]# xtrabackup --target-dir=/test/xtr --prepare --incremental-dir=/test/xtr1/    ##增量恢复

xtrabackup version 2.0.2 for Percona Server 5.1.59 pc-linux-gnu (i686) (revision id: undefined)
incremental backup from 51928 is enabled.
xtrabackup: cd to /test/xtr
xtrabackup: This target seems to be already prepared.
xtrabackup: xtrabackup_logfile detected: size=2097152, start_lsn=(52189)
xtrabackup: Temporary instance for recovery is set as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = /test/xtr1/
xtrabackup: innodb_log_files_in_group = 1
xtrabackup: innodb_log_file_size = 2097152
xtrabackup: page size for /test/xtr1//ibdata1.delta is 16384 bytes
Applying /test/xtr1//ibdata1.delta to ././ibdata1...
xtrabackup: Temporary instance for recovery is set as followings.
xtrabackup: innodb_data_home_dir = ./
xtrabackup: innodb_data_file_path = ibdata1:10M:autoextend
xtrabackup: innodb_log_group_home_dir = /test/xtr1/
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
120826 21:35:45 InnoDB: Initializing buffer pool, size = 100.0M
120826 21:35:45 InnoDB: Completed initialization of buffer pool
120826 21:35:45 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!
120826 21:35:45 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
120826 21:35:45 Percona XtraDB (http://www.percona.com) 1.0.17-12.5 started; log sequence number 52189
[notice (again)]
If you use binary log and don't use any hack of group commit,
the binary log position seems to be:
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
120826 21:35:45 InnoDB: Starting shutdown...
120826 21:35:46 InnoDB: Shutdown completed; log sequence number 52189

[root@acong data]# xtrabackup --defaults-file=/etc/my.cnf --prepare --target-dir=/test/xtr    ##增量恢复

xtrabackup version 2.0.2 for Percona Server 5.1.59 pc-linux-gnu (i686) (revision id: undefined)
xtrabackup: cd to /test/xtr
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:10M:autoextend
xtrabackup: innodb_log_group_home_dir = ./
xtrabackup: innodb_log_files_in_group = 2
xtrabackup: innodb_log_file_size = 5242880
xtrabackup: Temporary instance for recovery is set as followings.
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
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
120826 21:36:26 InnoDB: Initializing buffer pool, size = 100.0M
120826 21:36:26 InnoDB: Completed initialization of buffer pool
120826 21:36:26 InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
120826 21:36:26 InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
120826 21:36:26 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!
120826 21:36:26 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
120826 21:36:26 Percona XtraDB (http://www.percona.com) 1.0.17-12.5 started; log sequence number 52236
[notice (again)]
If you use binary log and don't use any hack of group commit,
the binary log position seems to be:
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
120826 21:36:26 InnoDB: Starting shutdown...
120826 21:36:26 InnoDB: Shutdown completed; log sequence number 52236
[root@acong data]# ll /test/xtr/
total 22576
-rw-r----- 1 root root 10485760 Aug 26 21:36 ibdata1
-rw-r--r-- 1 root root 5242880 Aug 26 21:36 ib_logfile0
-rw-r--r-- 1 root root 5242880 Aug 26 21:36 ib_logfile1
-rw-r----- 1 root root 73 Aug 26 21:36 xtrabackup_checkpoints
-rw-r----- 1 root root 2097152 Aug 26 21:34 xtrabackup_logfile

[root@acong data]# cp /test/xtr/ib* .

cp: overwrite `./ibdata1'? y
cp: overwrite `./ib_logfile0'? y
cp: overwrite `./ib_logfile1'? y
[root@acong data]# /etc/init.d/mysqld restart
Shutting down MySQL..... [ OK ]
Starting MySQL. [ OK ]
[root@acong data]# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.52 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use xtr;
Database changed
mysql> select * from xtr;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6 |
+------+
6 rows in set (0.00 sec)
mysql> \q
Bye
[root@acong data]# ll
total 20572
drwx------ 2 mysql mysql 4096 Aug 26 18:47 aa
drwx------ 2 mysql mysql 4096 Aug 26 18:15 acong
-rw-rw---- 1 mysql root 23405 Aug 26 21:40 acong.err
-rw-rw---- 1 mysql mysql 5 Aug 26 21:39 acong.pid
-rw-rw---- 1 mysql mysql 10485760 Aug 26 21:40 ibdata1
-rw-rw---- 1 mysql mysql 5242880 Aug 26 21:40 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Aug 26 21:39 ib_logfile1
drwx------ 2 mysql mysql 4096 Aug 26 18:11 lincong
drwx------ 2 mysql root 4096 Aug 24 05:47 mysql
drwx------ 2 mysql root 4096 Aug 24 05:22 test
drwx------ 2 mysql mysql 4096 Aug 26 19:43 xtr

本文的文字叙述很少,代码偏多照着操作,慢慢慢慢领会,祝你们成功
本文出自 “木木耳总” 博客,请务必保留此出处http://learon.blog.51cto.com/1114795/980078
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: