您的位置:首页 > 数据库 > MySQL

mysql数据备份之 xtrabackup

2018-11-05 21:08 1986 查看

上一篇简单介绍了一下mysqldump进行数据库的备份和恢复,这一篇说一下另一种备份工具xtrabackup,在InnoDB事务引擎泛滥的时代,xtrabackup可以很好的支持数据库的热备份,这就很讨人喜,

 

Xtrabackup在epel源中有,所以直接用yum安装即可;

完全备份就是直接连接MySQL服务,给定一个目标目录即可;

 

[root@www ~]# innobackupex  --user=root --host=localhost --port=3306 --password='123456'  /data/mydata
181105 20:31:30 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!".
…
181105 20:31:39 Executing UNLOCK TABLES
181105 20:31:39 All tables unlocked
181105 20:31:39 Backup created in directory '/data/mydata/2018-11-05_20-31-30'
181105 20:31:39 [00] Writing backup-my.cnf
181105 20:31:39 [00]        ...done
181105 20:31:39 [00] Writing xtrabackup_info
181105 20:31:39 [00]        ...done
xtrabackup: Transaction log of lsn (9424992) to (9424992) was copied.
181105 20:31:39 completed OK!

 

 

然后我们就可以在备份的目录中看到几个文件

[root@www ~]# ls /data/mydata/2018-11-05_20-31-30/
backup-my.cnf  ibdata1  performance_schema  xtrabackup_checkpoints  xtrabackup_logfile
hellodb        mysql    wpsdb               xtrabackup_info         zabbix

 

除了数据库之外,还有几个特殊的文件:

xtrabackup_binlog_info:记录了整个备份过程中的一些属性信息;

[root@www ~]# cd /data/mydata/2018-11-05_20-31-30/
[root@www 2018-11-05_20-31-30]# cat xtrabackup_info
uuid = 725248b0-da18-11e8-9fcc-000c29ceaa48
name =
tool_name = innobackupex
tool_command = --user=root --host=localhost --port=3306 --password=... /data/mydata
tool_version = 2.3.6
ibbackup_version = 2.3.6
server_version = 5.5.60-MariaDB
start_time = 2018-11-05 20:31:31
end_time = 2018-11-05 20:31:39
lock_time = 0
binlog_pos =
innodb_from_lsn = 0
innodb_to_lsn = 9424992
partial = N
incremental = N
format = file
compact = N
compressed = N
encrypted = N

 

backup-my.cnf:记录与InnoDB存储引擎相关的重要配置参数;

[root@www 2018-11-05_20-31-30]# cat backup-my.cnf
# This MySQL options file was generated by innobackupex.
 
# The MySQL server
[mysqld]
innodb_checksum_algorithm=innodb
innodb_log_checksum_algorithm=innodb
innodb_data_file_path=ibdata1:10M:autoextend
innodb_log_files_in_group=2
innodb_log_file_size=5242880
innodb_fast_checksum=false
innodb_page_size=16384
innodb_log_block_size=512
innodb_undo_directory=.
innodb_undo_tablespaces=0

 

xtrabackup_checkpoints:记录了此次的类型及起始和终止的LSN;

[root@www 2018-11-05_20-31-30]# cat xtrabackup_checkpoints
backup_type = full-backuped
fr
b62
om_lsn = 0
to_lsn = 9424992
last_lsn = 9424992
compact = 0
recover_binlog_info = 0
 
xtrabackup_binlog_info:记录当前使用的二进制日志的一致性坐标;
[root@www 2018-11-05_20-55-04]# cat xtrabackup_binlog_info
binlog.000001       245

 

 

完全备份的恢复(mysql的数据目录为空):

       恢复数据的过程只需要添加一个--copy-back即可完成;

[root@www 2018-11-05_20-55-04]# innobackupex --copy-back ./
181105 20:59:30 innobackupex: Starting the copy-back operation
 
IMPORTANT: Please check that the copy-back run completes successfully.
           At the end of a successful copy-back run innobackupex
           prints "completed OK!".

 

增量备份:

       相比于之前的完全备份,需要--incremental和--incremental-basedir两个选项即可;

[root@www ~]# innobackupex --incremental /data/mydata --incremental-basedir=/data/mydata/2018-11-05_20-31-30
181105 20:54:41 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!".
…
181105 20:55:14 Executing UNLOCK TABLES
181105 20:55:14 All tables unlocked
181105 20:55:14 Backup created in directory '/data/mydata/2018-11-05_20-55-04'
MySQL binlog position: filename 'binlog.000001', position '245'
181105 20:55:14 [00] Writing backup-my.cnf
181105 20:55:14 [00]        ...done
181105 20:55:14 [00] Writing xtrabackup_info
181105 20:55:14 [00]        ...done
xtrabackup: Transaction log of lsn (9424992) to (9424992) was copied.
181105 20:5
3eac
5:14 completed OK!

 

通过查看xtrabackup-checkpoints文件内容即可;

[root@www 2018-11-05_20-55-04]# cat xtrabackup_checkpoints
backup_type = incremental
from_lsn = 9424992
to_lsn = 9424992
last_lsn = 9424992
compact = 0
recover_binlog_info = 0

 

增量备份的恢复过程同上,也是一个--copy-back即可;


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息