forked from outroll/vesta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv-rebuild-databases
executable file
·72 lines (53 loc) · 1.82 KB
/
v-rebuild-databases
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
# info: rebuild databases
# options: USER
#
# The function for rebuilding of all databases of a single user.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
# Includes
source $VESTA/func/main.sh
source $VESTA/func/db.sh
source $VESTA/func/rebuild.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'USER'
validate_format 'user'
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Flush counters
U_DATABASES=0
SUSPENDED_DB=0
U_DISK_DB=0
# Starting rebuild loop
for database in $(search_objects 'db' 'SUSPENDED' "no" 'DB'); do
# Get database values
get_database_values
# Switching on db type
case $TYPE in
mysql) rebuild_mysql_database ;;
pgsql) rebuild_pgsql_database ;;
esac
U_DISK_DB=$((U_DISK_DB + U_DISK))
U_DATABASES=$((U_DATABASES + 1))
if [ "$SUSPENDED" = 'yes' ]; then
SUSPENDED_DB=$((SUSPENDED_DB + 1))
fi
done
update_user_value "$user" '$SUSPENDED_DB' "$SUSPENDED_DB"
update_user_value "$user" '$U_DATABASES' "$U_DATABASES"
update_user_value "$user" '$U_DISK_DB' "$U_DISK_DB"
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$EVENT"
exit