Skip to content

Commit e23249a

Browse files
committed
backup/restore procedure
1 parent 2364483 commit e23249a

29 files changed

+1638
-583
lines changed

bin/v-add-cron-job

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ is_object_unsuspended 'user' 'USER' "$user"
4040
is_package_full 'CRON_JOBS'
4141
get_next_cronjob
4242
validate_format 'job'
43-
is_object_free 'cron' 'JOB' "$job"
43+
is_object_new 'cron' 'JOB' "$job"
4444

4545

4646
#----------------------------------------------------------#

bin/v-add-database

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ is_system_enabled "$DB_SYSTEM"
4646
is_type_valid "$DB_SYSTEM" "$type"
4747
is_object_valid 'user' 'USER' "$user"
4848
is_object_unsuspended 'user' 'USER' "$user"
49-
is_object_free 'db' 'DB' "$database"
49+
is_object_new 'db' 'DB' "$database"
5050
get_next_dbhost
5151
is_object_valid "../../../conf/$type" 'HOST' "$host"
5252
is_object_unsuspended "../../../conf/$type" 'HOST' "$host"

bin/v-add-database-server

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
# info: add new database server
3-
# options: TYPE HOST PORT DBUSER DBPASS [MAX_DB] [CHARSETS] [TEMPLATE]
3+
# options: TYPE HOST DBUSER DBPASS [MAX_DB] [CHARSETS] [TEMPLATE]
44
#
55
# The function add new database server to the server pool. It supports local
66
# and remote database servers, which is useful for clusters. By adding a host
@@ -16,10 +16,9 @@
1616
# Argument defenition
1717
type=$1
1818
host=$2
19-
port=$3
20-
dbuser=$4
21-
dbpass=$5
22-
A5='******'
19+
dbuser=$3
20+
dbpass=$4
21+
A4='******'
2322
charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8}
2423
template=${8-template1}
2524

@@ -36,9 +35,9 @@ max_db=${6-500}
3635
# Verifications #
3736
#----------------------------------------------------------#
3837

39-
args_usage='TYPE HOST PORT DBUSER DBPASS [MAX_DB] [CHARSETS] [TPL]'
38+
args_usage='TYPE HOST DBUSER DBPASS [MAX_DB] [CHARSETS] [TPL]'
4039
check_args '5' "$#" "$args_usage"
41-
validate_format 'host' 'port' 'dbuser' 'dbpass' 'max_db' 'charsets' 'template'
40+
validate_format 'host' 'dbuser' 'dbpass' 'max_db' 'charsets' 'template'
4241
is_system_enabled "$DB_SYSTEM"
4342
is_type_valid "$DB_SYSTEM" "$type"
4443
is_dbhost_new
@@ -54,10 +53,10 @@ esac
5453

5554
# Concatentating db host string
5655
case $type in
57-
mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass' PORT='$port'";
56+
mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
5857
str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS=''";
5958
str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'";;
60-
pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass' PORT='$port'";
59+
pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
6160
str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'";
6261
str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'";
6362
str="$str TIME='$TIME' DATE='$DATE'";;

bin/v-add-dns-domain-record

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ is_object_unsuspended 'dns' 'DOMAIN' "$domain"
4646
is_package_full 'DNS_RECORDS'
4747
get_next_dnsrecord
4848
validate_format 'id'
49-
is_object_free "dns/$domain" 'ID' "$id"
49+
is_object_new "dns/$domain" 'ID' "$id"
5050

5151

5252
#----------------------------------------------------------#

bin/v-add-domain

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,11 @@ is_object_unsuspended 'user' 'USER' "$user"
3939

