VPS侦探论坛

 找回密码
 注册
查看: 3742|回复: 2

军哥,还要麻烦一下,关于备份的问题

[复制链接]
发表于 2016-4-26 19:52:21 | 显示全部楼层 |阅读模式

我看了你的备份数据库到FTP的,成功了。我的情况是这样的,我还有一个虚拟主机,我想做个备用的地址,他在FTP空间提供了一个数据库恢复目录。我想每天把VPS上/usr/local/mysql/var/数据库名/里面的数据库文件(就是后缀FRM MYD的文件)拷贝到backup目录,不要压缩。然后利用fFTP将这个目录里面的文件远程备份到FTPSQL恢复目录里面。这样我只需要点一下空间里的恢复数据库就同步了。拷贝过程中有相同文件直接覆盖,请问这样怎么实现?菜鸟一个,帮帮我忙吧,谢谢啦。

你文件中的backup.sh内容,求修改
  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/wwwroot/vpser.net" "/home/wwwroot/lnmp.org")

  10. ######~Set MySQL Database you want to backup~######
  11. Backup_Database=("lnmp" "vpser")

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

  15. ######~Enable Ftp Backup~######
  16. Enable_FTP=0
  17. # 0: enable; 1: disable
  18. ######~Set FTP Information~######
  19. FTP_Host='1.2.3.4'
  20. FTP_Username='vpser.net'
  21. FTP_Password='yourftppassword'
  22. FTP_Dir="backup"

  23. #Values Setting END!

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

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

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

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

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

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

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

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

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

  69. echo "complete."
  70. fi
复制代码
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2016-4-26 20:49:43 | 显示全部楼层


bye 前面加上一句 mirror -R /usr/local/mysql/var/数据库名  这个数据库名就会备份到ftp上
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
 楼主| 发表于 2016-4-27 08:45:04 | 显示全部楼层

好的,修改成功了,谢谢
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-11-17 13:43 , Processed in 0.025470 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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