Bulk database creation and batch data recovery

Source: Internet
Author: User

Recently the company has a database to be migrated, but there are more databases created, we take a script to separate the library, then upload to another host, create a new database, and then restore the database. Paste a few small scripts you wrote here,

Sub-Library Compression backup

#/bin/sh#version 0.1myuser=mysqlback[email protected] #SOCKET =/data/3306/mysql.sockmylogin= "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.gzdone

Batch Decompression

#/bin/bashfor i in ' ls *.gz ' does gunzip $i done decompression result: 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.sqlwl_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_sms Gate_jl_2017-04-12.sql Wl_smsgate_sb_2017-04-12.sql

Batch database creation

#/bin/bash#fun Create databasemysqluser=rootmysqlpass=winnerlook123mysqlcent= "Mysql-u $mysqluser-p$mysqlpass"  Dabasename= ' cat databasename ' date2= "_2017-04-12.sql" for data in $dabasenamedo $mysqlcent-E "CREATE database if not exists $data default character set UTF8 "done

Recovering data

#/bin/bash#fun Create databasemysqluser=rootmysqlpass=winnerlook123mysqlcent= "Mysql-u $mysqluser-p$mysqlpass"  Dabasename= ' cat databasename ' date2= "_2017-04-12.sql" for data in $dabasenamedo $mysqlcent-E "Use $data" && $mysqlcent-E "source/tmp/backup/$data $date2" #恢复数据done

Then examine the database's data character set and its number of data bars.

This article is from the "Keep Dreaming" blog, please be sure to keep this source http://dreamlinux.blog.51cto.com/9079323/1915152

Bulk database creation and batch data recovery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.