VPS侦探论坛

 找回密码
 注册
查看: 4647|回复: 4

LNMP1.2的备份脚本相关问题

[复制链接]
发表于 2015-8-31 22:03:00 | 显示全部楼层 |阅读模式

crontab执行日志:
  1. Backup website files...
  2. Backup Databases...
  3. Delete old backup files...
  4. Uploading backup files to ftp...
  5. /home/backup/backup.sh: line 77: cd: /home/backup/
  6. : No such file or directory
  7. /home/backup/backup.sh: line 78:
  8. : command not found
  9. Usage: rm [-r] [-f] files...
  10. Usage: rm [-r] [-f] files...
  11. mput: www-*-20150831.tar.gz: no files found
  12. mput: db-*-20150831.sql: no files found
  13. /home/backup/backup.sh: line 87:
  14. : command not found
  15. complete.
复制代码
根据这个日志来看是没有找到/home/backup/这个目录,但是确实是这个目录,并且备份是没有问题的,现在的问题就是没有FTP传输备份文件到FTP空间!
如果进入目录手动执行./backup.sh,就没有问题(注释了备份,因为已经备份),传输到FTP没有问题!
看了半天也不知道哪里的问题,军哥帮忙看看...
  1. [root@f2 backup]# ./backup.sh
  2. Backup website files...
  3. Backup Databases...
  4. Delete old backup files...
  5. Uploading backup files to ftp...
  6. Usage: rm [-r] [-f] files...
  7. Usage: rm [-r] [-f] files...
  8. `db-bbs-20150831.sql' at 1898232740 (64%) 9.12M/s eta:2m [Sending data]
复制代码

[ 本帖最后由 usa 于 2015-8-31 22:11 编辑 ]
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2015-9-1 07:54:50 | 显示全部楼层


你发一下你crontab里添加的规则我看一下
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2015-9-1 08:33:21 | 显示全部楼层

  1. [root@f2 ~]# crontab -l
  2. 30 2 * * 1 /home/backup/backup.sh
复制代码
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2015-9-1 17:08:06 | 显示全部楼层



发你的脚本看一下,去掉个人隐私信息
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2015-9-1 17:12:53 | 显示全部楼层

  1. #!/bin/bash

  2. #Funciont: Backup website and mysql database
  3. #Author: licess
  4. #Website: http://lnmp.org

  5. #IMPORTANT!!!Please Setting the following Values!

  6. Backup_Home="/home/backup/"
  7. MySQL_Dump="/usr/local/mysql/bin/mysqldump"
  8. ######~Set Directory you want to backup~######
  9. Backup_Dir=("/home/web" "/home/web2")

  10. ######~Set MySQL Database you want to backup~######
  11. Backup_Database=("1" "2" "3" "4" "5" "6" "7" "8" "9" "10")

  12. ######~Set MySQL UserName and password~######
  13. MYSQL_UserName='root'
  14. MYSQL_PassWord='mima112233445566'

  15. ######~Enable Ftp Backup~######
  16. Enable_FTP=0
  17. # 0: enable; 1: disable
  18. ######~Set FTP Information~######
  19. FTP_Host='127.0.0.1'
  20. FTP_port=2121
  21. FTP_Username='backup'
  22. FTP_Password='mima112233445566'
  23. FTP_Dir="web"

  24. #Values Setting END!

  25. TodayWWWBackup=www-*-$(date +"%Y%m%d").tar.gz
  26. TodayDBBackup=db-*-$(date +"%Y%m%d").sql
  27. OldWWWBackup=www-*-$(date -d -14day +"%Y%m%d").tar.gz
  28. OldDBBackup=db-*-$(date -d -14day +"%Y%m%d").sql

  29. Backup_Dir()
  30. {
  31.     Backup_Path=$1
  32.     Dir_Name=`echo ${Backup_Path##*/}`
  33.     Pre_Dir=`echo ${Backup_Path}|sed 's/'${Dir_Name}'//g'`
  34.     tar zcf ${Backup_Home}www-${Dir_Name}-$(date +"%Y%m%d").tar.gz -C ${Pre_Dir} ${Dir_Name}
  35. }
  36. Backup_Sql()
  37. {
  38.     ${MySQL_Dump} -u$MYSQL_UserName -p$MYSQL_PassWord $1 > ${Backup_Home}db-$1-$(date +"%Y%m%d").sql
  39. }

  40. if [ ! -f ${MySQL_Dump} ]; then  
  41.     echo "mysqldump command not found.please check your setting."
  42.     exit 1
  43. fi

  44. if [ ! -d ${Backup_Home} ]; then  
  45.     mkdir -p ${Backup_Home}
  46. fi

  47. type lftp >/dev/null 2>&1 || { echo >&2 "lftp command not found. Install: centos:yum install lftp,debian/ubuntu:apt-get install lftp."; }

  48. echo "Backup website files..."
  49. for dd in ${Backup_Dir[@]};do
  50.     Backup_Dir ${dd}
  51. done

  52. echo "Backup Databases..."
  53. for db in ${Backup_Database[@]};do
  54.     Backup_Sql ${db}
  55. done

  56. echo "Delete old backup files..."
  57. rm -f ${Backup_Home}${OldWWWBackup}
  58. rm -f ${Backup_Home}${OldDBBackup}

  59. if [ ${Enable_FTP} = 0 ]; then
  60.     echo "Uploading backup files to ftp..."
  61.     cd ${Backup_Home}
  62.    
  63.     lftp ${FTP_Host}:${FTP_port} -u ${FTP_Username},${FTP_Password} << EOF
  64. cd ${FTP_Dir}
  65. mrm ${OldWWWBackup}
  66. mrm ${OldDBBackup}
  67. mput ${TodayWWWBackup}
  68. mput ${TodayDBBackup}
  69. bye
  70. EOF

  71. echo "complete."
  72. fi
复制代码


只加了FTP端口,几乎没修改...

军哥运维代购:http://shop63846532.taobao.com/

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-11-17 04:29 , Processed in 0.026911 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表