首页 > 代码库 > XtraBackup 备份与恢复

XtraBackup 备份与恢复

 

前一篇文章我们讲到了PXB的原理以及安装方法,接下来将详细介绍 XtraBackup 备份和恢复的具体过程。

xtrabackup 工具有许多参数,具体可去官网查询(xtrabackup 参数选项),这里简单介绍一些常用的参数。

--defaults-file=[MY.CNF]

指定配置文件:只能从给定的文件中读取默认选项。 且必须作为命令行上的第一个选项;必须是一个真实的文件,它不能是一个符号链接。

--database=#  

指定备份的数据库和表,格式为:--database="db1[.tb1] db2[.tb2]"

 

创建用于备份恢复的用户 pxb 并赋予权限

mysql> create user pxb@localhost identified by 123456;mysql> grant reload,process,lock tables,replication client on *.* to pxb@localhost;

创建存放目录

[root@centos6 mysql]# mkdir -pv /data/pxbmkdir: 已创建目录 "/data"mkdir: 已创建目录 "/data/pxb"

进行数据库全备

[root@centos6 pxb]# innobackupex --defaults-file=/etc/my.cnf --user=pxb --password=123456 --socket=/tmp/mysql.sock  /data/pxb                                                                                                               170424 02:46:11 innobackupex: Starting the backup operationIMPORTANT: Please check that the backup run completes successfully.           At the end of a successful backup run innobackupex           prints "completed OK!".…………170424 02:46:12 >> log scanned up to (2627779)170424 02:46:13 Executing FLUSH NO_WRITE_TO_BINLOG TABLES...170424 02:46:13 Executing FLUSH TABLES WITH READ LOCK...170424 02:46:13 Starting to backup non-InnoDB tables and files…………170424 02:46:15 Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...xtrabackup: The latest check point (for incremental): 2627770xtrabackup: Stopping log copying thread..170424 02:46:15 >> log scanned up to (2627779)170424 02:46:15 Executing UNLOCK TABLES170424 02:46:15 All tables unlocked170424 02:46:15 [00] Copying ib_buffer_pool to /data/pxb/2017-04-24_02-46-11/ib_buffer_pool170424 02:46:15 [00]        ...done170424 02:46:15 Backup created in directory /data/pxb/2017-04-24_02-46-11/MySQL binlog position: filename mysql-bin.000002, position 2628170424 02:46:15 [00] Writing backup-my.cnf170424 02:46:15 [00]        ...done170424 02:46:15 [00] Writing xtrabackup_info170424 02:46:15 [00]        ...donextrabackup: Transaction log of lsn (2627770) to (2627779) was copied.170424 02:46:15 completed OK!

可以看到整个备份过程:连接数据库,开始拷贝redo log,拷贝innodb表文件,锁表、拷贝非innodb表文件,停止拷贝redo log,解锁

查看生成的文件:

[root@centos6 pxb]# ll 2017-04-24_02-46-11/总用量 12340-rw-r----- 1 root root      427 4月  24 02:46 backup-my.cnf-rw-r----- 1 root root      358 4月  24 02:46 ib_buffer_pool-rw-r----- 1 root root 12582912 4月  24 02:46 ibdata1drwxr-x--- 2 root root     4096 4月  24 02:46 mysqldrwxr-x--- 2 root root     4096 4月  24 02:46 performance_schemadrwxr-x--- 2 root root    12288 4月  24 02:46 sysdrwxr-x--- 2 root root     4096 4月  24 02:46 testdrwxr-x--- 2 root root     4096 4月  24 02:46 test1-rw-r----- 1 root root       22 4月  24 02:46 xtrabackup_binlog_info-rw-r----- 1 root root      113 4月  24 02:46 xtrabackup_checkpoints-rw-r----- 1 root root      518 4月  24 02:46 xtrabackup_info-rw-r----- 1 root root     2560 4月  24 02:46 xtrabackup_logfile

 

 

 

 

 

 

技术分享

XtraBackup 备份与恢复