Skip to content
Snippets Groups Projects
Commit 5e52dbbe authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

update restore.sh and restic plugin

parent bc12652d
No related branches found
No related tags found
1 merge request!1Version 2
...@@ -218,19 +218,17 @@ ...@@ -218,19 +218,17 @@
color cmd color cmd
t_cmdShowVolumes t_cmdShowVolumes
color reset 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 read _selid
test -z "$_selid" && _selid=$RESTORE_ITEM test -z "$_selid" && _selid=$RESTORE_ITEM
RESTORE_ITEM=$_selid RESTORE_ITEM=$_selid
echo using \"$RESTORE_ITEM\" echo using \"$RESTORE_ITEM\"
RESTORE_ITEMINFO=$( t_cmdShowVolumes | grep "^$RESTORE_ITEM" | awk '{ print $2 " " $3} ' )
echo echo
} }
# set a filter to reduce count of files to restore # set a filter to reduce count of files to restore
function t_restoreFilter(){ function t_restoreFilter(){
local _inc= 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 "You can enter ..."
echo " - a single directory name anywhere in the folderstructure" echo " - a single directory name anywhere in the folderstructure"
echo " - a filename without path" echo " - a filename without path"
......
...@@ -163,42 +163,9 @@ function setVars(){ ...@@ -163,42 +163,9 @@ function setVars(){
# sTarget=`j_getFullTarget "$sDir2restore"` # sTarget=`j_getFullTarget "$sDir2restore"`
sRestorepath="${RESTORE_BASEDIR}/${sSafeName}" 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
} }
function doRestore(){
# --------------------------------------------------------------------------------
# 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:
restorecmd=$( t_cmdRestore ) restorecmd=$( t_cmdRestore )
if [ -z "$restorecmd" ]; then if [ -z "$restorecmd" ]; then
color error color error
...@@ -208,11 +175,6 @@ h1 "RESTORE - GET FILES FROM STORAGE" ...@@ -208,11 +175,6 @@ h1 "RESTORE - GET FILES FROM STORAGE"
exit 1 exit 1
fi fi
echo
echo --- Restore:
echo $restorecmd
echo "RETURN to start restore ... or Ctrl + C to abort"
read dummy
mkdir -p "${sRestorepath}" mkdir -p "${sRestorepath}"
color cmd color cmd
$restorecmd $restorecmd
...@@ -230,6 +192,21 @@ h1 "RESTORE - GET FILES FROM STORAGE" ...@@ -230,6 +192,21 @@ h1 "RESTORE - GET FILES FROM STORAGE"
echo find ${sRestorepath} echo find ${sRestorepath}
exit 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 # ----- menu and loop
...@@ -244,8 +221,13 @@ h1 "RESTORE - GET FILES FROM STORAGE" ...@@ -244,8 +221,13 @@ h1 "RESTORE - GET FILES FROM STORAGE"
echo echo
echo " D - directory to restore: $sDir2restore" echo " D - directory to restore: $sDir2restore"
echo " W - time or snapshot ID : $RESTORE_ITEM" echo -n " W - time or snapshot ID : $RESTORE_ITEM"
echo " F - what to restore : $RESTORE_FILTER" 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
# echo " C - show file changes" # echo " C - show file changes"
# echo " S - search file" # echo " S - search file"
...@@ -256,7 +238,7 @@ h1 "RESTORE - GET FILES FROM STORAGE" ...@@ -256,7 +238,7 @@ h1 "RESTORE - GET FILES FROM STORAGE"
echo echo
echo " restore from : $sTarget" echo " restore from : $sTarget"
echo " restore to : $sRestorepath" echo " restore to : $sRestorepath"
echo -n " " echo -n " "
ls -d $sRestorepath >/dev/null 2>&1 ls -d $sRestorepath >/dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
color error color error
...@@ -269,9 +251,7 @@ h1 "RESTORE - GET FILES FROM STORAGE" ...@@ -269,9 +251,7 @@ h1 "RESTORE - GET FILES FROM STORAGE"
echo " X - exit" echo " X - exit"
echo echo
color input showPrompt "Select (not case sensitive) --> "
echo -n "Select (not case sensitive) --> "
color reset
read action read action
echo echo
...@@ -280,6 +260,7 @@ h1 "RESTORE - GET FILES FROM STORAGE" ...@@ -280,6 +260,7 @@ h1 "RESTORE - GET FILES FROM STORAGE"
enterBackupDir enterBackupDir
;; ;;
w|W) w|W)
h2 "Set a time / select a snapshot"
t_restoreSelect t_restoreSelect
;; ;;
c|C) c|C)
...@@ -297,9 +278,13 @@ h1 "RESTORE - GET FILES FROM STORAGE" ...@@ -297,9 +278,13 @@ h1 "RESTORE - GET FILES FROM STORAGE"
bash bash
;; ;;
f|F) 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 t_restoreFilter
;; ;;
r|R) r|R)
h2 "Start restore"
doRestore doRestore
;; ;;
x|X) x|X)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment