Skip to content

Commit 95e2fe5

Browse files
authored
Multiple Bug fixes UI restic (hestiacp#4863)
* Repo with rclone got overwritten * List repo snapshots instead * Allow restore full snapshot * Allow bulk delete snapshot * Use correct folder name * Add possibility to delete snapshot * 2 mandetory arguments * Fix bulk restore * Set some values to test the preformance * Slow down backup process * Mute outoutput * Export it * Update example
1 parent 37719aa commit 95e2fe5

File tree

7 files changed

+145
-13
lines changed

7 files changed

+145
-13
lines changed

bin/v-add-backup-host-restic

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ fi
7575
# Check if $repo starts with rclone
7676
if [[ $repo == "rclone:"* ]]; then
7777
# remove rclone: from $repo
78-
repo=$(echo "$repo" | sed 's/rclone://')
78+
repo2=$(echo "$repo" | sed 's/rclone://')
7979
# 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"
80+
if ! rclone lsd "$repo2" > /dev/null 2>&1; then
81+
check_result $E_NOTEXIST "Rclone repository '$repo2' does not exist"
8282
fi
8383
fi
8484

bin/v-backup-user-restic

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# info: backup system user with all its objects to restic backup
33
# options: USER NOTIFY
44
#
5-
# example: v-backup-user admin yes
5+
# example: v-backup-user-restic admin yes
6+
#
7+
# Backup user with all its objects to restic backup. If the repo doesn't exists a new one will be created.
68
#
7-
# This function is used for backing up user with all its domains and databases.
89

910
#----------------------------------------------------------#
1011
# Variables & Functions #
@@ -60,18 +61,20 @@ if [ ! -f "$USER_DATA/restic.conf" ]; then
6061
fi
6162
else
6263
# 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+
restic --repo "$REPO$user" --password-file $USER_DATA/restic.conf --json snapshots > /dev/null
6465
if [ $? -ne 0 ]; then
6566
# Send an email
6667
echo "Unable to open restic backup. It might not exists or key is incorrect" | $SENDMAIL -s "$subj" "$email" "yes"
6768
check_result $E_CONNECT "Unable to access restic repo"
6869
fi
69-
rm /home/$user/tmp/backup.conf
7070
fi
7171

7272
# create backup of the user.conf an database
7373
$BIN/v-backup-user-config $user
74-
restic --repo "$REPO$user" --password-file $USER_DATA/restic.conf backup /home/$user
74+
export GOMAXPROCS=2
75+
export RESTIC_READ_CONCURRENCY=2
76+
ionice -c2 -n7 nice -n 19 restic --repo "$REPO$user" --limit-upload 10240 --read-concurrency 2 --password-file $USER_DATA/restic.conf backup /home/$user
77+
7578
if [ $? -ne 0 ]; then
7679
echo "Unable to create the backup" | $SENDMAIL -s "$subj" "$email" "yes"
7780
check_result $E_BACKUP "Unable to backup user"

bin/v-delete-user-backup-restic

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
# info: delete a specific user snapshot from restic backup repository.
3+
# options: USER SNAPSHOT
4+
#
5+
# example: v-delete-user-backup-restic admin snapshot
6+
#
7+
# Delete a specific user snapshot from restic backup repository. It doesn't take in account any pruning done by the retention policy.
8+
# This function is used for deleting a specific user snapshot from restic backup repository.
9+
10+
#----------------------------------------------------------#
11+
# Variables & Functions #
12+
#----------------------------------------------------------#
13+
14+
# Argument definition
15+
user=$1
16+
snapshot=$2
17+
18+
# Includes
19+
# shellcheck source=/etc/hestiacp/hestia.conf
20+
source /etc/hestiacp/hestia.conf
21+
# shellcheck source=/usr/local/hestia/func/main.sh
22+
source $HESTIA/func/main.sh
23+
# shellcheck source=/usr/local/hestia/func/domain.sh
24+
source $HESTIA/func/domain.sh
25+
# shellcheck source=/usr/local/hestia/func/ip.sh
26+
source $HESTIA/func/ip.sh
27+
# shellcheck source=/usr/local/hestia/func/rebuild.sh
28+
source $HESTIA/func/rebuild.sh
29+
# shellcheck source=/usr/local/hestia/func/syshealth.sh
30+
source $HESTIA/func/syshealth.sh
31+
# load config file
32+
source_conf "$HESTIA/conf/hestia.conf"
33+
34+
source_conf $HESTIA/conf/restic.conf
35+
36+
#----------------------------------------------------------#
37+
# Verifications #
38+
#----------------------------------------------------------#
39+
40+
args_usage='USER SNAPSHOT'
41+
check_args '2' "$#" "$args_usage"
42+
is_format_valid 'user'
43+
is_object_valid 'user' 'USER' "$user"
44+
45+
source_conf $HESTIA/conf/restic.conf
46+
47+
#----------------------------------------------------------#
48+
# Action #
49+
#----------------------------------------------------------#
50+
51+
tmpdir=$(mktemp -p /home/$user/tmp/ -d)
52+
if [ ! -f "$tmpdir/backup.conf" ]; then
53+
restic --repo "$REPO$user" --password-file "$USER_DATA/restic.conf" dump "$snapshot" "/home/$user/backup/backup.conf" > "$tmpdir/backup.conf"
54+
if [ "$?" -ne 0 ]; then
55+
check_result "$E_NOTEXIST" "Unable to download from snapshot"
56+
fi
57+
fi
58+
59+
restic --repo "$REPO$user" --password-file "$USER_DATA/restic.conf" forget "$snapshot"
60+
61+
#----------------------------------------------------------#
62+
# Hestia #
63+
#----------------------------------------------------------#
64+
65+
sed -i "/v-delete-user-backup-restic '$user' '$snapshot' /d" $HESTIA/data/queue/backup.pipe
66+
67+
# Logging
68+
$BIN/v-log-action "system" "Info" "Backup" "Restic snapshot successfully deleted (User: $user, Snapshot: $snapshot)."
69+
$BIN/v-log-action "$user" "Info" "Backup" "Restic snapshot successfully deleted (Snapshot: $snapshot)."
70+
log_event "$OK" "$ARGUMENTS"
71+
exit
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
use function Hestiacp\quoteshellarg\quoteshellarg;
3+
4+
ob_start();
5+
include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
6+
7+
if (empty($_POST["backup"])) {
8+
header("Location: /list/backup/incremental/");
9+
exit();
10+
}
11+
if (empty($_POST["action"])) {
12+
header("Location: /list/backup/incremental/");
13+
exit();
14+
}
15+
16+
$backup = $_POST["backup"];
17+
$action = $_POST["action"];
18+
19+
// Check token
20+
verify_csrf($_POST);
21+
22+
switch ($action) {
23+
case "delete":
24+
$cmd = "v-delete-user-backup-restic";
25+
break;
26+
default:
27+
header("Location: /list/backup/");
28+
exit();
29+
}
30+
31+
foreach ($backup as $value) {
32+
$value = quoteshellarg($value);
33+
exec(HESTIA_CMD . $cmd . " " . $user . " " . $value, $output, $return_var);
34+
if ($return_var != 0) {
35+
$_SESSION["error_msg"] = implode("<br>", $output);
36+
if (empty($_SESSION["error_msg"])) {
37+
$_SESSION["error_msg"] = _("Error: Hestia did not return any output.");
38+
}
39+
}
40+
}
41+
42+
header("Location: /list/backup/incremental/");

web/schedule/restore/incremental/index.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
$output,
2020
$return_var,
2121
);
22+
if ($return_var == 0) {
23+
$_SESSION["error_msg"] = _(
24+
"Task has been added to the queue. You will receive an email notification when your restore has been completed.",
25+
);
26+
} else {
27+
$_SESSION["error_msg"] = implode("<br>", $output);
28+
if (empty($_SESSION["error_msg"])) {
29+
$_SESSION["error_msg"] = _("Error: Hestia did not return any output.");
30+
}
31+
if ($return_var == 4) {
32+
$_SESSION["error_msg"] = _(
33+
"An existing restoration task is already running. Please wait for it to finish before launching it again.",
34+
);
35+
}
36+
}
2237
} else {
2338
exec(
2439
HESTIA_CMD .

web/templates/pages/list_backup_detail_incremental.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
<div class="toolbar-buttons">
55
<a class="button button-secondary button-back js-button-back" href="/list/backup/incremental/"><i class="fas fa-arrow-left icon-blue"></i><?= _("Back") ?></a>
66
<?php if ($read_only !== "true") { ?>
7-
<a href="/schedule/restore/incremental/?token=<?= $_SESSION["token"] ?>&backup=<?= htmlentities($_GET["backup"]) ?>" class="button button-secondary"><i class="fas fa-arrow-rotate-left icon-green"></i><?= _("Restore All") ?></a>
7+
<a href="/schedule/restore/incremental/?token=<?= $_SESSION["token"] ?>&snapshot=<?= htmlentities($_GET["snapshot"]) ?>" class="button button-secondary"><i class="fas fa-arrow-rotate-left icon-green"></i><?= _("Restore All") ?></a>
88
<?php } ?>
99
</div>
1010
<div class="toolbar-right">
1111
<?php if ($read_only !== "true") { ?>
12-
<form x-data x-bind="BulkEdit" action="/bulk/backup/incremental" method="post">
12+
<form x-data x-bind="BulkEdit" action="/bulk/restore/incremental/" method="post">
1313
<input type="hidden" name="token" value="<?= $_SESSION["token"] ?>">
14+
<input type="hidden" name="snapshot" value="<?= htmlentities($_GET["snapshot"]) ?>">
1415
<select class="form-select" name="action">
1516
<option value=""><?= _("Apply to selected") ?></option>
1617
<option value="restore"><?= _("Restore Snapshot") ?></option>

web/templates/pages/list_backup_incremental.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
</div>
1111
<div class="toolbar-right">
1212
<?php if ($read_only !== "true") { ?>
13-
<form x-data x-bind="BulkEdit" action="/bulk/backup/incremental" method="post">
13+
<form x-data x-bind="BulkEdit" action="/bulk/backup/incremental/" method="post">
1414
<input type="hidden" name="token" value="<?= $_SESSION["token"] ?>">
1515
<select class="form-select" name="action">
1616
<option value=""><?= _("Apply to selected") ?></option>
17-
<option value="delete"><?= _("Delete Snapshot") ?></option>
17+
<option value="delete"><?= _("Delete") ?></option>
1818
</select>
1919
<button type="submit" class="toolbar-input-submit" title="<?= _("Apply to selected") ?>">
2020
<i class="fas fa-arrow-right"></i>
@@ -59,7 +59,7 @@
5959
<div class="units-table-row js-unit">
6060
<div class="units-table-cell">
6161
<div>
62-
<input id="check<?= $i ?>" class="js-unit-checkbox" type="checkbox" title="<?= _("Select") ?>" name="backup[]" value="<?= $key ?>" <?= $display_mode ?>> <span class="u-hide-desktop"><label for="check<?= $i ?>" class="u-hide-desktop"><?= _("Select") ?></label></span>
62+
<input id="check<?= $i ?>" class="js-unit-checkbox" type="checkbox" title="<?= _("Select") ?>" name="backup[]" value="<?= $value['short_id'] ?>" <?= $display_mode ?>> <span class="u-hide-desktop"><label for="check<?= $i ?>" class="u-hide-desktop"><?= _("Select") ?></label></span>
6363
</div>
6464
</div>
6565
<div class="units-table-cell units-table-heading-cell u-text-bold">

0 commit comments

Comments
 (0)