forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv-backup-user-restic
More file actions
executable file
·97 lines (82 loc) · 3.27 KB
/
v-backup-user-restic
File metadata and controls
executable file
·97 lines (82 loc) · 3.27 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
#!/bin/bash
# info: backup system user with all its objects to restic backup
# options: USER NOTIFY
#
# example: v-backup-user admin yes
#
# This function is used for backing up user with all its domains and databases.
#----------------------------------------------------------#
# Variables & Functions #
#----------------------------------------------------------#
# Argument definition
user=$1
notify=${2-no}
# 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
# shellcheck source=/usr/local/hestia/func/domain.sh
source $HESTIA/func/domain.sh
# shellcheck source=/usr/local/hestia/func/db.sh
source $HESTIA/func/db.sh
# shellcheck source=/usr/local/hestia/func/backup.sh
source $HESTIA/func/backup.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'USER'
is_format_valid 'user'
is_system_enabled "$BACKUP_SYSTEM" 'BACKUP_SYSTEM'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
is_incremental_backup_enabled
# Perform verification if read-only mode is enabled
check_hestia_demo_mode
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
source_conf $HESTIA/conf/restic.conf
if [ ! -f "$USER_DATA/restic.conf" ]; then
password=$(generate_password '' '32')
echo "$password" > $USER_DATA/restic.conf
restic --repo "$REPO$user" --password-file $USER_DATA/restic.conf init
if [ $? -ne 0 ]; then
check_result $E_CONNECT "Unable to create restic repo"
fi
fi
# create backup of the user.conf an database
$BIN/v-backup-user-config $user
restic --repo "$REPO$user" --password-file $USER_DATA/restic.conf backup /home/$user
if [[ -n "$SNAPSHOTS" && "$SNAPSHOTS" -ge 0 ]]; then
restic_prune="$restic_prune --keep-last $SNAPSHOTS"
fi
if [[ -n "$KEEP_DAILY" && "$KEEP_DAILY" -ge 0 ]]; then
restic_prune="$restic_prune --keep-daily $KEEP_DAILY"
fi
if [[ -n "$KEEP_WEEKLY" && "$KEEP_WEEKLY" -ge 0 ]]; then
restic_prune="$restic_prune --keep-weekly $KEEP_WEEKLY"
fi
if [[ -n "$KEEP_MONTLY" && "$KEEP_MONTLY" -ge 0 ]]; then
restic_prune="$restic_prune --keep-monthly $KEEP_MONTLY"
fi
if [[ -n "$KEEP_YEARLY" && "$KEEP_YEARLY" -ge 0 ]]; then
restic_prune="$restic_prune --keep-yearly $KEEP_YEARLY"
fi
restic --repo "$REPO$user" --password-file $USER_DATA/restic.conf forget $restic_prune --prune
# Send notification
if [ -e "$BACKUP/$user.log" ] && [ "$notify" = "yes" ]; then
subj="$user → backup has been completed"
email=$(get_user_value '$CONTACT')
cat $BACKUP/$user.log | $SENDMAIL -s "$subj" "$email" "$notify"
$BIN/v-add-user-notification "$user" "Snapshot created successfully" "Snap shot of user successfully created"
fi
# Deleting task from queue
sed -i "/v-backup-user-restic $user /d" $HESTIA/data/queue/backup.pipe
# Logging
$BIN/v-log-action "$user" "Info" "Backup" "Backup created."
$BIN/v-log-action "system" "Info" "Backup" "Backup created (User: $user)."
log_event "$OK" "$ARGUMENTS"
exit