You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ED8backup-attachment-rsync-Auto.sh 2.1KB

преди 5 години
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/bash
  2. BAK_Project=ED8
  3. USER=`whoami`
  4. LOG_Folder="/ED/${BAK_Project}/Script_${BAK_Project}/_LOG"
  5. LOG1=/ED/${BAK_Project}/Script_${BAK_Project}/_LOG/${BAK_Project}backup-attachment-rsync-Auto.log
  6. Bak_Folder="/ED/${BAK_Project}/Backup_file"
  7. ATTACH_FILE_Folder="/var/www/html/ed8/data"
  8. CHK_LOG_Folder (){
  9. echo -e "\033[32mCheck the auto backup log saving folder exist: \033[35m($LOG_Folder) \033[0m" | tee -a $LOG1
  10. ls $LOG_Folder > /dev/null 2>&1
  11. if [[ $? != 0 ]]; then
  12. echo -e " >> \033[33mWarning! There is no folder \"$LOG_Folder\". Next will create a new one.\033[0m" | tee -a $LOG1
  13. sudo mkdir -p $LOG_Folder
  14. sudo chown $USER:$USER $LOG_Folder -R
  15. if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m" | tee -a $LOG1; echo; exit; fi
  16. else echo -e " >> \033[34mPass. There is a folder \"$LOG_Folder\". \033[0m" | tee -a $LOG1
  17. fi
  18. }
  19. CHK_Bak_Folder (){
  20. echo -e "\033[32mCheck the local original backup folder exist: \033[35m($Bak_Folder) \033[0m" | tee -a $LOG1
  21. ls $Bak_Folder > /dev/null 2>&1
  22. if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. Backup file saving folder: $Bak_Folder exist, go next.\033[0m" | tee -a $LOG1
  23. else
  24. echo -e " >> \033[33mWarning! There is no Backup file saving folder: $Bak_Folder, next will create a new one automatically.\033[0m" | tee -a $LOG1
  25. sudo mkdir -p $Bak_Folder
  26. sudo chown $USER:$USER $Bak_Folder -R
  27. if [[ $? != 0 ]]; then echo -e " >> \033[41;37mCreate the folder failed. Exit\033[0m" | tee -a $LOG1; echo; exit; fi
  28. fi
  29. }
  30. RSYNC_ATTACHMENT (){
  31. echo -e "\033[32mStarting rsync... \033[0m" | tee -a $LOG1
  32. rsync -a $ATTACH_FILE_Folder $Bak_Folder/
  33. if [[ $? == 0 ]]; then echo -e " >> \033[34mPass. rsync attach file directory ($ATTACH_FILE_Folder).\033[0m" | tee -a $LOG1;
  34. else echo -e " >> \033[31mFail. rsync attach file directory ($ATTACH_FILE_Folder) failed.\033[0m" | tee -a $LOG1
  35. fi; echo
  36. }
  37. ##### Main
  38. echo -e "===== \033[43;30m$(date +"%Y/%m/%d %H:%M:%S")\033[0m ===== \033[36m$0\033[0m =====" | tee -a $LOG1
  39. CHK_LOG_Folder
  40. CHK_Bak_Folder
  41. RSYNC_ATTACHMENT