标签:备份 还原 xtrabackup
一:安装:
地址:https://www.percona.com/software/mysql-database/percona-xtrabackup
版本:2.3.2
注意:可能依赖perl-DBD-mysql
安装:yum -y localinstall percona-xtrabackup-2.3.2-1.el6.i686.rpm
一:授权
MariaDB [mysql]> grant reload,lock tables,replication client on *.* to ‘bkuser‘@‘localhost‘; Query OK, 0 rows affected (0.01 sec) MariaDB [mysql]> flush privileges;Query OK, 0 rows affected (0.00 sec)
二:完全备份
innobackupex --user=bkuser --password=123 /backup
151126 20:45:20 >> log scanned up to (64328555) 151126 20:45:21 Executing UNLOCK TABLES151126 20:45:21 All tables unlocked151126 20:45:21 Backup created in directory ‘/backup/2015-11-26_20-45-09‘MySQL binlog position: filename ‘mysql-bin.000016‘, position ‘202526‘, GTID of the last change ‘0-1-47174‘151126 20:45:21 [00] Writing backup-my.cnf151126 20:45:21 [00] ...done151126 20:45:21 [00] Writing xtrabackup_info151126 20:45:21 [00] ...donextrabackup: Transaction log of lsn (64327671) to (64328555) was copied.151126 20:45:21 completed OK!
三,增量备份
--incremental-basedir后面跟的是上一次完全备份或者增量备份的目录地址
innobackupex --user=bkuser --password=123 --incremental /backup/ --incremental-basedir=/backup/2015-11-26_20-45-09/
四、二进制日志备份
遇到灾难后,需备份二进制文件
cat /backup/2015-11-26_20-56-09/xtrabackup_binlog_info
里有数字,即增量备份到的位置,从此位置可以做二进制备份,知道误操作之前的备份结束
mysqlbinlog --start-position=232981 --stop-position=289768 /mydata/data/mysql-bin.000016 > /backup/zuihou.sql
五、合并完全跟增量操作
查看是完全备份还是增量备份的依据,进入备份目录
[root@nod1 2015-11-26_20-45-09]# cat xtrabackup_checkpoints backup_type = full-backuped from_lsn = 0 to_lsn = 64328555 last_lsn = 64328555 compact = 0 recover_binlog_info = 0
backup_type决定
innobackupex --apply-log --redo-only /backup/2015-11-26_20-45-09/ 完全备份合并 innobackupex --apply-log --redo-only /backup/2015-11-26_20-45-09/ --incremental-dir=/backup/2015-11-26_20-56-09 增量备份合并
六,基于安全考虑,禁止网络访问数据库
/etc/my.cnf加入这两项
[mysqld] --skip-networking --socket=/tmp/mysql-recovery.sock
恢复后删除即可
七、恢复,文件完全损坏后
innobackupex --copy-back 2015-11-26_20-45-09/
chown -R mysql:mysql ./* 恢复后的文件权限修改回来
八、还原二进制日志
mysql> set session sql_log_bin=0; 关闭二进制日志功能,恢复后 打开即可 mysql> source /backup/zuihou.sql; mysql> set session sql_log_bin=1
还原后注意再继续完全备份一次
本文出自 “学无止境” 博客,请务必保留此出处http://chickengg.blog.51cto.com/10402610/1717236
标签:备份 还原 xtrabackup
原文地址:http://chickengg.blog.51cto.com/10402610/1717236