- 积分
- 14
- 威望
-
- 金钱
-
- 注册时间
- 2016-2-20
- 在线时间
- 小时
- 最后登录
- 1970-1-1
|
lnmp一键包第一次使用,刚装上正在研究,不甚熟悉。/lnmp1.2-full/tools/下有个backup.sh备份脚本,看代码是可以用来备份数据库和网站目录的。我有三个问题想咨询下坛主:
1、如何手动运行backup.sh备份功能?
在运行bash backup.sh后报错,backup.sh放在/root/下:
- [root@AY1211101 ~]# bash backup.sh
- : command not found
- : command not found
- : command not found
- : command not found
- : command not found
- : command not found
- : command not found
- : command not found
- : command not found
- 'ackup.sh: line 37: syntax error near unexpected token `
- 'ackup.sh: line 37: `Backup_Dir()
复制代码
2、如何将backup.sh添加到crontab中定时自动运行备份?
3、如何只备份数据库并用FTP上传备份?
网站目录备份对我来说不需要用到,是否可以直接注释掉带"WWWBackup"、"Backup_Dir"、"Backup_Home"特征的部分代码来去掉网站目录备份?
请坛主指教,感谢坛主的无私奉献!
我的backup.sh文件内容如下,里面的mysql名和password实际使用是正确的,以下做了示例隐藏处理:
- #!/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/wwwroot/vpser.net" "/home/wwwroot/lnmp.org")
- ######~Set MySQL Database you want to backup~######
- Backup_Database=("db1" "db2")
- ######~Set MySQL UserName and password~######
- MYSQL_UserName='root'
- MYSQL_PassWord='1***1'
- ######~Enable Ftp Backup~######
- Enable_FTP=1
- # 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
- TodayDBBackup=db-*-$(date +"%Y%m%d").sql
- OldWWWBackup=www-*-$(date -d -3day +"%Y%m%d").tar.gz
- OldDBBackup=db-*-$(date -d -3day +"%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} -u ${FTP_Username},${FTP_Password} << EOF
- cd ${FTP_Dir}
- mrm ${OldWWWBackup}
- mrm ${OldDBBackup}
- mput ${TodayWWWBackup}
- mput ${TodayDBBackup}
- bye
- EOF
- echo "complete."
- fi
复制代码
[ 本帖最后由 半岛小生 于 2016-2-22 12:19 编辑 ] |
|