xtrabackup安装备份与恢复

安装Percona XtraBackup
[root@mysql etc]# cd /etc/yum.repos.d/
[root@mysql yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo
安装yum源
[root@mysql yum.repos.d]# yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
[root@mysql yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo  percona-release.repo
[root@mysql yum.repos.d]# 

[root@mysql yum.repos.d]# yum list | grep percona
percona-release.noarch                     0.1-4                         @/percona-release-0.1-4.noarch
Percona-SQL-50-debuginfo.x86_64            5.0.92-b23.89.rhel6           percona-release-x86_64
Percona-SQL-client-50.x86_64               5.0.92-b23.89.rhel6           percona-release-x86_64
Percona-SQL-devel-50.x86_64                5.0.92-b23.89.rhel6           percona-release-x86_64
Percona-SQL-server-50.x86_64               5.0.92-b23.89.rhel6           percona-release-x86_64
Percona-SQL-shared-50.x86_64               5.0.92-b23.89.rhel6           percona-release-x86_64
Percona-SQL-shared-compat.x86_64           5.0.92-b23.89.rhel6           percona-release-x86_64
Percona-SQL-test-50.x86_64                 5.0.92-b23.89.rhel6           percona-release-x86_64
Percona-Server-51-debuginfo.x86_64         5.1.73-rel14.12.624.rhel6     percona-release-x86_64
Percona-Server-55-debuginfo.x86_64         5.5.55-rel38.8.el6            percona-release-x86_64
Percona-Server-56-debuginfo.x86_64         5.6.36-rel82.0.el6            percona-release-x86_64
Percona-Server-57-debuginfo.x86_64         5.7.18-15.1.el6               percona-release-x86_64
Percona-Server-MongoDB.x86_64              3.0.15-1.10.el6               percona-release-x86_64
Percona-Server-MongoDB-32.x86_64           3.2.15-3.5.el6                percona-release-x86_64

安装依赖的包
yum -y install perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL
[root@mysql mysqldata]# wget  ftp://rpmfind.net/linux/dag/redhat/el6/en/x86_64/dag/RPMS/libev-4.15-1.el6.rf.x86_64.rpm  
[root@mysql mysqldata]# rpm -ivh libev-4.15-1.el6.rf.x86_64.rpm 
warning: libev-4.15-1.el6.rf.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY
Preparing...                ########################################### [100%]
   1:libev                  ########################################### [100%]
[root@mysql mysqldata]# 

安装xtrabackup
[root@mysql mysqldata]# yum install percona-xtrabackup-24
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.163.com
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package percona-xtrabackup-24.x86_64 0:2.4.8-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================================================================================================================
 Package                                             Arch                                 Version                                   Repository                                            Size
===============================================================================================================================================================================================
Installing:
 percona-xtrabackup-24                               x86_64                               2.4.8-1.el6                               percona-release-x86_64                               8.0 M
Transaction Summary
===============================================================================================================================================================================================
Install       1 Package(s)

参考:
https://www.percona.com/doc/percona-xtrabackup/2.4/installation/yum_repo.html


全量备份
备份目录:
/data/backup/full
# 全量备份
innobackupex --user=root --password=root001 -S /mysqldata/mysql.sock /data/backup/full

[root@mysql 2017-07-27_15-43-26]# ls
backup-my.cnf  ib_buffer_pool  ibdata1  mysql  performance_schema  sys  www  xtrabackup_binlog_info  xtrabackup_checkpoints  xtrabackup_info  xtrabackup_logfile
[root@mysql 2017-07-27_15-43-26]# pwd
/data/backup/full/2017-07-27_15-43-26

全量备份恢复:
拷贝备份文件到另外的目录恢复
[root@mysql backup]# cp /data/backup/full/2017-07-27_15-43-26/bakup.tar ./data
[root@mysql backup]# ls
bakup.tar
[root@mysql backup]# tar -xvf bakup.tar 


恢复数据文件
innobackupex --defaults-file=/home/my.cnf --apply-log /home/backup/data
[root@mysql data]# innobackupex --defaults-file=/home/my.cnf --apply-log /home/backup/data
170727 16:10:30 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 version 2.4.8 based on MySQL server 5.7.13 Linux (x86_64) (revision id: 97330f7)
xtrabackup: cd to /home/backup/data/
xtrabackup: This target seems to be not prepared yet.
InnoDB: Number of pools: 1
xtrabackup: xtrabackup_logfile detected: size=8388608, start_lsn=(1309531352)
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup:   innodb_data_home_dir = .
xtrabackup:   innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup:   innodb_log_group_home_dir = .
xtrabackup:   innodb_log_files_in_group = 1
xtrabackup:   innodb_log_file_size = 8388608
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup:   innodb_data_home_dir = .
xtrabackup:   innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup:   innodb_log_group_home_dir = .
xtrabackup:   innodb_log_files_in_group = 1
xtrabackup:   innodb_log_file_size = 8388608
xtrabackup: Starting InnoDB instance for recovery.
xtrabackup: Using 104857600 bytes for buffer pool (set by --use-memory parameter)
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Number of pools: 1
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
InnoDB: Completed initialization of buffer pool
InnoDB: page_cleaner coordinator priority: -20
InnoDB: Highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 1309531352
InnoDB: Doing recovery: scanned up to log sequence number 1309531361 (0%)
InnoDB: Doing recovery: scanned up to log sequence number 1309531361 (0%)
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: xtrabackup: Last MySQL binlog file position 554770132, file name mysql-bin.000011
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: Waiting for purge to start
InnoDB: 5.7.13 started; log sequence number 1309531361
InnoDB: xtrabackup: Last MySQL binlog file position 554770132, file name mysql-bin.000011
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 1309531380
InnoDB: Number of pools: 1
xtrabackup: using the following InnoDB configuration for recovery:
xtrabackup:   innodb_data_home_dir = .
xtrabackup:   innodb_data_file_path = ibdata1:12M:autoextend
xtrabackup:   innodb_log_group_home_dir = .
xtrabackup:   innodb_log_files_in_group = 2
xtrabackup:   innodb_log_file_size = 67108864
InnoDB: PUNCH HOLE support available
InnoDB: Mutexes and rw_locks use GCC atomic builtins
InnoDB: Uses event mutexes
InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
InnoDB: Compressed tables use zlib 1.2.3
InnoDB: Number of pools: 1
InnoDB: Using CPU crc32 instructions
InnoDB: Initializing buffer pool, total size = 100M, instances = 1, chunk size = 100M
InnoDB: Completed initialization of buffer pool
InnoDB: page_cleaner coordinator priority: -20
InnoDB: Setting log file ./ib_logfile101 size to 64 MB
InnoDB: Setting log file ./ib_logfile1 size to 64 MB
InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
InnoDB: New log files created, LSN=1309531380
InnoDB: Highest supported file format is Barracuda.
InnoDB: Log scan progressed past the checkpoint lsn 1309531660
InnoDB: Doing recovery: scanned up to log sequence number 1309531669 (0%)
InnoDB: Doing recovery: scanned up to log sequence number 1309531669 (0%)
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: xtrabackup: Last MySQL binlog file position 554770132, file name mysql-bin.000011
InnoDB: Removed temporary tablespace data file: "ibtmp1"
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: Waiting for purge to start
InnoDB: 5.7.13 started; log sequence number 1309531669
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 1309531688
170727 16:10:35 completed OK!
[root@mysql data]# 

修改文件属主
[root@mysql backup]# chown mysql:mysql -R data/

启动mysqld进程并且登录验证
mysqld_safe --defaults-file=/home/my.cnf --user=mysql --datadir=/home/backup/data &

[root@mysql home]# mysqld_safe --defaults-file=/home/my.cnf --user=mysql --datadir=/home/backup/data
2017-07-27T08:20:45.527469Z mysqld_safe Logging to '/home/backup/mysql-error.log'.
2017-07-27T08:20:45.543553Z mysqld_safe Starting mysqld daemon with databases from /home/backup/data

登录数据库
[root@mysql 2017-07-27_15-43-26]# mysql -uroot -proot001 -S /home/backup/mysql.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.14-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| www                |
+--------------------+
5 rows in set (0.00 sec)
mysql> 

增量备份:
innobackupex --user=root --password=root001 -S /mysqldata/mysql.sock /data/backup/full
在全量备份的基础上进行的备份:
[root@mysql inc1]# innobackupex  --user=root --password=root001 -S /mysqldata/mysql.sock --incremental /data/backup/inc1  --incremental-basedir=/data/backup/full/2017-07-27_15-43-26

增量备份如果要恢复
恢复数据文件
innobackupex --apply-log --redo-only /data/backup/full/2017-07-27_15-43-26
innobackupex --apply-log --redo-only /data/backup/full/2017-07-27_15-43-26 --incremental-dir=/data/backup/inc2/2017-07-27_16-28-43

如果要恢复到执行的时间点,就需要应用备份的binlog日志到指定的时间点
mysqlbinlog /mysqllog/mysql-bin0001 --start-position=1244 --stop-position=7899

猜你喜欢

转载自blog.csdn.net/weiwangsisoftstone/article/details/76208588