LNMP1.2的备份脚本相关问题
crontab执行日志:Backup website files...
Backup Databases...
Delete old backup files...
Uploading backup files to ftp...
/home/backup/backup.sh: line 77: cd: /home/backup/
: No such file or directory
/home/backup/backup.sh: line 78:
: command not found
Usage: rm [-r] [-f] files...
Usage: rm [-r] [-f] files...
mput: www-*-20150831.tar.gz: no files found
mput: db-*-20150831.sql: no files found
/home/backup/backup.sh: line 87:
: command not found
complete.根据这个日志来看是没有找到/home/backup/这个目录,但是确实是这个目录,并且备份是没有问题的,现在的问题就是没有FTP传输备份文件到FTP空间!
如果进入目录手动执行./backup.sh,就没有问题(注释了备份,因为已经备份),传输到FTP没有问题!
看了半天也不知道哪里的问题,军哥帮忙看看...# ./backup.sh
Backup website files...
Backup Databases...
Delete old backup files...
Uploading backup files to ftp...
Usage: rm [-r] [-f] files...
Usage: rm [-r] [-f] files...
`db-bbs-20150831.sql' at 1898232740 (64%) 9.12M/s eta:2m
[ 本帖最后由 usa 于 2015-8-31 22:11 编辑 ] 你发一下你crontab里添加的规则我看一下 # crontab -l
30 2 * * 1 /home/backup/backup.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/"
MySQL_Dump="/usr/local/mysql/bin/mysqldump"
######~Set Directory you want to backup~######
Backup_Dir=("/home/web" "/home/web2")
######~Set MySQL Database you want to backup~######
Backup_Database=("1" "2" "3" "4" "5" "6" "7" "8" "9" "10")
######~Set MySQL UserName and password~######
MYSQL_UserName='root'
MYSQL_PassWord='mima112233445566'
######~Enable Ftp Backup~######
Enable_FTP=0
# 0: enable; 1: disable
######~Set FTP Information~######
FTP_Host='127.0.0.1'
FTP_port=2121
FTP_Username='backup'
FTP_Password='mima112233445566'
FTP_Dir="web"
#Values Setting END!
TodayWWWBackup=www-*-$(date +"%Y%m%d").tar.gz
TodayDBBackup=db-*-$(date +"%Y%m%d").sql
OldWWWBackup=www-*-$(date -d -14day +"%Y%m%d").tar.gz
OldDBBackup=db-*-$(date -d -14day +"%Y%m%d").sql
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}
}
Backup_Sql()
{
${MySQL_Dump} -u$MYSQL_UserName -p$MYSQL_PassWord $1 > ${Backup_Home}db-$1-$(date +"%Y%m%d").sql
}
if [ ! -f ${MySQL_Dump} ]; then
echo "mysqldump command not found.please check your setting."
exit 1
fi
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 "Backup Databases..."
for db in ${Backup_Database[@]};do
Backup_Sql ${db}
done
echo "Delete old backup files..."
rm -f ${Backup_Home}${OldWWWBackup}
rm -f ${Backup_Home}${OldDBBackup}
if [ ${Enable_FTP} = 0 ]; then
echo "Uploading backup files to ftp..."
cd ${Backup_Home}
lftp ${FTP_Host}:${FTP_port} -u ${FTP_Username},${FTP_Password} << EOF
cd ${FTP_Dir}
mrm ${OldWWWBackup}
mrm ${OldDBBackup}
mput ${TodayWWWBackup}
mput ${TodayDBBackup}
bye
EOF
echo "complete."
fi
只加了FTP端口,几乎没修改...
页:
[1]