From 5e52dbbe052d19d7a4e8e42a57849225b2b71261 Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Tue, 25 May 2021 19:12:54 +0200 Subject: [PATCH] update restore.sh and restic plugin --- plugins/transfer/restic.sh | 6 +-- restore.sh | 75 +++++++++++++++----------------------- 2 files changed, 32 insertions(+), 49 deletions(-) diff --git a/plugins/transfer/restic.sh b/plugins/transfer/restic.sh index 6f916cd..9598f4a 100644 --- a/plugins/transfer/restic.sh +++ b/plugins/transfer/restic.sh @@ -218,19 +218,17 @@ color cmd t_cmdShowVolumes color reset - showPrompt "ID of the snapshot to restore from [$RESTORE_ITEM] >" + showPrompt "ID of the snapshot or \"latest\" to restore from [$RESTORE_ITEM] >" read _selid test -z "$_selid" && _selid=$RESTORE_ITEM RESTORE_ITEM=$_selid echo using \"$RESTORE_ITEM\" + RESTORE_ITEMINFO=$( t_cmdShowVolumes | grep "^$RESTORE_ITEM" | awk '{ print $2 " " $3} ' ) echo } # set a filter to reduce count of files to restore function t_restoreFilter(){ local _inc= - echo "--- Filter:" - echo "By default all files will be restored." - echo "You can limit it by setting include rules." echo "You can enter ..." echo " - a single directory name anywhere in the folderstructure" echo " - a filename without path" diff --git a/restore.sh b/restore.sh index f398159..1f5a67e 100755 --- a/restore.sh +++ b/restore.sh @@ -163,42 +163,9 @@ function setVars(){ # sTarget=`j_getFullTarget "$sDir2restore"` sRestorepath="${RESTORE_BASEDIR}/${sSafeName}" - if [ ! -z $sRestoreItem ]; then - echo ${sRestoreItem} | grep '\*' >/dev/null - if [ $? -eq 0 ]; then - sRestoreItem=`dirname $sRestoreItem | sed 's#^\.##'` - color error - echo ERROR: using a placeholder is not allowed. Using the directory above. - echo [$sRestoreItem] - color reset - fi - - sRestorepath="${sRestorepath}/${sRestoreItem}" - fi } - -# -------------------------------------------------------------------------------- -# MAIN -# -------------------------------------------------------------------------------- - -h1 "RESTORE - GET FILES FROM STORAGE" - - -# ----- set a directory to restore to have a useful initial point - - setBackupDir $1 - if [ -z $sDir2restore ]; then - enterBackupDir - fi - -# ----- make inputs - - t_restoreSelect - t_restoreFilter - -# ----- get restore command: - +function doRestore(){ restorecmd=$( t_cmdRestore ) if [ -z "$restorecmd" ]; then color error @@ -208,11 +175,6 @@ h1 "RESTORE - GET FILES FROM STORAGE" exit 1 fi - echo - echo --- Restore: - echo $restorecmd - echo "RETURN to start restore ... or Ctrl + C to abort" - read dummy mkdir -p "${sRestorepath}" color cmd $restorecmd @@ -230,6 +192,21 @@ h1 "RESTORE - GET FILES FROM STORAGE" echo find ${sRestorepath} exit +} + + +# -------------------------------------------------------------------------------- +# MAIN +# -------------------------------------------------------------------------------- + +# ----- set a directory to restore to have a useful initial point + + t_checkRequirements + + setBackupDir $1 + if [ -z $sDir2restore ]; then + enterBackupDir + fi # ----- menu and loop @@ -244,8 +221,13 @@ h1 "RESTORE - GET FILES FROM STORAGE" echo echo " D - directory to restore: $sDir2restore" - echo " W - time or snapshot ID : $RESTORE_ITEM" - echo " F - what to restore : $RESTORE_FILTER" + echo -n " W - time or snapshot ID : $RESTORE_ITEM" + test -z "$RESTORE_ITEM" && echo -n " ... set it" + test -z "$RESTORE_ITEMINFO" || echo -n " ($RESTORE_ITEMINFO)" + echo + echo -n " F - what to restore : $RESTORE_FILTER" + test -z "$RESTORE_FILTER" && echo -n "(no filter = restore all files)" + echo echo # echo " C - show file changes" # echo " S - search file" @@ -256,7 +238,7 @@ h1 "RESTORE - GET FILES FROM STORAGE" echo echo " restore from : $sTarget" echo " restore to : $sRestorepath" - echo -n " " + echo -n " " ls -d $sRestorepath >/dev/null 2>&1 if [ $? -eq 0 ]; then color error @@ -269,9 +251,7 @@ h1 "RESTORE - GET FILES FROM STORAGE" echo " X - exit" echo - color input - echo -n "Select (not case sensitive) --> " - color reset + showPrompt "Select (not case sensitive) --> " read action echo @@ -280,6 +260,7 @@ h1 "RESTORE - GET FILES FROM STORAGE" enterBackupDir ;; w|W) + h2 "Set a time / select a snapshot" t_restoreSelect ;; c|C) @@ -297,9 +278,13 @@ h1 "RESTORE - GET FILES FROM STORAGE" bash ;; f|F) + h2 "Filter restore items" + echo "By default all files will be restored." + echo "You can limit it by setting include rules." t_restoreFilter ;; r|R) + h2 "Start restore" doRestore ;; x|X) -- GitLab