用的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 <