forked from outroll/vesta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv-update-user-backup-exclusions
executable file
·83 lines (65 loc) · 2.05 KB
/
v-update-user-backup-exclusions
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
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# info: update backup exclusion list
# options: USER FILE
#
# The function for updating backup exclusion list
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
vfile=$2
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
is_file_available() {
if [ ! -e "$vfile" ]; then
echo "Error: file $vfile doesn't exist"
log_event "$E_NOTEXIST" "$EVENT"
exit $E_NOTEXIST
fi
}
is_file_valid() {
exclude="[!$#&;()\]"
vcontent=$(cat $vfile)
if [[ "$vcontent" =~ $exclude ]]; then
echo "Error: invalid characters in the exlusion list"
log_event "$E_INVALID" "$EVENT"
exit $E_INVALID
fi
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'USER FILE'
validate_format 'user' 'vfile'
is_object_valid 'user' 'USER' "$user"
is_file_available
is_file_valid
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Flush variables
WEB=''
DNS=''
MAIL=''
DB=''
CRON=''
USER=''
# Source exclusion list
source $vfile
# Updating exlusion list
echo "WEB='$WEB'" > $USER_DATA/backup-excludes.conf
echo "DNS='$DNS'" >> $USER_DATA/backup-excludes.conf
echo "MAIL='$MAIL'" >> $USER_DATA/backup-excludes.conf
echo "DB='$DB'" >> $USER_DATA/backup-excludes.conf
echo "CRON='$CRON'" >> $USER_DATA/backup-excludes.conf
echo "USER='$USER'" >> $USER_DATA/backup-excludes.conf
chmod 660 $USER_DATA/backup-excludes.conf
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_history "updated exlusion list"
log_event "$OK" "$EVENT"
exit