更新一下多FTP服务器多站多数据库备份SHELL脚本

  • A+
所属分类:AMH

更新一下多FTP服务器多站多数据库备份SHELL脚本

#数据库用户名及密码
DBUSER="数据库用户名"
DBPASS="数据库密码"
#数据库名
DB1="网站1"
DB2="网站2"
DB3="网站3"
DB4="网站4"
DB5="网站5"
DB6="网站6"
DB7="网站7"
#网站文件目录及保存文件名
WEBSITE1="/www/wwwroot/网站1.Com"
WEBSITE2="/www/wwwroot/网站2.Com"
WEBSITE3="/www/wwwroot/网站3.Com"
WEBSITE4="/www/wwwroot/网站4"
WEBSITE5="/www/wwwroot/网站5"
WEBSITE6="/www/wwwroot/网站6"
WEBSITE7="/www/wwwroot/网站7"
WEBNAME1="网站1.Com"
WEBNAME2="网站2.Com"
WEBNAME3="网站3.Com"
WEBNAME4="网站4"
WEBNAME5="网站5"
WEBNAME6="网站6"
WEBNAME7="网站7"
#其他需要备份的文件及保存文件名
OTHER1="/www/server/panel/rewrite/nginx"
OTHER2="/www/server/panel/vhost/nginx"
OTHER3="/etc/letsencrypt/live"
OTHERNAME1="Rewrite"
OTHERNAME2="VHOST"
OTHERNAME3="SSL"
#FTP登录网站和用户名、密码、备份目录
#FTPSITE="FTP服务器1t";
#FTPUSER="FTP用户名";
#FTPPASS="FTP密码";
#FTPDIR="/backup";
#网站2Com登录网站和用户名、密码、备份目录
网站2Com="FTP服务器1"
STPUSER="FTP用户名"
STPPASS="FTP密码"
STPDIR="/网站2COM"
#网站1Com登录网站和用户名、密码、备份目录
网站1Com="FTP服务器1"
GTPUSER="FTP用户名"
GTPPASS="FTP密码"
GTPDIR="/网站1Com"
#网站5登录网站和用户名、密码、备份目录
网站5网站1Com="FTP服务器2"
MTPUSER="FTP用户名"
MTPPASS="FTP密码"
MTPDIR="/网站5"
#网站6登录网站和用户名、密码、备份目录
网站6="FTP服务器2"
FSFTPUSER="FTP用户名"
FSFTPPASS="FTP密码"
FSFTPDIR="/网站6"
#网站3Com登录网站和用户名、密码、备份目录
网站3Com="FTP服务器3"
AGTPUSER="FTP用户名"
AGTPPASS="FTP密码"
AGTPDIR="/网站3Com"
#网站4登录网站和用户名、密码、备份目录
网站4="FTP服务器3"
ACTPUSER="FTP用户名"
ACTPPASS="FTP密码"
ACTPDIR="/网站4"
#网站7登录网站和用户名、密码、备份目录
网站7="FTP服务器1"
FFTPUSER="FTP用户名"
FFTPPASS="FTP密码"
FFTPDIR="/网站7"
#备份文件目录
DIR="/www/backup"

#!/bin/sh
cd ${DIR}
#开始备份网站网站1.Com
#导出数据库
mysqldump -p ${DB1} -u ${DBUSER} --password=${DBPASS} | gzip > ${DB1}.sql.gz
#打包文件
tar -zcvf ${DB1}_data$(date +%Y%m%d).tar.gz ${DB1}.sql.gz
tar -zcvf ${WEBNAME1}_$(date +%Y%m%d).tar.gz ${WEBSITE1}
tar -zcvf ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHER1}
tar -zcvf ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHER2}
tar -zcvf ${OTHERNAME3}_$(date +%Y%m%d).tar.gz ${OTHER3}

#删除FTP空间15天前<a href="https://www.sxsay.com/tag/%e5%a4%87%e4%bb%bd/" title="查看与 备份 相关的文章" target="_blank">备份</a>&上传到FTP空间
ftp -v -n ${网站1Com} << EOF
user ${GTPUSER} ${GTPPASS}
type binary
cd ${GTPDIR}
delete ${DB1}_data$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${WEBNAME1}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME1}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME2}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME3}_$(date -d "15day ago" +%Y%m%d).tar.gz
put ${DB1}_data$(date +%Y%m%d).tar.gz
put ${WEBNAME1}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME1}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME2}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME3}_$(date +%Y%m%d).tar.gz
bye
EOF
#删除本地文件
cd ${DIR}
rm -rf ${DB1}.sql.gz ${DB1}_data$(date +%Y%m%d).tar.gz ${WEBNAME1}_$(date +%Y%m%d).tar.gz ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHERNAME3}_$(date +%Y%m%d).tar.gz

