使用if条件语句编写MySQL备份脚本
#!/bin/bash #备份数据库 dir=/usr/share/nginx/html/project/ssh/backup/`date +%Y%m%d` mysqldb=test musqluser=root mysqlpwd=123456 mysqlicmd=/usr/bin/mysqldump if [ $UID -ne 0 ];then sudo su fi if [ ! -d $dir ];then mkdir -p $dir echo "create $dir now" else echo "$dir exists" fi $mysqlicmd -u$musqluser -p$mysqlpwd -d $mysqldb >$dir/$mysqldb.sql if [ $? -ef 0 ];then echo -e "\033[32mBackup Successfully!\033[0m" else echo -e "\033[32mBackup failded!\033[0m" fi
相关推荐
emmm00 2020-11-17
王艺强 2020-11-17
aydh 2020-11-12
世樹 2020-11-11
zry 2020-11-11
URML 2020-11-11
spurity 2020-11-10
yifangs 2020-10-13
Andrea0 2020-09-18
Ida 2020-09-16
ltd00 2020-09-12
tufeiax 2020-09-03
xjd0 2020-09-10
greatboylc 2020-09-10
adsadadaddadasda 2020-09-08
疯狂老司机 2020-09-08
CoderToy 2020-11-16
ribavnu 2020-11-16
bianruifeng 2020-11-16