SHELL 自动备份MySQL数据库
创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、成都网站设计、奉化网络推广、小程序设计、奉化网络营销、奉化企业策划、奉化品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供奉化建站搭建服务,24小时服务热线:028-86922220,官方网址:www.cdcxhl.com
备份单个数据库及所有数据库
楓城浪子原创,转载请标明出处!
更多技术博文请见个人博客:https://fengchenglangzi.000webhostapp.com
微信bh29890922
QQ445718526、490425557
部分截图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| #!/bin/bash
#2017-8-16 08:58:22
#By baiyuanhong
#Auto_Backup_Mysql
###############################################
MYSQL_STATUS=`netstat -anpl |grep mysqld | grep 3306 | wc -l`
###############################################
###############################################
#system base info
IPADD=`ifconfig eth0 | grep "inet addr" | awk '{print $2}' | sed 's/addr://g'`
HOSTNAME=`hostname`
DATE=`date +"%y-%m-%d %H:%M:%S"`
USER=`whoami`
DISK_SDA1=`df -h | grep /dev/sda1 | awk '{print $5}'`
CPU_INFO=`cat /proc/loadavg`
###############################################
###############################################
#status_check
echo -e "\033[32m********************************************\033[0m"
if [ $MYSQL_STATUS -eq 0 ];then
echo "Mysql..............................[NOT RUN]"
else
echo "Mysql..............................[RUNNING]"
fi
echo -e "\033[32m********************************************\033[0m"
cat << EOF
|------------System Information-------------
|DATE :$DATE
|HOSTNAME :$HOSTNAME
|USER :$USER
|IP :$IPADD
|DISK_USED :$DISK_SDA1
|CPU_AVERAGE :$CPU_INFO
--------------------------------------------
EOF
echo -e "\033[32m*******Please Enter Your Choice:[1-3]******\033[0m"
cat << EOF
1)Backup Single Mysql DB
2)Backup All Mysql DB
3)exit
--------------------------------------------
EOF
read -p "Please Enter Your Choice:" input
#############################################
#############################################
if [ $input -eq 1 ];then
mysql -uroot -p123456 -e "show databases;"
read -p "Please Enter Your DBname:" DBname
mysqldump -uroot -p123456 $DBname >/tmp/$DBname\_`date +%Y%m%d`.sql
fi
if [ $input -eq 2 ];then
mysql -uroot -p123456 -e "show databases;"
read -p "Please Confirm Your Choice(y/n):" yn
if [ $yn == "y" ];then
mysqldump -uroot -p123456 --all-databases >/tmp/all_databases_`date +%Y%m%d`.sql
else
exit
fi
fi
if [ $input -eq 3 ];then
exit
fi |
当前文章:SHELL自动备份MYSQL数据库(备份单个数据库及所有数据库)
文章链接:
http://cdkjz.cn/article/gephhs.html