自动备份数据库脚本

自动备份数据库

#!/bin/bash
read -p "Please enter username:" USER
read -p "Passwd:" -s PASSWD
mysql -u$USER -p$PASSWD -e "SHOW DATABASES;" &>/dev/null
if [ "$?" != "0" ]
then 
    echo -e "\nwhat you written is wrong"
    exit
else    
    mysql -u$USER -p$PASSWD -e "SHOWDATABASES;"  #用user用户登录,密码是passwd
    read -p "Please enter the file what you want to copy:"  DBNAME 
    read -p "Please give a path(/XXX/XXX.sql):"  DCH   

mysqldump -u$USER -p$PASSWD $DBNAME > $DCH
fi
if [ "$?" = "0" ]
then
    echo "finished"
else
    echo "fail"
fi

你可能感兴趣的:(自动备份数据库脚本)