v_update_db_base_disk 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. # info: update database disk usage
  3. # options: user database
  4. #
  5. # The function recalculates disk usage for speciefic database.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. database=$2
  12. # Importing variables
  13. source $VESTA/conf/vars.conf
  14. source $V_CONF/vesta.conf
  15. source $V_FUNC/shared.func
  16. source $V_FUNC/db.func
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. # Checking arg number
  21. check_args '2' "$#" 'user db_name'
  22. # Checking argument format
  23. format_validation 'user' 'database'
  24. # Checking web system is enabled
  25. is_system_enabled 'db'
  26. # Checking user
  27. is_user_valid
  28. # Checking db existance
  29. is_db_valid
  30. # Checking db is active
  31. is_db_suspended
  32. #----------------------------------------------------------#
  33. # Action #
  34. #----------------------------------------------------------#
  35. # Get some variables we do not have now
  36. db_user=$(get_db_value '$USER')
  37. host=$(get_db_value '$HOST')
  38. type=$(get_db_value '$TYPE')
  39. # Switching on db type
  40. case $type in
  41. mysql) disk_usage=$(get_disk_db_mysql); ret_val="$?" ;;
  42. pgsql) disk_usage=$(get_disk_db_pgsql); ret_val="$?" ;;
  43. esac
  44. # Checking ret_val
  45. if [ "$ret_val" -ne '0' ]; then
  46. exit $ret_val
  47. fi
  48. #----------------------------------------------------------#
  49. # Vesta #
  50. #----------------------------------------------------------#
  51. # Updating disk value in config
  52. update_db_base_value '$U_DISK' "$disk_usage"
  53. # Recalculating user disk space
  54. disk_size=$(get_usr_disk)
  55. update_user_value "$user" '$U_DISK' "$disk_size"
  56. # Logging
  57. log_event 'system' "$V_EVENT"
  58. exit