MySQL备份脚本

#!/bin/bash

DATE=`date +%y%m%d`
DELDATE=`date -d "30 days ago" +%y%m%d`
BASEDIR=`pwd`
TMPDIR="/home"
IP="192.168.1.123"
PASSWORD="15"
cat /var/log/backup_*.txt > dbname.txt

#创建备份临时目录
mkdir -p $TMPDIR/dbbackup
cd $TMPDIR/dbbackup/

#备份数据到临时目录并分别打包
while read line
do
        mysqldump -uroot -p23425 --quick $line > $TMPDIR/dbbackup/$line.sql
        tar -zcf db-$line-$DATE.tar.gz $line.sql
done < /root/dbname.txt

#上传备份文件
ftp -nv $IP 2101 << EOF
user youkiaback "$PASSWORD"
prompt
binary
mput *-$DATE.tar.gz
mdelete *-$DELDATE.tar.gz
quit
EOF

#删除本机临时备份数据
cd $TMPDIR
if [ "$?" = "0" ]
        then
                rm -rf dbbackup
        else
                rm -rf dbbackup
fi

 

posted @ 2018-04-13 10:09  带你去土耳其  阅读(88)  评论(0编辑  收藏  举报