[code lang="js"]

#!/bin/bash
######~mysqldump位置~######
MySQL_Dump="/usr/local/mysql/bin/mysqldump"

######~保存备份文件最长时间(天)~######
Backup_Day='7'

######~备份文件保存位置~######
Backup_Home="/home/backup"

######~需要备份的网站目录~######
Backup_Web=("/home/wwwroot/www.wzhpp.com")

######~需要备份的数据库~######
Backup_Database=("wzhpp")

######~MySQL设置~######
MYSQL_UserName='root'
MYSQL_PassWord='******'

######~备份文件名~######
Web='web'
Sql='sql'

######~备份模式~######
Enable_OSS='0'
Enable_FTP='1'
# 0: 开启; 1: 关闭

######~OSS设置~######
OSS_Bucket='wzh'
OSS_Dir='backup'
OSS_Host='oss-cn-hangzhou.aliyuncs.com'
#OSS_Host='oss-cn-hangzhou-internal.aliyuncs.com'
OSS_Id='******'
OSS_Key='******'

######~FTP设置~######
FTP_Host='******'
FTP_Username='******'
FTP_Password='******'
FTP_Dir='backup'

if [ ! -f ~/.ossutilconfig ]; then
echo "OSS配置文件不存在,自动创建..."
./ossutil config -e ${OSS_Host} -I ${OSS_Id} -K ${OSS_Key}
fi

if [ ! -f ${MySQL_Dump} ]; then
echo "mysqldump命令错误."
exit 1
fi

if [ ! -d ${Backup_Home} ]; then
mkdir -p ${Backup_Home}
fi

type lftp >/dev/null 2>&1 || { echo >&2 "lftp命令错误."; }

######~Backup~######
Backup_Dir=$(pwd)
cd ${Backup_Home}
Backup_Web()
{
Backup_Path=$1
Dir_Name=`echo ${Backup_Path##*/}`
Pre_Dir=`echo ${Backup_Path}|sed 's/'${Dir_Name}'//g'`
tar zcf ${Web}-${Dir_Name}-$(date +"%Y%m%d").tar.gz -C ${Pre_Dir} ${Dir_Name}
tar rvf ${Web}-$(date +%Y%m%d).tar.gz ${Web}-${Dir_Name}-$(date +"%Y%m%d").tar.gz --remove-files
}
Backup_Sql()
{
${MySQL_Dump} -u$MYSQL_UserName -p$MYSQL_PassWord $1 > ${Sql}-$1-$(date +"%Y%m%d").sql
tar rvf ${Sql}-$(date +"%Y%m%d").tar.gz ${Sql}-$1-$(date +"%Y%m%d").sql --remove-files
}

echo "正在删除本地过期文件..."
for ((i=${Backup_Day};i<${Backup_Day}+3;i++)); do
OldWeb=${Web}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
OldSql=${Sql}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
rm -rf ${OldWeb}
rm -rf ${OldSql}
done

echo "正在备份网站..."
rm -rf ${Web}-$(date +%Y%m%d).tar.gz
for web in ${Backup_Web[@]};do
Backup_Web ${web}
done

echo "正在备份数据库..."
rm -rf ${Sql}-$(date +%Y%m%d).tar.gz
for db in ${Backup_Database[@]};do
Backup_Sql ${db}
done

######~OSS~######
if [ ${Enable_OSS} = 0 ]; then
echo "正在删除OSS过期文件..."
for ((i=${Backup_Day};i<${Backup_Day}+3;i++)); do
OldWeb=${Web}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
OldSql=${Sql}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
$Backup_Dir/ossutil rm oss://${OSS_Bucket}/${OSS_Dir}/${OldWeb}
$Backup_Dir/ossutil rm oss://${OSS_Bucket}/${OSS_Dir}/${OldSql}
done
echo "正在上传文件到OSS..."
$Backup_Dir/ossutil rm oss://${OSS_Bucket}/${OSS_Dir}/${Web}-$(date +"%Y%m%d").tar.gz
$Backup_Dir/ossutil rm oss://${OSS_Bucket}/${OSS_Dir}/${Sql}-$(date +"%Y%m%d").tar.gz
$Backup_Dir/ossutil cp ${Web}-$(date +"%Y%m%d").tar.gz oss://${OSS_Bucket}/${OSS_Dir}/${Web}-$(date +"%Y%m%d").tar.gz
$Backup_Dir/ossutil cp ${Sql}-$(date +"%Y%m%d").tar.gz oss://${OSS_Bucket}/${OSS_Dir}/${Sql}-$(date +"%Y%m%d").tar.gz
echo "备份文件到OSS完成..."
fi

