数据库备份+FTP上传脚本

用的lftp上传,先安装下lftp(yum -y install lftp)

 

#!/bin/bash
#author:[email protected]

USERNAME=XXX
PASSWORD=XXX
DATE=`date +%Y-%m-%d-%H`
OLDDATE=`date +%Y-%m-%d -d '-20 days'`
FTPOLDDATE=`date +%Y-%m-%d -d '-60 days'`
MYSQL=/usr/local/mysql/bin/mysql
MYSQLDUMP=/usr/local/mysql/bin/mysqldump
SOCKET=/tmp/mysql.sock
BACKDIR=/data/backup
HOST=10.1.134.129 
FTP_USER=XXX 
FTP_PASS=XXX 
FTP_PORT=2221
[ -d ${BACKDIR} ] ||mkdir -p ${BACKDIR}
[ -d ${BACKDIR}/${DATE} ] ||mkdir -p  ${BACKDIR}/${DATE}
[ -d ${BACKDIR}/${OLDDATE} ] &&  rm -rf ${BACKDIR}/${OLDDATE}

for DBNAME in mysql gtaoam 
do
    ${MYSQLDUMP} --opt -u${USERNAME} -p${PASSWORD} -S${SOCKET} ${DBNAME} -R \
     > ${BACKDIR}/${DATE}/${DBNAME}_BACKUP_${DATE}.sql
    echo "${DBNAME} has been backup successful"
done

cd ${BACKDIR}/${DATE}
lftp < 

Comments

No comments yet. Why don’t you start the discussion?

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注