发布网友 发布时间:2022-04-24 17:54
共2个回答
懂视网 时间:2022-05-01 00:05
#!/bin/bash
#
#set -x
sql=/home/scripts
dbuser=root
dbpasswd=yzg1314520
nowtime=$(date +%Y%m%d%H%M)
serverlist=`cat /home/serverlist | awk ‘{print $2}‘`
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 "$1" in
8[0-9][0-9][0-9]|all)
;;
esac
case "$2" 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 "$2" in
export)
sql_tar_export
;;
output)
sql_tar_output
;;
esac
done
fi
exit 0
#set +x
mysql备份数据库,导入数据sql
标签:sql
热心网友 时间:2022-04-30 21:13
附加数据库