v-list-backup-host 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. # info: list backup host
  3. # options: TYPE [FORMAT]
  4. #
  5. # The function for obtaining the list of backup host parameters.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. TYPE=$1
  11. format=${2-shell}
  12. # Includes
  13. source $VESTA/func/main.sh
  14. # Json function
  15. json_list_ftp_host() {
  16. i=1
  17. fileds_count=$(echo "$fields" | wc -w)
  18. ip_data=$(cat $VESTA/conf/$TYPE.backup.conf)
  19. echo '{'
  20. echo -e "\t\"$TYPE\": {"
  21. eval $ip_data
  22. for field in $fields; do
  23. eval value=$field
  24. if [ $fileds_count -eq $i ]; then
  25. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  26. else
  27. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  28. fi
  29. (( ++i))
  30. done
  31. if [ -n "$value" ]; then
  32. echo -e ' }'
  33. fi
  34. echo -e '}'
  35. }
  36. # Shell function
  37. shell_list_ftp_host() {
  38. line=$(cat $VESTA/conf/$TYPE.backup.conf)
  39. eval $line
  40. for field in $fields; do
  41. eval key="$field"
  42. if [ -z "$key" ]; then
  43. key='NULL'
  44. fi
  45. echo "${field//$/}: $key "
  46. done
  47. }
  48. #----------------------------------------------------------#
  49. # Verifications #
  50. #----------------------------------------------------------#
  51. check_args '1' "$#" 'TYPE [FORMAT]'
  52. #----------------------------------------------------------#
  53. # Action #
  54. #----------------------------------------------------------#
  55. if [ ! -e "$VESTA/conf/$TYPE.backup.conf" ]; then
  56. exit
  57. fi
  58. # Defining fileds to select
  59. fields='$HOST $USERNAME $PORT $TYPE $BPATH $TIME $DATE'
  60. # Listing database
  61. case $format in
  62. json) json_list_ftp_host ;;
  63. plain) nohead=1; shell_list_ftp_host;;
  64. shell) shell_list_ftp_host | column -t ;;
  65. *) check_args '2' '0' '[FORMAT]'
  66. esac
  67. #----------------------------------------------------------#
  68. # Vesta #
  69. #----------------------------------------------------------#
  70. exit