/
v-delete-backup-host
executable file
·62 lines (50 loc) · 1.82 KB
/
v-delete-backup-host
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
#!/bin/bash
# info: delete backup ftp server
# options: TYPE [HOST]
#
# example: v-delete-backup-host sftp
#
# This function deletes ftp backup host
#----------------------------------------------------------#
# Variables & Functions #
#----------------------------------------------------------#
# Argument definition
type=$1
# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'TYPE [HOST]'
types=$(echo "$BACKUP_SYSTEM" | sed "s/,/\n/g" | grep "^$type$")
if [ -z "$types" ]; then
echo "Error: invalid backup type"
log_event "$E_INVALID" "$ARGUMENTS"
exit "$E_INVALID"
fi
# Perform verification if read-only mode is enabled
check_hestia_demo_mode
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Deleting host config
rm -f $HESTIA/conf/$type.backup.conf
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
# Updating hestia.conf
bckp=$(echo "$BACKUP_SYSTEM" \
| sed "s/,/\n/g" \
| sed "s/^$type$//" \
| sed "/^$/d" \
| sed ':a;N;$!ba;s/\n/,/g')
sed -i "s/BACKUP_SYSTEM=.*/BACKUP_SYSTEM='$bckp'/g" $HESTIA/conf/hestia.conf
# Logging
$BIN/v-log-action "system" "Info" "Backup" "Removed remote backup host (Host: $host, Type: $type)."
log_event "$OK" "$ARGUMENTS"
exit