溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

xtrabackup備份工具命令如何進(jìn)行單庫增量備份還原

發(fā)布時(shí)間:2021-09-28 11:49:05 來源:億速云 閱讀:236 作者:柒染 欄目:MySQL數(shù)據(jù)庫

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)xtrabackup備份工具命令如何進(jìn)行單庫增量備份還原,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

Innobackupex 參數(shù)解釋:

--defaults-file=[MY.CNF]該選項(xiàng)傳遞給xtrabackup子進(jìn)程,從指定文件讀取缺省選項(xiàng)

--apply-log 從備份恢復(fù)。

--redo-only 該選項(xiàng)強(qiáng)制跳過rollback階段,只進(jìn)行redo。這是有必要使用的,如果備份后,要使用增量改變的。

--copy-back 從備份目錄拷貝數(shù)據(jù)和索引文件到datadir目錄

--remote-host=HOSTNAME備份到遠(yuǎn)程主機(jī)上,使用ssh

--stream=[tar|cpio(notimplemented)] 指定備份標(biāo)準(zhǔn)輸出格式

--tmpdir=DIRECTORY默認(rèn)與tmpdir相同。使用—remote-host或—stream參數(shù)后,傳輸日志文件將存放在臨時(shí)目錄下

--use-memory=MB選項(xiàng)傳遞給xtrabackup子進(jìn)程?;謴?fù)使用內(nèi)存大小

--parallel=NUMBER-OF-THREADS選項(xiàng)傳遞給xtrabackup子進(jìn)程,指定數(shù)據(jù)傳輸線程總數(shù)。默認(rèn)為1

--throttle=IOS選項(xiàng)傳遞給xtrabackup子進(jìn)程,限制IO線程數(shù)量

--sleep=MS 選項(xiàng)傳遞給xtrabackup子進(jìn)程。每拷貝1MB數(shù)據(jù)暫停多少M(fèi)S時(shí)間

--compress[=LEVEL]選項(xiàng)傳遞給xtrabackup子進(jìn)程。壓縮級別在0-9.1快速壓縮,9最佳壓縮,0不壓縮。默認(rèn)為1.

--include=REGEXP選項(xiàng)傳遞給xtrabackup子進(jìn)程。使用正則進(jìn)行匹配

--databases=LIST指定備份數(shù)據(jù)庫

--tables-file=FILE

--uncompress選項(xiàng)傳遞給xtrabackup子進(jìn)程。對壓縮過的InnoDB數(shù)據(jù)文件不進(jìn)行壓縮

--export 僅使用于prepare選項(xiàng)。選項(xiàng)傳遞給xtrabackup子進(jìn)程。

--user=NAME

--password=WORD

--host=HOST

--port=PORT

--slave-info 備份復(fù)制從服務(wù)端,主從信息記錄在ibbackup_slave_info文件中

--socket=SOCKET

--no-timestamp不在備份根目錄下創(chuàng)建以當(dāng)前時(shí)間戳為名稱的新的備份目錄

--ibbackup=IBBACKUP-BINARYibbackup二進(jìn)制路徑

--no-lock 禁止表級鎖。全部是InnoDB引擎表和不關(guān)系二進(jìn)制日志位置下使用

--scpopt=SCP-OPTIONS指定scp參數(shù)

                                    innobackupex單庫增量恢復(fù)

[root@mini1 ~]# mkdir -p /opt/mysqlbackup/{full,inc}

#完全備份

[root@mini1 ~]# innobackupex --user=root --password=123456 --include=test /opt/mysqlbackup/full/

mysql> select * from test.t1;

+----+------+

| id | name |

+----+------+

|  1 | tom1 |

|  2 | tom1 |

+----+------+

#插入數(shù)據(jù)

mysql> insert into test.t1(name) values('tom2');

#增量備份1

[root@mini1 ~]# innobackupex --user=root --password=123456 --include=test --incremental /opt/mysqlbackup/inc/ --incremental-basedir=/opt/mysqlbackup/full/2018-07-30_20-36-57/

#插入數(shù)據(jù),添加新表

mysql> insert into test.t1(name) values('tom3');

mysql> create table test.t2(id int);

mysql> insert into test.t2 values(1);

mysql> select * from test.t2;

+------+

| id   |

+------+

|    1 |

#增量備份2

[root@mini1 ~]# innobackupex --user=root --password=123456 --include=test --incremental /opt/mysqlbackup/inc/ --incremental-basedir=/opt/mysqlbackup/inc/2018-07-30_20-47-55/

[root@mini1 ~]# ls /opt/mysqlbackup/full

2018-07-30_20-36-57

[root@mini1 ~]# ls /opt/mysqlbackup/inc/

2018-07-30_20-47-55  2018-07-30_20-51-21

#刪除數(shù)據(jù)庫

mysql> drop database test;

[root@mini1 ~]# service mysqld stop

[root@mini1 ~]# cd /opt/mysqlbackup/full/2018-07-30_20-36-57/test/

[root@mini1 test]# ls

db.opt  t1.frm  t1.ibd

[root@mini1 ~]innobackupex --apply-log --redo-only /opt/mysqlbackup/full/2018-07-30_20-34-34/

[root@mini1 ~]innobackupex --apply-log --redo-only /opt/mysqlbackup/full/2018-07-30_20-34-34/ --incremental-dir=/opt/mysqlbackup/inc/2018-07-30_20-38-12/

