MySQL backup database, import data sql

Source: Internet
Author: User
Tags create directory mysql backup mysql backup database

#!/bin/bash

#


#set-X



Sql=/home/scripts

Dbuser=root

dbpasswd=yzg1314520

nowtime=$ (Date +%y%m%d%h%m)

Serverlist= ' Cat/home/serverlist | awk ' {print $} '


Sql_tar_export ()

{

CD $sql/$P/mysqlbak

MYSQLDUMP-U$DBUSER-P$DBPASSWD $dbname-R test > $nowtime. test.sql

TAR-ZCF $nowtime. test.Full.tar.gz $nowtime. Test.sql

RM-RF $nowtime. Test.sql

}


Sql_tar_output ()

{

CD $sql/$P/mysqlbak

Mysql-u$dbroot-p$dbpasswd-e ' drop database test '

MYSQL-U$DBROOT-P$DBPASSWD-E ' CREATE DATABASE test '

Tar zxvf $nowtime. test.Full.tar.gz

MYSQL-U$DBUSER-P$DBPASSWD Test < $nowtime. test.sql




}

Case "$" in

8[0-9][0-9][0-9]|all)

;;


Esac


Case "$" in

Export|output)

;;

Esac


Port=$1



If ["$port"! = "All"];

Then

CD $sql/$port/mysqlbak

MYSQLDUMP-U$DBUSER-P$DBPASSWD $dbname-R test > $nowtime. test.sql

TAR-ZCF $nowtime. test.Full.tar.gz $nowtime. Test.sql

RM-RF $nowtime. Test.sql



elif ["$port" = "All"];

Then

For P in $serverlist

Do

If [-D $sql/$P/mysqlbak];

Then

echo "Directory exist"

Else

echo "Not is a directory,please mkdir Directory"

mkdir $sql/$P/mysqlbak

if [$ = = 0] && [-D $sql/$P/mysqlbak];

Then

echo "Create Directory Success"

Fi

Fi


cd/$sql/$P/mysqlbak

Case "$" in

Export

Sql_tar_export

;;

Output

Sql_tar_output

;;



Esac

Done

Fi



Exit 0


#set +x


MySQL backup database, import data sql

Related Article

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.