ITPub博客

首页 > 数据库 > MySQL > 使用xtrabackup对mysql进行备份和恢复

使用xtrabackup对mysql进行备份和恢复

原创 MySQL 作者:db_wjw 时间:2015-07-01 16:52:35 0 删除 编辑
使用xtrabackup对mysql进行备份:

安装xtrabackup:
# rpm -ivh percona-release-0.0-1.x86_64.rpm
# yum install percona-xtrabackup

1、创建备份用户及赋予相关权限
mysql -u root -p
create user 'bkpuser'@'localhost' identified by 'bkpuser';
grant reload,lock tables,replication client on *.* to 'bkpuser'@'localhost';
flush privileges;

2、创建备份目录
# mkdir -p /mysql_backup
# chown -R mysql:mysql /mysql_backup

3、全量备份及恢复:
create:
$ innobackupex --user=bkpuser --password=bkpuser /mysql_backup
prepare:
$ innobackupex --apply-log --use-memory=1G /mysql_backup/2015-05-27_15-20-49
restore:
$ service mysql stop
$ rm -rf /var/lib/mysql/*
$ innobackupex --copy-back /mysql_backup/2015-05-27_15-20-49
$ chown -R mysql:mysql /var/lib/mysql


4、全量备份、增量备份及恢复:
create:
$ innobackupex --user=bkpuser --password=bkpuser /mysql_backup
$ innobackupex --user=bkpuser --password=bkpuser --incremental /mysql_backup --incremental-basedir=/mysql_backup/2015-05-27_16-45-43
$ innobackupex --user=bkpuser --password=bkpuser --incremental /mysql_backup --incremental-basedir=/mysql_backup/2015-05-27_16-48-18
$ innobackupex --user=bkpuser --password=bkpuser --incremental /mysql_backup --incremental-basedir=/mysql_backup/2015-05-27_16-50-45

prepare:
innobackupex --apply-log --redo-only --use-memory=1G /mysql_backup/2015-05-27_16-45-43
innobackupex --apply-log --redo-only --use-memory=1G /mysql_backup/2015-05-27_16-45-43 --incremental-dir=/mysql_backup/2015-05-27_16-48-18
innobackupex --apply-log --redo-only --use-memory=1G /mysql_backup/2015-05-27_16-45-43 --incremental-dir=/mysql_backup/2015-05-27_16-50-45
innobackupex --apply-log --use-memory=1G /mysql_backup/2015-05-27_16-45-43 --incremental-dir=/mysql_backup/2015-05-27_16-52-38
innobackupex --apply-log --use-memory=1G /mysql_backup/2015-05-27_16-45-43

restore:
$ service mysql stop
$ rm -rf /var/lib/mysql/*
$ innobackupex --copy-back /mysql_backup/2015-05-27_16-45-43
$ chown -R mysql:mysql /var/lib/mysql

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26194851/viewspace-1719245/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-08-21

  • 博文量
    96
  • 访问量
    452073