4040
# Get ip if it wasn't defined
4141
if [ -z "$ip" ]; then
42-
ip=$(grep -H "OWNER='$user'" $VESTA/data/ips/* 2>/dev/null|head -n1)
43-
ip=$(echo "$ip" | cut -f 7 -d / | cut -f 1 -d :)
42+
ip=$(get_user_ip $user)
4443
if [ -z "$ip" ]; then
45-
# Check shared ips
46-
admin_ips=$(grep -H "OWNER='admin'" $VESTA/data/ips/* 2>/dev/null)
47-
admin_ips=$(echo "$admin_ips" | cut -f 7 -d / | cut -f 1 -d :)
48-
for admin_ip in $admin_ips; do
49-
if [ -z "$ip" ]; then
50-
shared=$(grep "STATUS='shared'" $VESTA/data/ips/$admin_ip)
51-
if [ ! -z "$shared" ]; then
52-
ip=$admin_ip
53-
fi
54-
fi
55-
done
44+
echo "Error: no avaiable IP address"
45+
log_event "$E_NOTEXIST" "$EVENT"
46+
exit $E_NOTEXIST
5647
fi
5748
fi
5849

bin/v-backup-user

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ else
5454
email=$(grep CONTACT $VESTA/data/users/admin/user.conf | cut -f 2 -d \')
5555
fi
5656
if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
57-
mail="$VESTA/web/inc/mail-wrapper.php"
57+
send_mail="$VESTA/web/inc/mail-wrapper.php"
5858
else
59-
mail=$(which mail)
59+
send_mail=$(which mail)
6060
fi
6161

6262
# Check load average
@@ -67,7 +67,7 @@ while [ "$la" -ge "$BACKUP_LA_LIMIT" ]; do
6767
echo
6868
sleep 60
6969
if [ "$i" -ge "15" ]; then
70-
echo "LoadAverage $i is above threshold" | $mail -s "$subj" $email
70+
echo "LoadAverage $i is above threshold" | $send_mail -s "$subj" $email
7171
echo "Error: LA is too high"
7272
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
7373
log_event "$E_LA" "$EVENT"
@@ -79,9 +79,10 @@ done
7979
# Creating temporary directory
8080
tmpdir=$(mktemp -p $BACKUP -d)
8181
if [ "$?" -ne 0 ]; then
82-
echo "Can't create tmp dir $tmpdir" | $mail -s "$subj" $email
82+
echo "Can't create tmp dir $tmpdir" | $send_mail -s "$subj" $email
8383
echo "Error: can't create tmp dir"
8484
log_event "$E_NOTEXIST" "$EVENT"
85+
exit $E_NOTEXIST
8586
fi
8687

8788
# Backingup system configs
@@ -316,7 +317,7 @@ then
316317
cd $HOMEDIR/$user/mail/$domain
317318
accounts=$(ls)
318319
if [ ! -z "$accounts" ]; then
319-
tar -cf $tmpdir/mail/$domain/accounts.tar $accounts
320+
tar -cpf $tmpdir/mail/$domain/accounts.tar $accounts
320321
fi
321322

322323
if [ ! -z "$BACKUP_GZIP" ] && [ ! -z $accounts ]; then
@@ -484,7 +485,8 @@ local_backup(){
484485

485486
if [ "$disk_usage" -ge "$BACKUP_DISK_LIMIT" ]; then
486487
rm -rf $tmpdir
487-
echo "Not enough disk space to run backup" | $mail -s "$subj" $email
488+
echo "Not enough disk space to run backup" |\
489+
$send_mail -s "$subj" $email
488490
echo "Error: Not enough disk space"
489491
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
490492
log_event "$E_DISK" "$EVENT"
@@ -522,7 +524,7 @@ ftp_backup() {
522524
# Checking config
523525
if [ ! -e "$VESTA/conf/ftp.backup.conf" ]; then
524526
ftp_conf_error="Can't open $VESTA/conf/ftp.backup.conf"
525-
echo "$ftp_conf_error" | $mail -s "$subj" $email
527+
echo "$ftp_conf_error" | $send_mail -s "$subj" $email
526528
echo "Error: $VESTA/conf/ftp.backup.conf does not exist"
527529
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
528530
log_event "$E_NOTEXIST" "$EVENT"
@@ -535,7 +537,8 @@ ftp_backup() {
535537
# Checking variables
536538
if [ -z "$HOST" ] || [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then
537539
rm -rf $tmpdir
538-
echo "Can't parse ftp backup configuration" | $mail -s "$subj" $email
540+
echo "Can't parse ftp backup configuration" |\
541+
$send_mail -s "$subj" $email
539542
echo "Error: Parsing error"
540543
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
541544
log_event "$E_PARSING" "$EVENT"
@@ -549,7 +552,8 @@ ftp_backup() {
549552
# Checking ftp connection
550553
if [ ! -z "$(ftpc)" ]; then
551554
rm -rf $tmpdir
552-
echo "Can't login to ftp://$USERNAME@$HOST" | $mail -s "$subj" $email
555+
echo "Can't login to ftp://$USERNAME@$HOST" |\
556+
$send_mail -s "$subj" $email
553557
echo "Error: can't login to ftp"
554558
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
555559
log_event "$E_FTP" "$EVENT"
@@ -562,7 +566,8 @@ ftp_backup() {
562566
ftp_result=$(ftpc "mkdir $ftmpdir" "rm $ftmpdir")
563567
if [ ! -z "$ftp_result" ] ; then
564568
rm -rf $tmpdir
565-
echo "Can't create ftp backup folder" | $mail -s "$subj" $email
569+
echo "Can't create ftp backup folder" |\
570+
$send_mail -s "$subj" $email
566571
echo "Error: cant's create ftp folder"
567572
sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
568573
log_event "$E_FTP" "$EVENT"
@@ -660,7 +665,7 @@ sed -i "/ $user /d" $VESTA/data/queue/backup.pipe
660665
if [ "$notify" != 'no' ]; then
661666
subj="$user → backup has been completed"
662667
email=$(get_user_value '$CONTACT')
663-
echo -e "$msg" | $mail -s "$subj" $email
668+
echo -e "$msg" | $send_mail -s "$subj" $email
664669
fi
665670

666671
# Logging

bin/v-list-database-server

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ is_object_valid "../../conf/$type" 'HOST' "$host"
6969

7070
# Defining fileds to select
7171
conf=$VESTA/conf/$type.conf
72-
fields='$HOST $PORT $CHARSETS $MAX_DB $U_SYS_USERS $U_DB_BASES $TPL $SUSPENDED'
72+
fields='$HOST $CHARSETS $MAX_DB $U_SYS_USERS $U_DB_BASES $TPL $SUSPENDED'
7373
fields="$fields \$TIME \$DATE"
7474

7575
# Listing database

bin/v-list-database-servers

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ check_args '1' "$#" 'TYPE [FORMAT]'
3131

3232
# Defining fileds to select
3333
conf=$VESTA/conf/$type.conf
34-
fields='$HOST $PORT $CHARSETS $MAX_DB $U_SYS_USERS $U_DB_BASES $TPL $SUSPENDED'
34+
fields='$HOST $CHARSETS $MAX_DB $U_SYS_USERS $U_DB_BASES $TPL $SUSPENDED'
3535
fields="$fields \$TIME \$DATE"
3636

3737
# Listing database
3838
case $format in
3939
json) json_list ;;
4040
plain) nohead=1; shell_list;;
41-
shell) fields='$HOST $PORT $MAX_DB $U_DB_BASES $SUSPENDED $DATE';
41+
shell) fields='$HOST $MAX_DB $U_DB_BASES $SUSPENDED $DATE';
4242
shell_list | column -t ;;
4343
*) check_args '2' '0' 'TYPE [FORMAT]'
4444
esac

bin/v-list-user-backup

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/bin/bash
2+
# info: list user backup
3+
# options: USER BACKUP [FORMAT]
4+
#
5+
# The function of obtaining the list of backup parameters. This call, just as
6+
# all v_list_* calls, supports 3 formats - json, shell and plain.
7+
8+
9+
#----------------------------------------------------------#
10+
# Variable&Function #
11+
#----------------------------------------------------------#
12+
13+
# Argument defenition
14+
user=$1
15+
backup=$2
16+
format=${3-shell}
17+
18+
# Includes
19+
source $VESTA/func/main.sh
20+
21+
# Json function
22+
json_list_backup() {
23+
i=1
24+
fileds_count=$(echo "$fields" | wc -w)
25+
line=$(grep "BACKUP='$backup'" $conf)
26+
27+
# Print top bracket
28+
echo '{'
29+
30+
# Assing key=value
31+
eval $line
32+
33+
# Starting output loop
34+
for field in $fields; do
35+
# Parsing key=value
36+
eval value=$field
37+
38+
# Checking first field
39+
if [ "$i" -eq 1 ]; then
40+
echo -e "\t\"$value\": {"
41+
else
42+
if [ "$fileds_count" -eq "$i" ]; then
43+
echo -e "\t\t\"${field//$/}\": \"$value\""
44+
else
45+
echo -e "\t\t\"${field//$/}\": \"$value\","
46+
fi
47+
fi
48+
# Updating iterator
49+
(( ++i))
50+
done
51+
52+
# If there was any output
53+
if [ -n "$value" ]; then
54+
echo -e ' }'
55+
fi
56+
# Printing bottom json bracket
57+
echo -e "}"
58+
}
59+
60+
# Shell function
61+
shell_list_backup() {
62+
line=$(grep "BACKUP='$backup'" $conf)
63+
64+
# Parsing key=value
65+
eval $line
66+
67+
# Print result line
68+
for field in $fields; do
69+
eval key="$field"
70+
echo "${field//$/}: $key "
71+
done
72+
}
73+
74+
75+
#----------------------------------------------------------#
76+
# Verifications #
77+
#----------------------------------------------------------#
78+
79+
check_args '2' "$#" 'USER BACKUP [FORMAT]'
80+
is_object_valid 'user' 'USER' "$user"
81+
is_object_valid 'backup' 'BACKUP' "$backup"
82+
83+
84+
#----------------------------------------------------------#
85+
# Action #
86+
#----------------------------------------------------------#
87+
88+
# Defining config and fields to select
89+
conf=$USER_DATA/backup.conf
90+
91+
fields="\$BACKUP \$TYPE \$SIZE \$VESTA \$PAM \$WEB \$DNS \$DB"
92+
fields="$fields \$MAIL \$CRON \$RUNTIME \$TIME \$DATE"
93+
94+
# Listing backup
95+
case $format in
96+
json) json_list_backup ;;
97+
plain) nohead=1; shell_list_backup ;;
98+
shell) shell_list_backup |column -t ;;
99+
*) check_args '2' '0' 'USER BACKUP [FORMAT]'
100+
esac
101+
102+
103+
#----------------------------------------------------------#
104+
# Vesta #
105+
#----------------------------------------------------------#
106+
107+
exit

bin/v-rebuild-databases

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ user=$1
1616
source $VESTA/conf/vesta.conf
1717
source $VESTA/func/main.sh
1818
source $VESTA/func/db.sh
19+
source $VESTA/func/rebuild.sh
1920

2021

2122
#----------------------------------------------------------#
@@ -34,12 +35,16 @@ is_object_valid 'user' 'USER' "$user"
3435

3536
# Starting rebuild loop
3637
for database in $(search_objects 'db' 'SUSPENDED' "no" 'DB'); do
38+
39+
# Get database values
3740
get_database_values
41+
3842
# Switching on db type
3943
case $TYPE in
4044
mysql) rebuild_mysql_database ;;
4145
pgsql) rebuild_pgsql_database ;;
4246
esac
47+
4348
done
4449

4550

0 commit comments

Comments
 (0)