使用xtrabackup對mysql進行備份和恢復

db_wjw發表於2015-07-01
使用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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章