v-list-user-backup-exclusions 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. # info: list backup exclusions
  3. # options: USER [FORMAT]
  4. #
  5. # The function for obtaining the backup exclusion list
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. format=${2-shell}
  12. USER=''
  13. # Includes
  14. source $VESTA/func/main.sh
  15. # Json function
  16. json_list_backup_xld() {
  17. set -f
  18. echo '{'
  19. fields_count=$(echo "$fields" | wc -w)
  20. i=1
  21. source $USER_DATA/backup-excludes.conf
  22. for field in $fields; do
  23. eval value=$field
  24. j=1
  25. echo -e "\t\"${field//$/}\": {"
  26. for exlcude in ${value//,/ }; do
  27. exlcude_obj=$(echo $exlcude |cut -f 1 -d:)
  28. exclude_param=$(echo $exlcude |sed -e "s/$exlcude_obj://")
  29. if [ "$exlcude_obj" = "$exclude_param" ]; then
  30. exclude_param=''
  31. fi
  32. if [ $j -lt "$(echo ${value//,/ } |wc -w)" ]; then
  33. echo -e "\t\t\"$exlcude_obj\": \"$exclude_param\","
  34. else
  35. echo -e "\t\t\"$exlcude_obj\": \"$exclude_param\""
  36. fi
  37. (( ++j))
  38. done
  39. if [ $i -lt $fields_count ]; then
  40. echo -e "\t},"
  41. else
  42. echo -e "\t}"
  43. fi
  44. (( ++i))
  45. done
  46. echo '}'
  47. }
  48. # Shell function
  49. shell_list_backup_xld() {
  50. source $USER_DATA/backup-excludes.conf
  51. for field in $fields; do
  52. eval value=$field
  53. echo -e "${field//$/}: $value"
  54. done
  55. }
  56. #----------------------------------------------------------#
  57. # Verifications #
  58. #----------------------------------------------------------#
  59. check_args '1' "$#" 'USER [FORMAT]'
  60. validate_format 'user'
  61. is_object_valid 'user' 'USER' "$user"
  62. #----------------------------------------------------------#
  63. # Action #
  64. #----------------------------------------------------------#
  65. # Flush variables
  66. WEB=''
  67. DNS=''
  68. MAIL=''
  69. DB=''
  70. CRON=''
  71. USER=''
  72. # Defining fileds to select
  73. touch $USER_DATA/backup-excludes.conf
  74. fields="\$WEB \$DNS \$MAIL \$DB \$CRON \$USER"
  75. # Listing backup exclusions
  76. case $format in
  77. json) json_list_backup_xld ;;
  78. plain) nohead=1; shell_list_backup_xld ;;
  79. shell) shell_list_backup_xld;;
  80. *) check_args '1' '0' '[FORMAT]'
  81. esac
  82. #----------------------------------------------------------#
  83. # Vesta #
  84. #----------------------------------------------------------#
  85. exit