v-update-user-backup-exclusions 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. vcontent=$(cat $vfile)
  23. if [[ "$vcontent" =~ $exclude ]]; then
  24. check_result $E_INVALID "invalid characters in the exlusion list"
  25. fi
  26. }
  27. #----------------------------------------------------------#
  28. # Verifications #
  29. #----------------------------------------------------------#
  30. check_args '2' "$#" 'USER FILE'
  31. is_format_valid 'user' 'vfile'
  32. is_object_valid 'user' 'USER' "$user"
  33. is_file_available
  34. is_file_valid
  35. #----------------------------------------------------------#
  36. # Action #
  37. #----------------------------------------------------------#
  38. # Flush variables
  39. WEB=''
  40. DNS=''
  41. MAIL=''
  42. DB=''
  43. CRON=''
  44. USER=''
  45. # Source exclusion list
  46. source $vfile
  47. # Updating exlusion list
  48. echo "WEB='$WEB'" > $USER_DATA/backup-excludes.conf
  49. echo "DNS='$DNS'" >> $USER_DATA/backup-excludes.conf
  50. echo "MAIL='$MAIL'" >> $USER_DATA/backup-excludes.conf
  51. echo "DB='$DB'" >> $USER_DATA/backup-excludes.conf
  52. echo "CRON='$CRON'" >> $USER_DATA/backup-excludes.conf
  53. echo "USER='$USER'" >> $USER_DATA/backup-excludes.conf
  54. chmod 660 $USER_DATA/backup-excludes.conf
  55. #----------------------------------------------------------#
  56. # Vesta #
  57. #----------------------------------------------------------#
  58. # Logging
  59. log_history "updated exlusion list"
  60. log_event "$OK" "$ARGUMENTS"
  61. exit