天天看點

MySQL利用xtrabackup進行增量備份詳細過程彙總

mysql -uroot --password="" -e"create user 'backup'@'192.168.%' identified by '123456'";

mysql -uroot --password="" -e"grant reload, lock tables, replication

client, create tablespace, superon *.* to 'backup'@'192.168.%'";

備份指令:

xtrabackup --defaults-file=/etc/my.cnf--user=backup

--password="123456" --port=3306

--backup--target-dir=/data/backups/mysql/full_incre_$(date +%y%m%d)

ps: 2>/tmp/fullbackup.log 将備份資訊放入檔案中。

備份過程資訊如下:

xtrabackup --defaults-file=/etc/my.cnf--backup --user=backup

--target-dir=/data/backups/mysql/incre_20150320/--incremental-basedir=/data/backups/mysql/full_incre_201503192>/tmp/incre_backup_1.log

檢視備份日志資訊:

建立一張表t_incre_2:

--target-dir=/data/backups/mysql/incre_20150321/--incremental-basedir=/data/backups/mysql/incre_20150320

2>/tmp/incre_backup_2.log

備份資訊記錄如下:

備份指令如下:

xtrabackup --defaults-file=/etc/my.cnf--prepare --user=backup

--password="123456"

--apply-log-only--target-dir=/data/backups/mysql/full_incre_20150319

2>/tmp/full_restore.log

恢複指令:

--apply-log-only--target-dir=/data/backups/mysql/full_incre_20150319--incremental-dir=/data/backups/mysql/incre_20150320

2>/tmp/restore_incre_1.log

恢複過程:

--password="123456" --apply-log-only

--target-dir=/data/backups/mysql/full_incre_20150319--incremental-dir=/data/backups/mysql/incre_201503212>/tmp/restore_incre_2.log

--password="123456"--target-dir=/data/backups/mysql/full_incre_20150319

2>/tmp/restore_end_3.log

停止mysql服務:

service mysqld5612 stop

開始rsync資料檔案:

cd /data/backups/mysql/full_incre_20150319

rsync -rvt --exclude'xtrabackup_checkpoints' --exclude 'xtrabackup_logfile' ./ /home/data/mysql/data

授予mysql通路權限:

chown -r mysql:mysql /home/data/mysql/data

啟動mysql服務:

service mysqld5612 start

登入mysql,看到以前在備份之後删除的t4以及t_incre_2表的資料已經通過2次增量備份恢複過來了,如下所示:

指令如下:

innobackupex --defaults-file=/etc/my.cnf--user=backup

--host=192.168.52.129/data/backups/mysql/innobackupex_full_20150319/

--no-timestamp 2>/tmp/innobackupex_full.log

備份過程資訊:

先錄入增量資料

再進行增量備份,指令如下:

innobackupex

--incremental/data/backups/mysql/innobackex_incre_1--incremental-basedir=/data/backups/mysql/innobackupex_full_20150319/--user=backup

--password="123456" --host=192.168.52.129

--no-timestamp2>/tmp/innobackex_incre_1.log

先錄入增量資料錄入

開始進行第二次增量備份,備份指令:

innobackupex --incremental/data/backups/mysql/innobackex_incre_2

--incremental-basedir=/data/backups/mysql/innobackex_incre_1/--user=backup

--no-timestamp2>/tmp/innobackex_incre_2.log

innobackupex --user=backup--password="123456" --host=192.168.52.129

--apply-log/data/backups/mysql/innobackupex_full_20150319/2>/tmp/innobackex_restore_full.log

/data/backups/mysql/innobackupex_full_20150319/--incremental-dir=/data/backups/mysql/innobackex_incre_1

--apply-log2>/tmp/innobackex_restore_incre_1.log

/data/backups/mysql/innobackupex_full_20150319/--incremental-dir=/data/backups/mysql/innobackex_incre_2

--apply-log2>/tmp/innobackex_restore_incre_2.log

停止資料庫

清空資料目錄下所有檔案

mkdir -p /tmp/mysqldatabak/

mv/home/data/mysql/data/* /tmp/mysqldatabak/

将恢複好的資料按照配置檔案的需求拷貝到相應目錄

--password="123456" --host=192.168.52.129--defaults-file=/etc/my.cnf

--copy-back/data/backups/mysql/innobackupex_full_20150319/

2>/tmp/innobackex_incre_restore_end.log

賦予mysql賬号權限

啟動mysql服務

ps:--copy-back過程如下:

登入mysql界面,檢視表incre1和表incre2,資料已經恢複,如下所示:

繼續閱讀