######~FTP~######
if [ ${Enable_FTP} = 0 ]; then
echo "正在删除FTP过期文件..."
for ((i=${Backup_Day};i<${Backup_Day}+3;i++)); do
OldWeb=${Web}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
OldSql=${Sql}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
lftp ${FTP_Host} -u ${FTP_Username},${FTP_Password} << EOF
cd ${FTP_Dir}
mrm ${OldWeb}
mrm ${OldSql}
bye
EOF
done
echo "正在上传文件到FTP..."
lftp ${FTP_Host} -u ${FTP_Username},${FTP_Password} << EOF
cd ${FTP_Dir}
mrm ${Web}-$(date +"%Y%m%d").tar.gz
mrm ${Sql}-$(date +"%Y%m%d").tar.gz
mput ${Web}-$(date +"%Y%m%d").tar.gz
mput ${Sql}-$(date +"%Y%m%d").tar.gz
bye
EOF
echo "备份文件到FTP完成..."
fi
######~Backup~######

[/code]

ossutil 下载地址 https://help.aliyun.com/document_detail/35477.html

[code lang="js"]

#!/bin/bash
######~mysqldump位置~######
MySQL_Dump="/usr/local/mysql/bin/mysqldump"

######~保存备份文件最长时间(天)~######
Backup_Day='7'

######~备份文件保存位置~######
Backup_Home="/home/backup"

######~需要备份的网站目录~######
Backup_Web=("/home/wwwroot/www.wzhpp.com")

######~需要备份的数据库~######
Backup_Database=("wzhpp")

######~MySQL设置~######
MYSQL_UserName='root'
MYSQL_PassWord='wzh4418090.'

######~备份文件名~######
Web='web'
Sql='sql'

######~备份模式~######
Enable_OSS='0'
Enable_FTP='1'
# 0: 开启; 1: 关闭

######~OSS设置~######
OSS_Bucket='wzh'
#OSS_Host='oss-cn-hangzhou.aliyuncs.com'
OSS_Host='oss-cn-hangzhou-internal.aliyuncs.com'
OSS_Id='******'
OSS_Key='******'
OSS_Dir='Backup'

######~FTP设置~######
FTP_Host='******'
FTP_Username='******'
FTP_Password='******'
FTP_Dir='Backup'

######~Backup~######
Backup_Dir=$(pwd)
cd ${Backup_Home}
Backup_Web()
{
Backup_Path=$1
Dir_Name=`echo ${Backup_Path##*/}`
Pre_Dir=`echo ${Backup_Path}|sed 's/'${Dir_Name}'//g'`
tar zcf ${Web}-${Dir_Name}-$(date +"%Y%m%d").tar.gz -C ${Pre_Dir} ${Dir_Name}
tar rvf ${Web}-$(date +%Y%m%d).tar.gz ${Web}-${Dir_Name}-$(date +"%Y%m%d").tar.gz --remove-files
}
Backup_Sql()
{
${MySQL_Dump} -u$MYSQL_UserName -p$MYSQL_PassWord $1 > ${Sql}-$1-$(date +"%Y%m%d").sql
tar rvf ${Sql}-$(date +"%Y%m%d").tar.gz ${Sql}-$1-$(date +"%Y%m%d").sql --remove-files
}

if [ ! -f ${MySQL_Dump} ]; then
echo "mysqldump命令错误."
exit 1
fi

if [ ! -d ${Backup_Home} ]; then
mkdir -p ${Backup_Home}
fi

type lftp >/dev/null 2>&1 || { echo >&2 "lftp命令错误."; }

echo "正在删除本地过期文件..."
for ((i=${Backup_Day};i<${Backup_Day}+3;i++)); do
OldWeb=${Web}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
OldSql=${Sql}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
rm -rf ${OldWeb}
rm -rf ${OldSql}
done

echo "正在备份网站..."
rm -rf ${Web}-$(date +%Y%m%d).tar.gz
for web in ${Backup_Web[@]};do
Backup_Web ${web}
done

