mysql数据备份之xtrabackup-创新互联
上一篇简单介绍了一下mysqldump进行数据库的备份和恢复,这一篇说一下另一种备份工具xtrabackup,在InnoDB事务引擎泛滥的时代,xtrabackup可以很好的支持数据库的热备份,这就很讨人喜,
创新互联公司是一家成都做网站、网站建设,提供网页设计,网站设计,网站制作,建网站,按需网站开发,网站开发公司,自2013年起是互联行业建设者,服务者。以提升客户品牌价值为核心业务,全程参与项目的网站策划设计制作,前端开发,后台程序制作以及后期项目运营并提出专业建议和思路。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 = Nbackup-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=0xtrabackup_checkpoints:记录了此次的类型及起始和终止的LSN;
[root@www 2018-11-05_20-31-30]# cat xtrabackup_checkpoints backup_type = full-backuped from_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:55: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即可;
xtrabackup是一个相当好的备份工具,在如今事务引擎遍地的时代,良好的热备份机制和简单化的操作,对我们来说很友好,所以,我很推荐这个工具,而mysqldump大多用来做测试用,因为mysqldump需要锁表,所以温备份机制在这方便不如xtrabackup的热备份机制。但是,在我们实验环境做测试的情况下,这个直接打包成数据库,copy到其他主机就可以释放,还是很不错的。
另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章题目:mysql数据备份之xtrabackup-创新互联
网站URL:http://azwzsj.com/article/icjco.html