auto_mysqldump_data.sh

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了auto_mysqldump_data.sh相关的知识,希望对你有一定的参考价值。

#!/bin/bash
#2019年10月31日22:57:25
#auto back mysql‘s database
IPADDR="10.0.0.7"
BAK_TIME=date +%F-%T
MYSQL_USER="backup"
MYSQL_PASS="123456"
MYSQL_COM1="mysqldump"
MYSQL_COM2="mysql"
SQL_DIR="/data/mysqlback/"
SQL_DBS="$*"
if [ $# -eq 0 ]; then
echo -e "33[33m-----------------------------------33[0m"
echo -e "33[31m-->{Usage:(eg:$0 jf1 | jf1 jf2 .. | all )}33[0m"
echo -e "33[33m-----------------------------------33[0m"
elif [ $1 == help ];then
echo -e "33[33m-----------------------------------33[0m"
echo -e "33[31m-->{Usage:(eg:$0 jf1 | jf1 jf2 .. | all )}33[0m"
echo -e "33[33m-----------------------------------33[0m"
fi

if [ ! -d $SQL_DIR ]; then
mkdir -p $SQL_DIR
fi

for SQL_DB in $SQL_DBS
do
$MYSQL_COM2 -h$IPADDR -u$MYSQL_USER -p$MYSQL_PASS -e "show databases" |grep "$SQL_DB"
if [ $? == 0 ];then
$MYSQL_COM1 -h$IPADDR -u$MYSQL_USER -p$MYSQL_PASS --database $SQL_DB >${SQL_DIR}${SQL_DB}-${BAK_TIME}.sql
if [ $? == 0 ];then
echo "this $SQL_DB was already backup .."
continue
else
echo -e "33[32m@You input the database is not exist..Please resume !33[0m"
exit
fi
else
if [ $SQL_DBS == all ];then
$MYSQL_COM1 -h$IPADDR -u$MYSQL_USER -p$MYSQL_PASS --all-databases >${SQL_DIR}all-${BAK_TIME}.sql
if [ $? == 0 ];then
echo "all databases was already backup .."
exit
else
echo -e "33[32m@@You input the database is not exist..Please resume !33[0m"
exit
fi
fi

fi
done

以上是关于auto_mysqldump_data.sh的主要内容,如果未能解决你的问题,请参考以下文章

代码片|水波纹

代码片--练习匿名内部类

一个简单的时间片轮转内核代码的分析(课程作业)

markdown 放代码片

代码片-下拉树实现

用java给html文件添加必要的控制html代码片