Skip to content

Commit c2f05fd

Browse files
authored
Fix multiple smaller bugs with incremental backups (hestiacp#4861)
* Improve check to make sure repo is writeable Also fix bug when admin user != admin * Make Incremental backups enabled available for in v-list-users * FIx bug in v-add-user-package not saving change incremental backup * Check if repo is writeable Check if folder exists or check if rclone repo exists
1 parent 9902200 commit c2f05fd

File tree

7 files changed

+40
-8
lines changed

7 files changed

+40
-8
lines changed

bin/v-add-backup-host-restic

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ fi
6565
# Update restic to last release
6666
restic self-update > /dev/null 2>&1
6767

68+
# Check if $repo starts with a slash
69+
if [[ $repo == "/"* ]]; then
70+
if [ ! -d "$repo" ]; then
71+
check_result $E_NOTEXIST "Directory '$repo' does not exist"
72+
fi
73+
fi
74+
75+
# Check if $repo starts with rclone
76+
if [[ $repo == "rclone:"* ]]; then
77+
# remove rclone: from $repo
78+
repo=$(echo "$repo" | sed 's/rclone://')
79+
# check if rclone is working
80+
if ! rclone lsd "$repo" > /dev/null 2>&1; then
81+
check_result $E_NOTEXIST "Rclone repository '$repo' does not exist"
82+
fi
83+
fi
84+
6885
echo "REPO='$repo'" > /usr/local/hestia/conf/restic.conf
6986
echo "SNAPSHOTS='$snapshots'" >> /usr/local/hestia/conf/restic.conf
7087
echo "KEEP_DAILY='$daily'" >> /usr/local/hestia/conf/restic.conf

bin/v-add-user-package

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ is_package_consistent() {
7171
is_int_format_valid "$BANDWIDTH" 'BANDWIDTH'
7272
fi
7373
is_int_format_valid "$BACKUPS" 'BACKUPS'
74-
is_boolean_format_valid "$BACKUPS_INCREMENTAL" 'BACKUP_INCREMENTAL'
74+
is_boolean_format_valid "$BACKUPS_INCREMENTAL" 'BACKUPS_INCREMENTAL'
7575
if [ -n "$WEB_TEMPLATE" ]; then
7676
is_web_template_valid "$WEB_TEMPLATE"
7777
fi
@@ -150,7 +150,7 @@ BANDWIDTH='$BANDWIDTH'
150150
NS='$NS'
151151
SHELL='$SHELL'
152152
BACKUPS='$BACKUPS'
153-
BACKUPS_INCREMENTAL='$BACKUP_INCREMENTAL'
153+
BACKUPS_INCREMENTAL='$BACKUPS_INCREMENTAL'
154154
TIME='$time'
155155
DATE='$date'
156156
" > "$HESTIA/data/packages/$package.pkg"

bin/v-backup-user-config

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ check_hestia_demo_mode
4646
# Get current time
4747
start_time=$(date '+%s')
4848

49-
# Set notification email and subject
50-
subj="$user → backup failed"
51-
email=$(grep CONTACT "$HESTIA/data/users/admin/user.conf" | cut -f 2 -d \')
52-
5349
tmpdir="/home/$user/backup/"
5450

5551
# We delete the backup dir first make sure all old database has been cleared

bin/v-backup-user-restic

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ check_hestia_demo_mode
4444
# Action #
4545
#----------------------------------------------------------#
4646

47+
# Set notification email and subject
48+
subj="$user → backup failed"
49+
email=$(grep CONTACT "$HESTIA/data/users/$ROOT_USER/user.conf" | cut -f 2 -d \')
50+
4751
source_conf $HESTIA/conf/restic.conf
4852

4953
if [ ! -f "$USER_DATA/restic.conf" ]; then
@@ -54,11 +58,24 @@ if [ ! -f "$USER_DATA/restic.conf" ]; then
5458
if [ $? -ne 0 ]; then
5559
check_result $E_CONNECT "Unable to create restic repo"
5660
fi
61+
else
62+
# Check if repo exists and is accessible with restic key
63+
restic --repo "$REPO$user" --password-file $USER_DATA/restic.conf --json dump $snapshot /home/$user/backup/backup.conf > /home/$user/tmp/backup.conf
64+
if [ $? -ne 0 ]; then
65+
# Send an email
66+
echo "Unable to open restic backup. It might not exists or key is incorrect" | $SENDMAIL -s "$subj" "$email" "yes"
67+
check_result $E_CONNECT "Unable to access restic repo"
68+
fi
69+
rm /home/$user/tmp/backup.conf
5770
fi
5871

5972
# create backup of the user.conf an database
6073
$BIN/v-backup-user-config $user
6174
restic --repo "$REPO$user" --password-file $USER_DATA/restic.conf backup /home/$user
75+
if [ $? -ne 0 ]; then
76+
echo "Unable to create the backup" | $SENDMAIL -s "$subj" "$email" "yes"
77+
check_result $E_BACKUP "Unable to backup user"
78+
fi
6279

6380
if [[ -n "$SNAPSHOTS" && "$SNAPSHOTS" -ge 0 ]]; then
6481
restic_prune="$restic_prune --keep-last $SNAPSHOTS"

bin/v-list-user

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ json_list() {
7878
"U_DATABASES": "'$U_DATABASES'",
7979
"U_CRON_JOBS": "'$U_CRON_JOBS'",
8080
"U_BACKUPS": "'$U_BACKUPS'",
81+
"BACKUPS_INCREMENTAL": "'$BACKUPS_INCREMENTAL'",
8182
"LANGUAGE": "'$LANGUAGE'",
8283
"THEME": "'$THEME'",
8384
"NOTIFICATIONS": "'$NOTIFICATIONS'",

web/list/backup/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
$data = array_reverse($data, true);
1616
}
1717
unset($output);
18-
1918
render_page($user, $TAB, "list_backup");
2019
} else {
2120
exec(

web/templates/pages/list_backup.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
<a href="/schedule/backup/?token=<?= $_SESSION["token"] ?>" class="button button-secondary"><i class="fas fa-circle-plus icon-green"></i><?= _("Create Backup") ?></a>
77
<a href="/list/backup/exclusions/" class="button button-secondary"><i class="fas fa-folder-minus icon-orange"></i><?= _("Backup Exclusions") ?></a>
88
<?php } ?>
9-
<a href="/list/backup/incremental/" class="button button-secondary"><i class="fas fa-vault icon-blue"></i><?= _("Incremental Backups") ?></a>
9+
<?php if ($panel[$user_plain]['BACKUPS_INCREMENTAL'] === 'yes') { ?>
10+
<a href="/list/backup/incremental/" class="button button-secondary"><i class="fas fa-vault icon-blue"></i><?= _("Incremental Backups") ?></a>
11+
<?php } ?>
1012
</div>
1113
<div class="toolbar-right">
1214
<?php if ($read_only !== "true") { ?>

0 commit comments

Comments
 (0)