- 积分
- 16
- 威望
-
- 金钱
-
- 注册时间
- 2017-3-3
- 在线时间
- 小时
- 最后登录
- 1970-1-1
|
军哥: 我最近在军哥网站上学习备份的脚本,按要求修改了备份的参数,很好用!
现我想把网站数据和数据库分开备份,网站数据按半个月一次来备份,备份完后删除本地文件,我应该怎么改下面的脚本?谢谢!
#!/bin/bash
#Funciont: Backup website
#Author: licess
#Website: https://lnmp.org
#IMPORTANT!!!Please Setting the following Values!
Backup_Home="/home/backup/"
######~Set Directory you want to backup~######
Backup_Dir=("/home/wwwroot/vpser.net" "/home/wwwroot/lnmp.org")
######~Enable Ftp Backup~######
Enable_FTP=0
# 0: enable; 1: disable
######~Set FTP Information~######
FTP_Host='1.2.3.4'
FTP_Username='vpser.net'
FTP_Password='yourftppassword'
FTP_Dir="backup"
#Values Setting END!
TodayWWWBackup=www-*-$(date +"%Y%m%d").tar.gz
OldWWWBackup=www-*-$(date -d -3day +"%Y%m%d").tar.gz
Backup_Dir()
{
Backup_Path=$1
Dir_Name=`echo ${Backup_Path##*/}`
Pre_Dir=`echo ${Backup_Path}|sed 's/'${Dir_Name}'//g'`
tar zcf ${Backup_Home}www-${Dir_Name}-$(date +"%Y%m%d").tar.gz -C ${Pre_Dir} ${Dir_Name}
}
if [ ${Enable_FTP} = 0 ]; then
type lftp >/dev/null 2>&1 || { echo >&2 "lftp command not found. Install: centos:yum install lftp,debian/ubuntu:apt-get install lftp."; }
fi
echo "Backup website files..."
for dd in ${Backup_Dir[@]};do
Backup_Dir ${dd}
done
echo "Delete old backup files..."
rm -f ${Backup_Home}${OldWWWBackup}
if [ ${Enable_FTP} = 0 ]; then
echo "Uploading backup files to ftp..."
cd ${Backup_Home}
lftp ${FTP_Host} -u ${FTP_Username},${FTP_Password} << EOF
cd ${FTP_Dir}
mrm ${OldWWWBackup}
mput ${TodayWWWBackup}
bye
EOF
echo "complete."
fi |
|