337 views
Linux-shell脚本

mysql备份if判断

使用if条件判断

[code]

#!/bin/bash

#2017年8月15日08:47:10

#Backup Mysql databases

#By ying

BACKUP_DIR=/mysql_backup

#判断目录是否存在

if [ ! -d $BACKUP_DIR ];then

mkdir -p $BACKUP_DIR

fi

#备份策略

mysql -e “show databases;”

read -p “Do you want to back up one database or all databases?[one/all]:” BASES

if [ “$BASES” == “one” ];then

read -p “Which database do you want to back up?” BASE

mysqldump –events $BASE > $BACKUP_DIR/$BASE.sql

elif [ “$BASES” == “all” ];then

mysqldump –events –all-databases > $BACKUP_DIR/all.sql

else

echo “Only one or all inputs can be entered. This operation failed!”

fi

[/code]

Leave a Reply

影子专属博客 赣ICP备17013143号