#开始备份网站网站2.Com
#导出数据库
mysqldump -p ${DB2} -u ${DBUSER} --password=${DBPASS} | gzip > ${DB2}.sql.gz
#打包文件
tar -zcvf ${DB2}_data$(date +%Y%m%d).tar.gz ${DB2}.sql.gz
tar -zcvf ${WEBNAME2}_$(date +%Y%m%d).tar.gz ${WEBSITE2}
tar -zcvf ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHER1}
tar -zcvf ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHER2}
tar -zcvf ${OTHERNAME3}_$(date +%Y%m%d).tar.gz ${OTHER3}

#删除FTP空间15天前备份&上传到FTP空间
ftp -v -n ${网站2Com} << EOF
user ${STPUSER} ${STPPASS}
type binary
cd ${STPDIR}
delete ${DB2}_data$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${WEBNAME2}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME1}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME2}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME3}_$(date -d "15day ago" +%Y%m%d).tar.gz
put ${DB2}_data$(date +%Y%m%d).tar.gz
put ${WEBNAME2}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME1}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME2}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME3}_$(date +%Y%m%d).tar.gz
bye
EOF
#删除本地文件
cd ${DIR}
rm -rf ${DB2}.sql.gz ${DB2}_data$(date +%Y%m%d).tar.gz ${WEBNAME2}_$(date +%Y%m%d).tar.gz ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHERNAME3}_$(date +%Y%m%d).tar.gz

#开始备份网站网站5
#导出数据库
mysqldump -p ${DB5} -u ${DBUSER} --password=${DBPASS} | gzip > ${DB5}.sql.gz
#打包文件
tar -zcvf ${DB5}_data$(date +%Y%m%d).tar.gz ${DB5}.sql.gz
tar -zcvf ${WEBNAME5}_$(date +%Y%m%d).tar.gz ${WEBSITE5}
tar -zcvf ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHER1}
tar -zcvf ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHER2}
tar -zcvf ${OTHERNAME3}_$(date +%Y%m%d).tar.gz ${OTHER3}

#删除FTP空间7天前备份&上传到FTP空间
ftp -v -n ${网站5网站1Com} << EOF
user ${MTPUSER} ${MTPPASS}
type binary
cd ${MTPDIR}
delete ${DB5}_data$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${WEBNAME5}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME1}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME2}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME3}_$(date -d "15day ago" +%Y%m%d).tar.gz
put ${DB5}_data$(date +%Y%m%d).tar.gz
put ${WEBNAME5}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME1}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME2}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME3}_$(date +%Y%m%d).tar.gz
bye
EOF
#删除本地文件
cd ${DIR}
rm -rf ${DB5}.sql.gz ${DB5}_data$(date +%Y%m%d).tar.gz ${WEBNAME5}_$(date +%Y%m%d).tar.gz ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHERNAME3}_$(date +%Y%m%d).tar.gz

#开始备份网站网站6
#导出数据库
mysqldump -p ${DB6} -u ${DBUSER} --password=${DBPASS} | gzip > ${DB6}.sql.gz
#打包文件
tar -zcvf ${DB6}_data$(date +%Y%m%d).tar.gz ${DB6}.sql.gz
tar -zcvf ${WEBNAME6}_$(date +%Y%m%d).tar.gz ${WEBSITE6}
tar -zcvf ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHER1}
tar -zcvf ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHER2}
tar -zcvf ${OTHERNAME3}_$(date +%Y%m%d).tar.gz ${OTHER3}

#删除FTP空间15天前备份&上传到FTP空间
ftp -v -n ${网站6} << EOF
user ${FSFTPUSER} ${FSFTPPASS}
type binary
cd ${FSFTPDIR}
delete ${DB6}_data$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${WEBNAME6}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME1}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME2}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME3}_$(date -d "15day ago" +%Y%m%d).tar.gz
put ${DB6}_data$(date +%Y%m%d).tar.gz
put ${WEBNAME6}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME1}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME2}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME3}_$(date +%Y%m%d).tar.gz
bye
EOF
#删除本地文件
cd ${DIR}
rm -rf ${DB6}.sql.gz ${DB6}_data$(date +%Y%m%d).tar.gz ${WEBNAME6}_$(date +%Y%m%d).tar.gz ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHERNAME3}_$(date +%Y%m%d).tar.gz

#开始备份网站网站7
#导出数据库
mysqldump -p ${DB7} -u ${DBUSER} --password=${DBPASS} | gzip > ${DB7}.sql.gz
#打包文件
tar -zcvf ${DB7}_data$(date +%Y%m%d).tar.gz ${DB7}.sql.gz
tar -zcvf ${WEBNAME7}_$(date +%Y%m%d).tar.gz ${WEBSITE7}
tar -zcvf ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHER1}
tar -zcvf ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHER2}
tar -zcvf ${OTHERNAME3}_$(date +%Y%m%d).tar.gz ${OTHER3}

