function main { # 参数检查 # 如果当前脚本在执行时传递了参数,则优先级高于当前脚本文件中变量的默认设置 if [ -n "$1" ]; then DB_NAME=$1 else if [ ! "$DB_NAME" ]; then read -p "请输入要备份的数据库名称:" dbname DB_NAME=$dbname fi fi
# 检查备份目录是否存在 if [ ! -d "$DUMP_FILE_PATH" ]; then mkdir -p $DUMP_FILE_PATH if [ "$?" -ne "0" ]; then echo -en "无法创建备份文件目录:$DUMP_FILE_PATH" exit 1 fi fi
# 操作开始 OLD_IFS="$IFS" IFS="," arr=($DB_NAME) IFS="$OLD_IFS" for db in${arr[@]} do # echo "$db" doDump $db done }