website_bk.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. . ../options.conf
  11. WebSite=$1
  12. LogFile=${backup_dir}/web.log
  13. NewFile=${backup_dir}/Web_${WebSite}_$(date +%Y%m%d_%H).tgz
  14. OldFile=${backup_dir}/Web_${WebSite}_$(date +%Y%m%d --date="${expired_days} days ago")*.tgz
  15. [ ! -e "${backup_dir}" ] && mkdir -p ${backup_dir}
  16. [ ! -e "${wwwroot_dir}/${WebSite}" ] && { echo "[${wwwroot_dir}/${WebSite}] not exist" >> ${LogFile} ; exit 1 ; }
  17. if [ `du -sm "${wwwroot_dir}/${WebSite}" | awk '{print $1}'` -lt 1024 ]; then
  18. if [ -n "`ls ${OldFile} 2>/dev/null`" ]; then
  19. rm -f ${OldFile}
  20. echo "[${OldFile}] Delete Old File Success" >> ${LogFile}
  21. else
  22. echo "[${OldFile}] Delete Old Backup File" >> ${LogFile}
  23. fi
  24. if [ -e "${NewFile}" ]; then
  25. echo "[${NewFile}] The Backup File is exists, Can't Backup" >> ${LogFile}
  26. else
  27. pushd ${wwwroot_dir} > /dev/null
  28. tar czf ${NewFile} ./${WebSite} >> ${LogFile} 2>&1
  29. echo "[${NewFile}] Backup success ">> ${LogFile}
  30. popd > /dev/null
  31. fi
  32. else
  33. rsync -crazP --delete ${wwwroot_dir}/${WebSite} ${backup_dir}
  34. fi