#删除FTP空间15天前备份&上传到FTP空间
ftp -v -n ${网站7} << EOF
user ${FFTPUSER} ${FFTPPASS}
type binary
cd ${FFTPDIR}
delete ${DB7}_data$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${WEBNAME7}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME1}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME2}_$(date -d "15day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME3}_$(date -d "15day ago" +%Y%m%d).tar.gz
put ${DB7}_data$(date +%Y%m%d).tar.gz
put ${WEBNAME7}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME1}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME2}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME3}_$(date +%Y%m%d).tar.gz
bye
EOF
#删除本地文件
cd ${DIR}
rm -rf ${DB7}.sql.gz ${DB7}_data$(date +%Y%m%d).tar.gz ${WEBNAME7}_$(date +%Y%m%d).tar.gz ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHERNAME3}_$(date +%Y%m%d).tar.gz

#开始备份网站网站3.Com
#导出数据库
mysqldump -p ${DB3} -u ${DBUSER} --password=${DBPASS} | gzip > ${DB3}.sql.gz
#打包文件
tar -zcvf ${DB3}_data$(date +%Y%m%d).tar.gz ${DB3}.sql.gz
tar -zcvf ${WEBNAME3}_$(date +%Y%m%d).tar.gz ${WEBSITE3}
tar -zcvf ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHER1}
tar -zcvf ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHER2}
tar -zcvf ${OTHERNAME3}_$(date +%Y%m%d).tar.gz ${OTHER3}

#删除FTP空间7天前备份&上传到FTP空间
ftp -v -n ${网站3Com} << EOF
user ${AGTPUSER} ${AGTPPASS}
type binary
cd ${AGTPDIR}
delete ${DB3}_data$(date -d "7day ago" +%Y%m%d).tar.gz
delete ${WEBNAME3}_$(date -d "7day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME1}_$(date -d "7day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME2}_$(date -d "7day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME3}_$(date -d "7day ago" +%Y%m%d).tar.gz
put ${DB3}_data$(date +%Y%m%d).tar.gz
put ${WEBNAME3}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME1}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME2}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME3}_$(date +%Y%m%d).tar.gz
bye
EOF
#删除本地文件
cd ${DIR}
rm -rf ${DB3}.sql.gz ${DB3}_data$(date +%Y%m%d).tar.gz ${WEBNAME3}_$(date +%Y%m%d).tar.gz ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHERNAME3}_$(date +%Y%m%d).tar.gz

#开始备份网站网站4
#导出数据库
mysqldump -p ${DB4} -u ${DBUSER} --password=${DBPASS} | gzip > ${DB4}.sql.gz
#打包文件
tar -zcvf ${DB4}_data$(date +%Y%m%d).tar.gz ${DB4}.sql.gz
tar -zcvf ${WEBNAME4}_$(date +%Y%m%d).tar.gz ${WEBSITE4}
tar -zcvf ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHER1}
tar -zcvf ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHER2}
tar -zcvf ${OTHERNAME3}_$(date +%Y%m%d).tar.gz ${OTHER3}

#删除FTP空间7天前备份&上传到FTP空间
ftp -v -n ${网站4} << EOF
user ${ACTPUSER} ${ACTPPASS}
type binary
cd ${ACTPDIR}
delete ${DB4}_data$(date -d "7day ago" +%Y%m%d).tar.gz
delete ${WEBNAME4}_$(date -d "7day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME1}_$(date -d "7day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME2}_$(date -d "7day ago" +%Y%m%d).tar.gz
delete ${OTHERNAME3}_$(date -d "7day ago" +%Y%m%d).tar.gz
put ${DB4}_data$(date +%Y%m%d).tar.gz
put ${WEBNAME4}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME1}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME2}_$(date +%Y%m%d).tar.gz
put ${OTHERNAME3}_$(date +%Y%m%d).tar.gz
bye
EOF
#删除本地文件
cd ${DIR}
rm -rf ${DB4}.sql.gz ${DB4}_data$(date +%Y%m%d).tar.gz ${WEBNAME4}_$(date +%Y%m%d).tar.gz ${OTHERNAME1}_$(date +%Y%m%d).tar.gz ${OTHERNAME2}_$(date +%Y%m%d).tar.gz ${OTHERNAME3}_$(date +%Y%m%d).tar.gz

更新一下多FTP服务器多站多数据库备份SHELL脚本

weinxin
QQ群:20764411
QQ群扫码加群