近期公司有一個(gè)數(shù)據(jù)庫需要遷移,但是里面創(chuàng)建的數(shù)據(jù)庫比較多,我們采取腳本將庫單獨(dú)備份,然后上傳到另一臺主機(jī),新建數(shù)據(jù)庫,然后恢復(fù)數(shù)據(jù)庫。將自己寫的幾個(gè)小腳本粘貼到此,
創(chuàng)新互聯(lián)建站是一家集網(wǎng)站建設(shè),市北企業(yè)網(wǎng)站建設(shè),市北品牌網(wǎng)站建設(shè),網(wǎng)站定制,市北網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,市北網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
分庫壓縮備份
#/bin/sh #version 0.1 MYUSER=MySQLback MYPASS=databack@162.com #SOCKET=/data/3306/mysql.sock MYLOGIN="mysql -u$MYUSER -p$MYPASS " MYDUMP="mysqldump -u$MYUSER -p$MYPASS -B" DATABASE="$($MYLOGIN -e "show databases;"|egrep -vi "Data|_schema|mysql")" #正則 for dbname in $DATABASE do MYDIR=/data/backup/$dbname [ ! -d $MYDIR ] && mkdir -p $MYDIR $MYDUMP $dbname|gzip >$MYDIR/${dbname}_$(date +%F).sql.gz done
批量解壓縮
#/bin/bash for i in `ls *.gz` do gunzip $i done 解壓結(jié)果: wl_smsgate_2017-04-12.sql wl_smsgate_hx_2017-04-12.sql wl_smsgate_ldkj_2017-04-12.sql wl_smsgate_tt_2017-04-12.sql wl_smsgate_dg_2017-04-12.sql wl_smsgate_jjbs_2017-04-12.sql wl_smsgate_pc_2017-04-12.sql wl_smsgate_tt_lt_2017-04-12.sql wl_smsgate_dxfj_2017-04-12.sql wl_smsgate_jl_2017-04-12.sql wl_smsgate_sb_2017-04-12.sql
批量創(chuàng)建數(shù)據(jù)庫
#/bin/bash #fun create database mysqluser=root mysqlpass=winnerlook123 mysqlcent="mysql -u $mysqluser -p$mysqlpass" dabasename=`cat databasename` date2="_2017-04-12.sql" for data in $dabasename do $mysqlcent -e "create database if not exists $data default character set utf8" done
恢復(fù)數(shù)據(jù)
#/bin/bash #fun create database mysqluser=root mysqlpass=winnerlook123 mysqlcent="mysql -u $mysqluser -p$mysqlpass" dabasename=`cat databasename` date2="_2017-04-12.sql" for data in $dabasename do $mysqlcent -e "use $data " && $mysqlcent -e " source /tmp/backup/$data$date2 "#恢復(fù)數(shù)據(jù) done
然后檢查數(shù)據(jù)庫的數(shù)據(jù)字符集以及其數(shù)據(jù)條數(shù)。