标签:rom start one stop bak database .com myisam rpm
mysql:5.6.29
xtrabackup:2.2.10
mysql数据目录:/data/mysql
mysql备份目录:/data/dbbak/ #确保有足够的磁盘空间
官方文档:https://www.percona.com/doc/percona-xtrabackup/2.2/innobackupex/incremental_backups_innobackupex.html
1、安装依赖
yum -y install libaio perl-Time-HiRes perl-DBD-MySQL perl-IO-Socket-SSL rsync.x86_64
2、安装xtrabackup
rpm -ivh percona-xtrabackup-2.2.10-1.el6.x86_64.rpm
3、在数据库创建备份账号
mysql> CREATE USER ‘bkpuser‘@‘localhost‘ IDENTIFIED BY ‘s3cret‘; mysql> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT,Process ON *.* TO ‘bkpuser‘@‘localhost‘; mysql> FLUSH PRIVILEGES;
4、初始化验证数据
CREATE DATABASE if not EXISTS test /*!40100 DEFAULT CHARACTER SET utf8mb4 */; use test; drop table if EXISTS myisam_table; CREATE TABLE myisam_table ( id int NOT NULL AUTO_INCREMENT, column1 varchar(30), column2 varchar(30), PRIMARY KEY (`id`) ) ENGINE=MyISAM; drop table if EXISTS innodb_table; CREATE TABLE innodb_table ( id int NOT NULL AUTO_INCREMENT, column1 varchar(30), column2 varchar(30), PRIMARY KEY (`id`) ) ENGINE=INNODB; insert into myisam_table values (null,‘完整备份‘,‘完整备份‘); insert into innodb_table values (null,‘完整备份‘,‘完整备份‘);
5、完整备份
innobackupex --user=bkpuser --password=s3cret /data/dbbak/full --no-timestamp --defaults-file=/etc/my.cnf
第一次增量备份
insert into myisam_table values (null,‘增量备份1‘,‘增量备份1‘);
insert into innodb_table values (null,‘增量备份1‘,‘增量备份1‘);
innobackupex --user=bkpuser --password=s3cret /data/dbbak/incre1 --incremental --incremental-basedir=/data/dbbak/full --no-timestamp --defaults-file=/etc/my.cnf
第二次增量备份
insert into myisam_table values (null,‘增量备份2‘,‘增量备份2‘); insert into innodb_table values (null,‘增量备份2‘,‘增量备份2‘); innobackupex --user=bkpuser --password=s3cret /data/dbbak/incre2 --incremental --incremental-basedir=/data/dbbak/incre1 --no-timestamp --defaults-file=/etc/my.cnf
6、还原
合并所有增量备份至完整备份
innobackupex --apply-log --redo-only /data/dbbak/full innobackupex --apply-log --redo-only /data/dbbak/full --incremental-dir=/data/dbbak/incre1 innobackupex --apply-log /data/dbbak/full --incremental-dir=/data/dbbak/incre2 最后一次增量备份,不需要添加--redo-only Note --redo-only should be used when merging all incrementals except the last one. That’s why the previous line doesn’t contain the --redo-only option. Even if the --redo-only was used on the last step, backup would still be consistent but in that case server would perform the rollback phase. Once you merge the base with all the increments, you can prepare it to roll back the uncommitted transactions innobackupex --apply-log /data/dbbak/full /etc/init.d/mysql.server stop mv /data/mysql /data/mysql_bak innobackupex --copy-back /data/dbbak/full chown mysql:mysql /data/mysql -R /etc/init.d/mysql.server start
7、验证数据
select * from test.myisam_table; select * from test.innodb_table;
标签:rom start one stop bak database .com myisam rpm
原文地址:http://www.cnblogs.com/dbcloud/p/6130848.html