echo "正在备份数据库..."
rm -rf ${Sql}-$(date +%Y%m%d).tar.gz
for db in ${Backup_Database[@]};do
Backup_Sql ${db}
done

######~OSS~######
if [ ${Enable_OSS} = 0 ]; then
echo "正在删除OSS过期文件..."
for ((i=${Backup_Day};i<${Backup_Day}+3;i++)); do
OldWeb=${Web}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
OldSql=${Sql}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
python $Backup_Dir/oss/osscmd --host=${OSS_Host} --id=${OSS_Id} --key=${OSS_Key} del oss://${OSS_Bucket}/${OSS_Dir}/${OldWeb}
python $Backup_Dir/oss/osscmd --host=${OSS_Host} --id=${OSS_Id} --key=${OSS_Key} del oss://${OSS_Bucket}/${OSS_Dir}/${OldSql}
done
echo "正在上传文件到OSS..."
python $Backup_Dir/oss/osscmd --host=${OSS_Host} --id=${OSS_Id} --key=${OSS_Key} del oss://${OSS_Bucket}/${OSS_Dir}/${Web}-$(date +"%Y%m%d").tar.gz
python $Backup_Dir/oss/osscmd --host=${OSS_Host} --id=${OSS_Id} --key=${OSS_Key} del oss://${OSS_Bucket}/${OSS_Dir}/${Sql}-$(date +"%Y%m%d").tar.gz
python $Backup_Dir/oss/osscmd --host=${OSS_Host} --id=${OSS_Id} --key=${OSS_Key} put ${Web}-$(date +"%Y%m%d").tar.gz oss://${OSS_Bucket}/${OSS_Dir}/${Web}-$(date +"%Y%m%d").tar.gz
python $Backup_Dir/oss/osscmd --host=${OSS_Host} --id=${OSS_Id} --key=${OSS_Key} put ${Sql}-$(date +"%Y%m%d").tar.gz oss://${OSS_Bucket}/${OSS_Dir}/${Sql}-$(date +"%Y%m%d").tar.gz
echo "备份文件到OSS完成..."
fi

######~FTP~######
if [ ${Enable_FTP} = 0 ]; then
echo "正在删除FTP过期文件......"
for ((i=${Backup_Day};i<${Backup_Day}+3;i++)); do
OldWeb=${Web}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
OldSql=${Sql}-$(date -d -"${i}"day +"%Y%m%d").tar.gz
lftp ${FTP_Host} -u ${FTP_Username},${FTP_Password} << EOF
cd ${FTP_Dir}
mrm ${OldWeb}
mrm ${OldSql}
bye
EOF
done
echo "正在上传文件到FTP..."
lftp ${FTP_Host} -u ${FTP_Username},${FTP_Password} << EOF
cd ${FTP_Dir}
mrm ${Web}-$(date +"%Y%m%d").tar.gz
mrm ${Sql}-$(date +"%Y%m%d").tar.gz
mput ${Web}-$(date +"%Y%m%d").tar.gz
mput ${Sql}-$(date +"%Y%m%d").tar.gz
bye
EOF
echo "备份文件到FTP完成..."
fi
######~Backup~######

[/code]

osscmd 下载地址 https://help.aliyun.com/document_detail/32171.html

[code lang="js"]
server
{
listen 443 ssl;
server_name www.wzhpp.com wzhpp.com;

if ($host = 'wzhpp.com'){
return 301 https://www.wzhpp.com$request_uri;
}

index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.wzhpp.com;
ssl on;
ssl_certificate /home/ssl/www.wzhpp.com/ssl.crt;
ssl_certificate_key /home/ssl/www.wzhpp.com/ssl.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RC4-SHA:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!DSS:!PKS;
ssl_session_cache builtin:1000 shared:SSL:10m;

include wordpress.conf;
#error_page 404 /404.html;
include enable-php.conf;

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}

location ~ .*\.(js|css)?$
{
expires 12h;
}

location ~ /\.
{
deny all;
}

access_log /home/wwwlogs/www.wzhpp.com.log;
}

server
{
listen 80;
server_name www.wzhpp.com wzhpp.com;
return 301 https://www.wzhpp.com$request_uri;
}

[/code]