基于percona xtrabackup的innobackupex如何實(shí)現(xiàn)基于時(shí)間點(diǎn)數(shù)據(jù)庫(kù)恢復(fù),很多新手對(duì)此不是很清楚,為了幫助大家解決這個(gè)難題,下面小編將為大家詳細(xì)講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
成都創(chuàng)新互聯(lián)公司主要從事成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)銀州,十年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):18982081108
數(shù)據(jù)庫(kù)在運(yùn)行期間,可能是因?yàn)槿藶樵蛘`操作或者出現(xiàn)存儲(chǔ)故障,導(dǎo)致某些表不能正常訪問,此時(shí),可以使用基于時(shí)間點(diǎn)的恢復(fù),采用數(shù)據(jù)庫(kù)備份及二進(jìn)制日志,把誤操作或出現(xiàn)故障的數(shù)據(jù)還原回來,建議不要在生產(chǎn)系統(tǒng)中進(jìn)行基于時(shí)間點(diǎn)的恢復(fù),可以在一個(gè)臨時(shí)的環(huán)境把數(shù)據(jù)恢復(fù)出來,然后讓業(yè)務(wù)及開發(fā)確認(rèn),然后再把數(shù)據(jù)導(dǎo)回到生產(chǎn)數(shù)據(jù)庫(kù),這樣也不影響數(shù)據(jù)庫(kù)中其它業(yè)務(wù)的運(yùn)行。
1,數(shù)據(jù)庫(kù)的當(dāng)前數(shù)據(jù)庫(kù)
MySQL> select * from zxydb.t_go;
+----+------+
| a | b |
+----+------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 5 | 5 |
| 8 | 8 |
| 10 | 10 |
| 11 | 11 |
| 12 | 12 |
+----+------+
8 rows in set (0.00 sec)
2,構(gòu)建數(shù)據(jù)庫(kù)的基準(zhǔn)備份
--構(gòu)建存儲(chǔ)數(shù)據(jù)庫(kù)基準(zhǔn)備份的目錄
[root@standbygtid mysql]# mkdir -p /database_base_dir
[root@standbygtid mysql]# innobackupex -uroot -psystem /database_base_dir --no-timestamp
[root@standbygtid mysql]# cd /database_base_dir/
[root@standbygtid database_base_dir]# ll
總用量 77868
-rw-r----- 1 root root 418 11月 5 00:56 backup-my.cnf
drwxr-x--- 2 root root 4096 11月 5 00:56 completedb
-rw-r----- 1 root root 79691776 11月 5 00:56 ibdata1
drwxr-x--- 2 root root 4096 11月 5 00:56 mysql
drwxr-x--- 2 root root 4096 11月 5 00:56 performance_schema
drwxr-x--- 2 root root 4096 11月 5 00:56 test
-rw-r----- 1 root root 18 11月 5 00:56 xtrabackup_binlog_info
-rw-r----- 1 root root 115 11月 5 00:56 xtrabackup_checkpoints
-rw-r----- 1 root root 507 11月 5 00:56 xtrabackup_info
-rw-r----- 1 root root 2560 11月 5 00:56 xtrabackup_logfile
drwxr-x--- 2 root root 4096 11月 5 00:56 zxydb
3,準(zhǔn)備用于恢復(fù)上述的基準(zhǔn)備份
(注:其實(shí)就是用在線日志應(yīng)用到基準(zhǔn)備份,確保數(shù)據(jù)一致性)
[root@standbygtid database_base_dir]# innobackupex -uroot -psystem --apply-log /database_base_dir
[root@standbygtid database_base_dir]# ll
總用量 196652
-rw-r----- 1 root root 418 11月 5 00:56 backup-my.cnf
drwxr-x--- 2 root root 4096 11月 5 00:56 completedb
-rw-r----- 1 root root 79691776 11月 5 01:01 ibdata1
-rw-r----- 1 root root 50331648 11月 5 01:01 ib_logfile0
-rw-r----- 1 root root 50331648 11月 5 01:01 ib_logfile1
-rw-r----- 1 root root 12582912 11月 5 01:01 ibtmp1
drwxr-x--- 2 root root 4096 11月 5 00:56 mysql
drwxr-x--- 2 root root 4096 11月 5 00:56 performance_schema
drwxr-x--- 2 root root 4096 11月 5 00:56 test
-rw-r----- 1 root root 18 11月 5 00:56 xtrabackup_binlog_info
-rw-r--r-- 1 root root 19 11月 5 01:01 xtrabackup_binlog_pos_innodb
-rw-r----- 1 root root 115 11月 5 01:01 xtrabackup_checkpoints
-rw-r----- 1 root root 507 11月 5 00:56 xtrabackup_info
-rw-r----- 1 root root 8388608 11月 5 01:01 xtrabackup_logfile
drwxr-x--- 2 root root 4096 11月 5 00:56 zxydb
4,查看上述基準(zhǔn)備份對(duì)應(yīng)的二進(jìn)制日志及位置
(注:如下基于時(shí)間點(diǎn)恢復(fù)就是從這個(gè)二進(jìn)制日志及位置開始恢復(fù)到某個(gè)時(shí)間點(diǎn),很重要喲)
[root@standbygtid database_base_dir]# more xtrabackup_binlog_info
binlog.000001120
[root@standbygtid database_base_dir]#
5,為了更好模擬基于時(shí)間點(diǎn)恢復(fù),切換二進(jìn)制日志,產(chǎn)生新的二進(jìn)制日志
mysql> flush logs;
Query OK, 0 rows affected (0.01 sec)
6,查看當(dāng)前的二進(jìn)制日志及位置
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000002 | 337 | | | |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
--共計(jì)2個(gè)二進(jìn)制日志
mysql> show binary logs;
+---------------+-----------+
| Log_name | File_size |
+---------------+-----------+
| binlog.000001 | 164 |
| binlog.000002 | 337 |
+---------------+-----------+
2 rows in set (0.00 sec)
7,產(chǎn)生數(shù)據(jù)變更
mysql> use zxydb;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from t_go;
+----+------+
| a | b |
+----+------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 5 | 5 |
| 8 | 8 |
| 10 | 10 |
| 11 | 11 |
| 12 | 12 |
+----+------+
8 rows in set (0.00 sec)
mysql> insert into t_go select 13,13;
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
8,查看當(dāng)前二進(jìn)制日志對(duì)應(yīng)的事件信息
mysql> show binlog events in 'binlog.000002';
+---------------+-----+-------------+-----------+-------------+----------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+---------------+-----+-------------+-----------+-------------+----------------------------------------------------------------------+
| binlog.000002 | 4 | Format_desc | 1 | 120 | Server ver: 5.6.25-enterprise-commercial-advanced-log, Binlog ver: 4 |
| binlog.000002 | 120 | Query | 1 | 201 | BEGIN |
| binlog.000002 | 201 | Query | 1 | 306 | use `zxydb`; insert into t_go select 13,13 |
| binlog.000002 | 306 | Xid | 1 | 337 | COMMIT /* xid=41 */ |
+---------------+-----+-------------+-----------+-------------+----------------------------------------------------------------------+
4 rows in set (0.00 sec)
9,繼續(xù)變化數(shù)據(jù)
mysql> insert into t_go select 18,18;
Query OK, 1 row affected (0.02 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> show binlog events in 'binlog.000002';
+---------------+-----+-------------+-----------+-------------+----------------------------------------------------------------------+
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
+---------------+-----+-------------+-----------+-------------+----------------------------------------------------------------------+
| binlog.000002 | 4 | Format_desc | 1 | 120 | Server ver: 5.6.25-enterprise-commercial-advanced-log, Binlog ver: 4 |
| binlog.000002 | 120 | Query | 1 | 201 | BEGIN |
| binlog.000002 | 201 | Query | 1 | 306 | use `zxydb`; insert into t_go select 13,13 |
| binlog.000002 | 306 | Xid | 1 | 337 | COMMIT /* xid=41 */ |
| binlog.000002 | 337 | Query | 1 | 418 | BEGIN |
| binlog.000002 | 418 | Query | 1 | 523 | use `zxydb`; insert into t_go select 18,18 |
| binlog.000002 | 523 | Xid | 1 | 554 | COMMIT /* xid=48 */ |
+---------------+-----+-------------+-----------+-------------+----------------------------------------------------------------------+
7 rows in set (0.00 sec)
10,因?yàn)榛跁r(shí)間點(diǎn)恢復(fù)要用于二進(jìn)制日志,備份下述的二進(jìn)制文件到另一個(gè)目錄
(注:即使二進(jìn)制日志非常重要,一定要定期進(jìn)行備份,不然真要進(jìn)行基于時(shí)間點(diǎn)恢復(fù),而所需要的二進(jìn)制日志又沒有了,哪就會(huì)導(dǎo)致數(shù)據(jù)損失了)
[root@standbygtid database_base_dir]# cd /var/lib/mysql
[root@standbygtid mysql]# ll
總用量 188464
-rw-rw---- 1 mysql mysql 56 11月 4 23:52 auto.cnf
-rw-rw---- 1 mysql mysql 164 11月 5 01:06 binlog.000001
-rw-rw---- 1 mysql mysql 554 11月 5 01:12 binlog.000002
-rw-rw---- 1 mysql mysql 32 11月 5 01:06 binlog.index
drwxr-x--- 2 mysql mysql 4096 11月 4 23:48 completedb
-rw-r----- 1 mysql mysql 79691776 11月 5 01:12 ibdata1
-rw-r----- 1 mysql mysql 50331648 11月 5 01:12 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 11月 4 23:48 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 11月 4 23:48 ibtmp1
drwxr-x--- 2 mysql mysql 4096 11月 4 23:48 mysql
srwxrwxrwx 1 mysql mysql 0 11月 4 23:52 mysql.sock
-rw------- 1 root root 159 11月 4 23:52 nohup.out
drwxr-x--- 2 mysql mysql 4096 11月 4 23:48 performance_schema
-rw-r----- 1 mysql root 2508 11月 4 23:52 standbygtid.err
-rw-rw---- 1 mysql mysql 6 11月 4 23:52 standbygtid.pid
drwxr-x--- 2 mysql mysql 4096 11月 4 23:48 test
drwxr-x--- 2 mysql mysql 4096 11月 4 23:48 zxydb
[root@standbygtid mysql]# mysqlbinlog binlog.000001 binlog.000002 --start-position=120 --stop-position=337 > /base_binlog_pos.sql
[root@standbygtid mysql]#
11,關(guān)閉數(shù)據(jù)庫(kù)
mysqladmin -uroot -psystem shutdown
12,物理刪除數(shù)據(jù)文件
[root@standbygtid mysql]# pwd
/var/lib/mysql
[root@standbygtid mysql]# rm -rf *
13,還原上述的備份到數(shù)據(jù)庫(kù)的數(shù)據(jù)文件目錄
[root@standbygtid mysql]# innobackupex --datadir=/var/lib/mysql --copy-back /database_base_dir
14,授權(quán)數(shù)據(jù)庫(kù)的數(shù)據(jù)文件目錄
[root@standbygtid mysql]# chown -Rf mysql:mysql *
[root@standbygtid mysql]# ll
總用量 188448
drwxr-x--- 2 mysql mysql 4096 11月 5 01:49 completedb
-rw-r----- 1 mysql mysql 79691776 11月 5 01:49 ibdata1
-rw-r----- 1 mysql mysql 50331648 11月 5 01:49 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 11月 5 01:49 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 11月 5 01:49 ibtmp1
drwxr-x--- 2 mysql mysql 4096 11月 5 01:49 mysql
drwxr-x--- 2 mysql mysql 4096 11月 5 01:49 performance_schema
drwxr-x--- 2 mysql mysql 4096 11月 5 01:49 test
-rw-r----- 1 mysql mysql 19 11月 5 01:49 xtrabackup_binlog_pos_innodb
-rw-r----- 1 mysql mysql 507 11月 5 01:49 xtrabackup_info
drwxr-x--- 2 mysql mysql 4096 11月 5 01:49 zxydb
15,刪除上述與xtrabackup相關(guān)的文件
[root@standbygtid mysql]# rm -rf xtrabackup_*
16,重啟數(shù)據(jù)庫(kù)
[root@standbygtid mysql]# nohup mysqld_safe --user=mysql&
17,基于時(shí)間點(diǎn)恢復(fù)
(注:我們就恢復(fù)到二進(jìn)制日志的 337,見上述的第9步)
[root@standbygtid mysql]# mysql -uroot -psystem < /base_binlog_pos.sql
Warning: Using a password on the command line interface can be insecure.
[root@standbygtid mysql]#
mysql> select * from zxydb.t_go;
+----+------+
| a | b |
+----+------+
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 5 | 5 |
| 8 | 8 |
| 10 | 10 |
| 11 | 11 |
| 12 | 12 |
| 13 | 13 |
+----+------+
9 rows in set (0.00 sec)
看完上述內(nèi)容是否對(duì)您有幫助呢?如果還想對(duì)相關(guān)知識(shí)有進(jìn)一步的了解或閱讀更多相關(guān)文章,請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝您對(duì)創(chuàng)新互聯(lián)的支持。
文章標(biāo)題:基于perconaxtrabackup的innobackupex如何實(shí)現(xiàn)基于時(shí)間點(diǎn)數(shù)據(jù)庫(kù)恢復(fù)
網(wǎng)頁URL:http://chinadenli.net/article32/jsidpc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站、網(wǎng)站策劃、標(biāo)簽優(yōu)化、搜索引擎優(yōu)化、網(wǎng)站收錄、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)