forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-add-backup-host-restic
More file actions
executable file
·101 lines (83 loc) · 3.09 KB
/
v-add-backup-host-restic
File metadata and controls
executable file
·101 lines (83 loc) · 3.09 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# info: add backup host
# options: TYPE HOST USERNAME PASSWORD [PATH] [PORT]
#
# example: v-add-backup-host sftp backup.acme.com admin 'P4$$w@rD'
# v-add-backup-host b2 bucketName keyID applicationKey
#
# Add a new remote backup location. Currently SFTP, FTP and Backblaze are supported
#----------------------------------------------------------#
# Variables & Functions #
#----------------------------------------------------------#
# Argument definition
repo=$1
snapshots=$2
daily=$3
weekly=$4
monthly=$5
yearly=$6
# CPU Architecture
arch=$(arch)
# 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"
# Fetch current verison B2 CLI tool
source_conf "$HESTIA/install/upgrade/upgrade.conf"
is_negative_one_or_int() {
if [[ "$1" != '-1' ]]; then
is_int_format_valid "$1" "$2"
fi
}
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '6' "$#" "REPO SNAPSHOTS DAILY WEEKLY MONTHLY YEARLY"
format_no_quotes $repo 'Repository host'
is_negative_one_or_int $snapshots 'Snapshots'
is_negative_one_or_int $daily 'Daily snapshots'
is_negative_one_or_int $weekly 'Weekly snapshots'
is_negative_one_or_int $monthly 'Monthly snapshots'
is_negative_one_or_int $yearly 'Yearly snapshots'
# Perform verification if read-only mode is enabled
check_hestia_demo_mode
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Check if Restic is allready installed if not install it ...
if ! which /usr/bin/restic > /dev/null 2>&1; then
apt install restic
fi
# Update restic to last release
restic self-update > /dev/null 2>&1
# Check if $repo starts with a slash
if [[ $repo == "/"* ]]; then
if [ ! -d "$repo" ]; then
check_result $E_NOTEXIST "Directory '$repo' does not exist"
fi
fi
# Check if $repo starts with rclone
if [[ $repo == "rclone:"* ]]; then
# remove rclone: from $repo
repo2=$(echo "$repo" | sed 's/rclone://')
# check if rclone is working
if ! rclone lsd "$repo2" > /dev/null 2>&1; then
check_result $E_NOTEXIST "Rclone repository '$repo2' does not exist"
fi
fi
echo "REPO='$repo'" > /usr/local/hestia/conf/restic.conf
echo "SNAPSHOTS='$snapshots'" >> /usr/local/hestia/conf/restic.conf
echo "KEEP_DAILY='$daily'" >> /usr/local/hestia/conf/restic.conf
echo "KEEP_WEEKLY='$weekly'" >> /usr/local/hestia/conf/restic.conf
echo "KEEP_MONTHLY='$monthly'" >> /usr/local/hestia/conf/restic.conf
echo "KEEP_YEARLY='$yearly'" >> /usr/local/hestia/conf/restic.conf
$BIN/v-change-sys-config-value 'BACKUP_INCREMENTAL' 'yes'
#----------------------------------------------------------#
# Hestia #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$ARGUMENTS"
exit