- 积分
- 77
- 威望
-
- 金钱
-
- 注册时间
- 2016-6-21
- 在线时间
- 小时
- 最后登录
- 1970-1-1
|
因为网站文件夹比较大,所以用军哥的backup.sh每天只备份数据库。然后自己改了个backup7.sh,每周一备份网站文件夹。
但是现在出现一个问题,就是手动运行backup7.sh可以正常备份,但是每周一自动运行的时候,就出错,旧备份都删除了,但是新备份失败了,无论是源VPS里的backup文件夹,还是备份VPS里的备份文件夹里,都没有新的网站文件夹备份。
特来求助军哥,谢谢。
crontab代码如下:
- 00 03 * * * /root/backup.sh
- 00 04 * * 1 /root/backup7.sh
复制代码
backup7.sh代码如下:
- #!/bin/bash
- #Funciont: Backup website and mysql database
- #Author: licess
- #Website: http://lnmp.org
- #IMPORTANT!!!Please Setting the following Values!
- Backup_Home="/home/backup/"
- ######~Set Directory you want to backup~######
- Backup_Dir=("/home/wwwroot/www.12345.com")
- ######~Enable Ftp Backup~######
- Enable_FTP=0
- # 0: enable; 1: disable
- ######~Set FTP Information~######
- FTP_Host='1.2.3.4'
- FTP_Username='12345'
- FTP_Password='12345'
- FTP_Dir="backup"
- #Values Setting END!
- TodayWWWBackup=www-*-$(date +"%Y%m%d").tar.gz
- OldWWWBackup=www-*-$(date -d -7day +"%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 [ ! -d ${Backup_Home} ]; then
- mkdir -p ${Backup_Home}
- fi
- type lftp >/dev/null 2>&1 || { echo >&2 "lftp command not found. Install: centos:yum install lftp,debian/ubuntu:apt-get install lftp."; }
- 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
复制代码 |
|