Advertisement
Guest User

Untitled

a guest
Jan 19th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
  4. # PLEASE UPDATE CONFIG BELOW #
  5. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
  6.  
  7. # local file backup directory
  8. path='/home/hary/backup/app'
  9. # ftp/sftp config
  10. ftptype="sftp" #ftp
  11. ftppath="/home/hary/backup/app"
  12. ftpuser="hary"
  13. ftppassword=""
  14. ftpserver="192.168.88.28"
  15. ftpport="4637"
  16. # app source path
  17. appdirpath="/app/development"
  18. # app backup
  19. appnames="ib cm"
  20.  
  21. # backup file lifetime before delete
  22. lifetime=7
  23.  
  24. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
  25. # PLEASE UPDATE CONFIG ABOVE #
  26. #@@@@@@@@@@@@@@@@@@@@@@@@@@@@#
  27.  
  28. archive='.tgz'
  29. tgl=`/bin/date +%Y%m%d`
  30. jam=`/bin/date +%H%M%S`
  31. tgljam=${tgl}_${jam}
  32. for app in ${appnames}; do
  33. filepath=${path}/${app}
  34. echo "Checking file lifetime ${filepath}"
  35. #find ${filepath} -maxdepth 1 -type d -mtime +7 -exec rm -rf {} \;
  36. find ${filepath} -maxdepth 1 -type f -mtime +${lifetime} -exec rm -rf {} \;
  37. filename=${app}_${tgljam}${archive}
  38. if [ ! -d ${filepath} ]; then /bin/mkdir -p ${filepath}; fi
  39.  
  40. cd ${filepath}
  41. echo "Create/compress application backup ${filename}"
  42.  
  43. if [ "${archive}" == ".tar.gz" ]
  44. then
  45. cd ${appdirpath}
  46. tar -czf ${filepath}/${filename} ${app} -R
  47. elif [ "${archive}" == ".tgz" ]
  48. then
  49. cd ${appdirpath}
  50. tar -czf ${filepath}/${filename} ${app} -R
  51. elif [ "${archive}" == ".zip" ]
  52. then
  53. zip -rv9 ${filepath}/${filename} "${appdirpath}/${app}"
  54. else
  55. echo "unknown archive type ${archive}"
  56. fi
  57.  
  58. #touch ${filename}
  59. echo "Upload application backup ${filename}"
  60. if [ "${ftptype}" == "ftp" ]
  61. then
  62. lftp -u ${ftpuser},${ftppassword} -p ${ftpport} -e "set ftp:passive-mode on; mkdir -p ${ftppath}/${app}/${tgl}; cd ${ftppath}/${app}/${tgl}; mput ${filepath}/${filename}; quit" ${ftpserver}
  63. elif [ "${ftptype}" == "sftp" ]
  64. then
  65. lftp sftp://${ftpuser}:${ftppassword}@${ftpserver} -p ${ftpport} -e "mkdir -p ${ftppath}/${app}/${tgl}; cd ${ftppath}/${app}/${tgl}; put ${filepath}/${filename}; bye"
  66. else
  67. echo "unknown ftp type ${ftptype}"
  68. fi
  69. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement