Преглед изворни кода

Fix multiple smaller bugs with incremental backups (#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
Jaap Marcus пре 1 година
родитељ
комит
c2f05fd0c1

+ 17 - 0
bin/v-add-backup-host-restic

@@ -65,6 +65,23 @@ 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
+	repo=$(echo "$repo" | sed 's/rclone://')
+	# check if rclone is working
+	if ! rclone lsd "$repo" > /dev/null 2>&1; then
+		check_result $E_NOTEXIST "Rclone repository '$repo' 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

+ 2 - 2
bin/v-add-user-package

@@ -71,7 +71,7 @@ is_package_consistent() {
 		is_int_format_valid "$BANDWIDTH" 'BANDWIDTH'
 	fi
 	is_int_format_valid "$BACKUPS" 'BACKUPS'
-	is_boolean_format_valid "$BACKUPS_INCREMENTAL" 'BACKUP_INCREMENTAL'
+	is_boolean_format_valid "$BACKUPS_INCREMENTAL" 'BACKUPS_INCREMENTAL'
 	if [ -n "$WEB_TEMPLATE" ]; then
 		is_web_template_valid "$WEB_TEMPLATE"
 	fi
@@ -150,7 +150,7 @@ BANDWIDTH='$BANDWIDTH'
 NS='$NS'
 SHELL='$SHELL'
 BACKUPS='$BACKUPS'
-BACKUPS_INCREMENTAL='$BACKUP_INCREMENTAL'
+BACKUPS_INCREMENTAL='$BACKUPS_INCREMENTAL'
 TIME='$time'
 DATE='$date'
 " > "$HESTIA/data/packages/$package.pkg"

+ 0 - 4
bin/v-backup-user-config

@@ -46,10 +46,6 @@ check_hestia_demo_mode
 # Get current time
 start_time=$(date '+%s')
 
-# Set notification email and subject
-subj="$user → backup failed"
-email=$(grep CONTACT "$HESTIA/data/users/admin/user.conf" | cut -f 2 -d \')
-
 tmpdir="/home/$user/backup/"
 
 # We delete the backup dir first make sure all old database has been cleared

+ 17 - 0
bin/v-backup-user-restic

@@ -44,6 +44,10 @@ check_hestia_demo_mode
 #                       Action                             #
 #----------------------------------------------------------#
 
+# Set notification email and subject
+subj="$user → backup failed"
+email=$(grep CONTACT "$HESTIA/data/users/$ROOT_USER/user.conf" | cut -f 2 -d \')
+
 source_conf $HESTIA/conf/restic.conf
 
 if [ ! -f "$USER_DATA/restic.conf" ]; then
@@ -54,11 +58,24 @@ if [ ! -f "$USER_DATA/restic.conf" ]; then
 	if [ $? -ne 0 ]; then
 		check_result $E_CONNECT "Unable to create restic repo"
 	fi
+else
+	# Check if repo exists and is accessible with restic key
+	restic --repo "$REPO$user" --password-file $USER_DATA/restic.conf --json dump $snapshot /home/$user/backup/backup.conf > /home/$user/tmp/backup.conf
+	if [ $? -ne 0 ]; then
+		# Send an email
+		echo "Unable to open restic backup. It might not exists or key is incorrect" | $SENDMAIL -s "$subj" "$email" "yes"
+		check_result $E_CONNECT "Unable to access restic repo"
+	fi
+	rm /home/$user/tmp/backup.conf
 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 [ $? -ne 0 ]; then
+	echo "Unable to create the backup" | $SENDMAIL -s "$subj" "$email" "yes"
+	check_result $E_BACKUP "Unable to backup user"
+fi
 
 if [[ -n "$SNAPSHOTS" && "$SNAPSHOTS" -ge 0 ]]; then
 	restic_prune="$restic_prune --keep-last $SNAPSHOTS"

+ 1 - 0
bin/v-list-user

@@ -78,6 +78,7 @@ json_list() {
         "U_DATABASES": "'$U_DATABASES'",
         "U_CRON_JOBS": "'$U_CRON_JOBS'",
         "U_BACKUPS": "'$U_BACKUPS'",
+        "BACKUPS_INCREMENTAL": "'$BACKUPS_INCREMENTAL'",
         "LANGUAGE": "'$LANGUAGE'",
         "THEME": "'$THEME'",
         "NOTIFICATIONS": "'$NOTIFICATIONS'",

+ 0 - 1
web/list/backup/index.php

@@ -15,7 +15,6 @@ if (empty($_GET["backup"])) {
 		$data = array_reverse($data, true);
 	}
 	unset($output);
-
 	render_page($user, $TAB, "list_backup");
 } else {
 	exec(

+ 3 - 1
web/templates/pages/list_backup.php

@@ -6,7 +6,9 @@
 				<a href="/schedule/backup/?token=<?= $_SESSION["token"] ?>" class="button button-secondary"><i class="fas fa-circle-plus icon-green"></i><?= _("Create Backup") ?></a>
 				<a href="/list/backup/exclusions/" class="button button-secondary"><i class="fas fa-folder-minus icon-orange"></i><?= _("Backup Exclusions") ?></a>
 			<?php } ?>
-			<a href="/list/backup/incremental/" class="button button-secondary"><i class="fas fa-vault icon-blue"></i><?= _("Incremental Backups") ?></a>
+			<?php if ($panel[$user_plain]['BACKUPS_INCREMENTAL'] === 'yes') { ?>
+				<a href="/list/backup/incremental/" class="button button-secondary"><i class="fas fa-vault icon-blue"></i><?= _("Incremental Backups") ?></a>
+			<?php } ?>
 		</div>
 		<div class="toolbar-right">
 			<?php if ($read_only !== "true") { ?>