|
| 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 |
0 commit comments