fetch_db_dumpsql.pl從mysqldump全備中恢複指定庫的資料

來源:互聯網
上載者:User

標籤:從mysqldump全備中恢複指定庫的數

解決從mysqldump全備中恢複指定庫的資料,
從全備中抽取指定資料庫(可多個)的sql,每個資料庫匯出為資料庫名命名的sql檔案
注意:mysqldump時不能包含參數 --skip-comments

[[email protected] opt]# perl fetch_db_dumpsql.pl --help=========================================================================================Info  :        Created By babaoqiUsage :Command line options :    -h, --help          Print Help Info.     -s, --srcfile       src dumpsql file    -B, --databases     fetch some databases.     -O, --outfile       output sql file. default:cur pathSample :   shell> perl fetch_db_dumpsql.pl -s=xxx.sql -B=db1   shell> perl fetch_db_dumpsql.pl -s=xxx.sql -B=db1,db2    shell> perl fetch_db_dumpsql.pl -s=xxx.sql -B=db1,db2,db3 -O=/tmp/=========================================================================================

先全備份整個MySQL資料庫

[[email protected] opt]# mysqldump -uroot -p -A -B >allbak.sqlWarning: Using a password on the command line interface can be insecure.

進行刪庫測試:

MySQL [zhangyou]> drop database zixun3;Query OK, 88 rows affected (0.07 sec)MySQL [zhangyou]> drop database zhangyou;Query OK, 88 rows affected (0.01 sec)MySQL [(none)]> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              |       || performance_schema || test001            |+--------------------+5 rows in set (0.00 sec)

從全備份的資料庫中過濾出需要恢複的資料庫的資料:

[[email protected] opt]#  perl fetch_db_dumpsql.pl -s=/opt/allbak.sql -B=zhangyou,zixun3 -O=/tmp/srcfile=/opt/allbak.sql, databases=zhangyou,zixun3, output=/tmp/ ============= start fetch zhangyou sqlszhangyou pos: 2804--5519============= start fetch zixun3 sqlszixun3 pos: 5520--8233
[[email protected] opt]# ll /tmp/zhangyou.sql -rw-r--r-- 1 root root 931528 Jun  6 16:52 /tmp/zhangyou.sql[[email protected] opt]# ll /tmp/zixun3.sql -rw-r--r-- 1 root root 14493249 Jun  6 16:52 /tmp/zixun3.sql[[email protected] opt]# 

fetch_db_dumpsql.pl從mysqldump全備中恢複指定庫的資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.