[root@mini1 ~]innobackupex --apply-log --redo-only /opt/mysqlbackup/full/2018-07-30_20-34-34/ --incremental-dir=/opt/mysqlbackup/inc/2018-07-30_20-42-03/

[root@mini1 ~]innobackupex --apply-log --export /opt/mysqlbackup/full/2018-07-30_20-34-34/

[root@mini1 ~]cp -rf /opt/mysqlbackup/full/2018-07-30_20-34-34/* /usr/local/mysql/data/

[root@mini1 data]# service mysqld restart 

mysql> select * from t1;

+----+------+

| id | name |

+----+------+

|  1 | tom1 |

|  2 | tom1 |

|  3 | tom1 |

|  4 | tom1 |

|  5 | tom1 |

|  6 | tom1 |

+----+------+

6 rows in set (0.00 sec)

mysql> select * from t2

    -> ;

+------+

| id   |

+------+

|    1 |

|    3 |

|    2 |

+------+

                                                          innobackupex備份多庫

[root@mini1 full]# innobackupex --user=root --password=123456 --databases="test test1" /opt/mysqlbackup/full/

xtrabackup備份單個(gè)表

[root@mini1 ~]# mkdir -p /opt/mysqlbackup/{full,inc}

[root@mini1 ~]# mysql -uroot -p123456

mysql> use test

mysql> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

| sys                |

| test               |

| test1              |

+--------------------+

mysql> select * from test.t1;

+----+------+

| id | name |

+----+------+

|  1 | tom1 |

|  2 | tom1 |

+----+------+

[root@mini1 ~]# xtrabackup --user=root --password=123456 --backup --target-dir=/opt/mysqlbackup/full/full_$(date +%F_%H%M%S) --databases="test"

mysql> insert into test.t1(name) values('tom1');

[root@mini1 ~]# xtrabackup --user=root --password=123456 --backup --target-dir=/opt/mysqlbackup/inc/inc_$(date +%F_%H%M%S) --incremental-basedir=/opt/mysqlbackup/full/full_2018-07-30_204200/ --databases='test'

mysql> insert into test.t1(name) values('tom1');

mysql> insert into test.t2(name) values('tom1');

[root@mini1 ~]# xtrabackup --user=root --password=123456 --backup --target-dir=/opt/mysqlbackup/inc/inc_$(date +%F_%H%M%S) --incremental-basedir=/opt/mysqlbackup/inc/inc_2018-07-30_205007/ --databases='test'

mysql> drop table test.t1;

mysql> delete from test.t2 where id=1;

[root@mini1 ~]# xtrabackup --prepare --apply-log-only --target-dir=/opt/mysqlbackup/full/full_2018-07-30_204200/

[root@mini1 ~]# cat /opt/mysqlbackup/full/full_2018-07-30_204200/xtrabackup_checkpoints 

backup_type = log-applied

from_lsn = 0

to_lsn = 2609032

last_lsn = 2609041

compact = 0

recover_binlog_info = 0

[root@mini1 ~]# xtrabackup --prepare --apply-log-only --target-dir=/opt/mysqlbackup/full/full_2018-07-30_204200/ --incremental-dir=/opt/mysqlbackup/inc/inc_2018-07-30_205007/

[root@mini1 ~]# xtrabackup --prepare --apply-log-only --target-dir=/opt/mysqlbackup/full/full_2018-07-30_204200/ --incremental-dir=/opt/mysqlbackup/inc/inc_2018-07-30_205157/

[root@mini1 ~]# xtrabackup --prepare --target-dir=/opt/mysqlbackup/full/full_2018-07-30_204200/

[root@mini1 ~]# cat /opt/mysqlbackup/full/full_2018-07-30_204200/xtrabackup_checkpoints 

backup_type = full-prepared

from_lsn = 0

to_lsn = 2613778

last_lsn = 2613787

compact = 0

recover_binlog_info = 0

[root@mini1 ~]# service mysqld stop 

[root@mini1 ~]# cd /opt/mysqlbackup/full/full_2018-07-30_204200/

[root@mini1 full_2018-07-30_204200]# rsync -rvt --exclude 'xtrabackup_checkpoints' --exclude 'xtrabackup_logfile' ./ /usr/local/mysql/data/

[root@mini1 full_2018-07-30_204200]# chown -R mysql:mysql /usr/local/mysql/

[root@mini1 full_2018-07-30_204200]# service mysqld start

mysql> show tables;

+----------------+

| Tables_in_test |

+----------------+

| t1             |

| t2             |

+----------------+

2 rows in set (0.00 sec)

mysql> select * from t1;

+----+------+

| id | name |

+----+------+

|  1 | tom1 |

|  2 | tom1 |

|  3 | tom1 |

|  4 | tom1 |

+----+------+

4 rows in set (0.00 sec)

mysql> select * from t2;

+----+------+

| id | name |

+----+------+

|  1 | tom1 |

|  2 | tom1 |

|  3 | tom1 |

+----+------+

3 rows in set (0.00 sec)

  xtrabackup備份多庫

[root@mini1 /]# xtrabackup --defaults-file=/etc/my.cnf --user=root --password=123456 --backup --target-dir=/opt/mysqlbackup/full/3 --databases='test test1'

mysql> insert into test.t1(name) values('tom1');

上述就是小編為大家分享的xtrabackup備份工具命令如何進(jìn)行單庫增量備份還原了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI