v-update-user-backup-exclusions 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. # info: update backup exclusion list
  3. # options: USER FILE
  4. #
  5. # The function for updating backup exclusion list
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. vfile=$2
  12. # Includes
  13. source $VESTA/func/main.sh
  14. source $VESTA/conf/vesta.conf
  15. is_file_available() {
  16. if [ ! -e "$vfile" ]; then
  17. check_result $E_NOTEXIST "file $vfile doesn't exist"
  18. fi
  19. }
  20. is_file_valid() {
  21. exclude="[!|#|$|^|&|(|)|{|}|<|>|?|\|\"|;|%|\`]"
  22. if [[ "$(cat $vfile)" =~ $exclude ]]; then
  23. check_result $E_INVALID "invalid characters in the exlusion list"
  24. fi
  25. }
  26. #----------------------------------------------------------#
  27. # Verifications #
  28. #----------------------------------------------------------#
  29. check_args '2' "$#" 'USER FILE'
  30. is_format_valid 'user' 'vfile'
  31. is_object_valid 'user' 'USER' "$user"
  32. is_file_available
  33. is_file_valid
  34. #----------------------------------------------------------#
  35. # Action #
  36. #----------------------------------------------------------#
  37. # Flush variables
  38. WEB=''
  39. DNS=''
  40. MAIL=''
  41. DB=''
  42. CRON=''
  43. USER=''
  44. # Source exclusion list
  45. source $vfile
  46. # Updating exlusion list
  47. echo "WEB='$WEB'" > $USER_DATA/backup-excludes.conf
  48. echo "DNS='$DNS'" >> $USER_DATA/backup-excludes.conf
  49. echo "MAIL='$MAIL'" >> $USER_DATA/backup-excludes.conf
  50. echo "DB='$DB'" >> $USER_DATA/backup-excludes.conf
  51. echo "CRON='$CRON'" >> $USER_DATA/backup-excludes.conf
  52. echo "USER='$USER'" >> $USER_DATA/backup-excludes.conf
  53. chmod 660 $USER_DATA/backup-excludes.conf
  54. #----------------------------------------------------------#
  55. # Vesta #
  56. #----------------------------------------------------------#
  57. # Logging
  58. log_history "updated exlusion list"
  59. log_event "$OK" "$ARGUMENTS"
  60. exit