shell脚本之 备份mysql数据库

简单的备份mysql中的数据库,并上传到ftp服务器上

[root@zhu2 ~]# vim mysql_backup.sh
#!/usr/bin/bash
USERNAME=root
PASSWORD=123456
DATE=`date +%F`
OLDDATE=`date +%F -d '-20 days'`
FTPOLDDATE=`date +%F -d '-30 days'`
MYSQL=/opt/mysql/bin/mysql
MYSQLDUMP=/opt/mysql/bin/mysqldump
BACKDIR=/data_backup
[ -d ${BACKDIR} ] || mkdir -p ${BACKDIR}
[ -d ${BACKDIR}/${DATE} ] || mkdir ${BACKDIR}/${DATE}
[ ! -d ${BACKDIR}/${OLDDATE} ] || rm -rf ${BACKDIR}/${OLDDATE}
for DBNAME in mysql zabbix zhujiangtao
do
echo "${DBNAME} has been backup successfully"
done
FTP_SERVER=192.168.70.137
FTP_USER=zabbix
FTP_PASSWORD=zabbix
cd ${BACKDIR}/${DATE}
/usr/bin/ftp -i -n -v  <<EOF
open ${FTP_SERVER}
user ${FTP_USER} ${FTP_PASSWORD}
bin
cd ${FTPOLDDATE}
mdelete *
cd ..
rmdir ${FTPOLDDATE}
mkdir ${DATE}
cd ${DATE}
mput *
bye
EOF
echo "the backup of mysql has been successfully"
#ftp参数说明
-i:关闭多个文件传输时的交互提示信息
-n :关闭自动登录
-v :显示远程服务器的响应信息

本文出自 “浪淘沙” 博客,谢绝转载!

你可能感兴趣的:(mysql,数据库,FTP服务器)