Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iml-backup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
iml-backup
Commits
a2dddcf7
Commit
a2dddcf7
authored
2 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
restore - init vars; shell fixes
parent
d9305959
No related branches found
No related tags found
1 merge request
!88
5814 migrate repo to v2 - rename hooks
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
restore.sh
+26
-29
26 additions, 29 deletions
restore.sh
with
26 additions
and
29 deletions
restore.sh
+
26
−
29
View file @
a2dddcf7
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
# 2018-08-27 ah,ds v1.2 fix restore target with a given selection; handle '*' placeholder
# 2018-08-27 ah,ds v1.2 fix restore target with a given selection; handle '*' placeholder
# 2019-06-05 ah,ds v1.3 add custom cache dir
# 2019-06-05 ah,ds v1.3 add custom cache dir
# 2021-05-19 ah,ds, v2.0 plugin driven
# 2021-05-19 ah,ds, v2.0 plugin driven
# 2022-10-21 ah v2.1 init vars
# 2022-10-21 ah v2.1 init vars
; shell fixes
# ================================================================================
# ================================================================================
...
@@ -32,11 +32,11 @@
...
@@ -32,11 +32,11 @@
# . `dirname $0`/inc_config.sh
# . `dirname $0`/inc_config.sh
.
`
dirname
$0
`
/jobhelper.sh
.
$(
dirname
$0
)
/jobhelper.sh
.
`
dirname
$0
`
/inc_bash.sh
.
$(
dirname
$0
)
/inc_bash.sh
# --- load a transfer plugin
# --- load a transfer plugin
STORAGE_BIN
=
`
_j_getvar
${
STORAGEFILE
}
"bin"
`
STORAGE_BIN
=
$(
_j_getvar
${
STORAGEFILE
}
"bin"
)
if
[
-z
"
$STORAGE_BIN
"
]
;
then
if
[
-z
"
$STORAGE_BIN
"
]
;
then
if
!
id
-u
|
grep
'^0$'
if
!
id
-u
|
grep
'^0$'
...
@@ -50,20 +50,20 @@
...
@@ -50,20 +50,20 @@
CFGPREFIX
=
${
STORAGE_BIN
}
_
CFGPREFIX
=
${
STORAGE_BIN
}
_
.
`
dirname
$0
`
/plugins/transfer/
$STORAGE_BIN
.sh
||
exit
1
.
$(
dirname
$0
)
/plugins/transfer/
$STORAGE_BIN
.sh
||
exit
1
# --- get backend url of backup data
# --- get backend url of backup data
STORAGE_BASEDIR
=
`
_j_getvar
${
STORAGEFILE
}
"storage"
`
STORAGE_BASEDIR
=
$(
_j_getvar
${
STORAGEFILE
}
"storage"
)
if
[
-z
$STORAGE_BASEDIR
]
;
then
if
[
-z
$STORAGE_BASEDIR
]
;
then
echo
ERROR: missing config
for
backup target.
echo
"
ERROR: missing config for backup target.
"
echo
There must be an entry storage
in
${
STORAGEFILE
}
echo
"
There must be an entry storage in
${
STORAGEFILE
}
"
exit
1
exit
1
fi
fi
# target directory of directory specific repository
# target directory of directory specific repository
STORAGE_TARGETPATH
=
STORAGE_TARGETPATH
=
PASSPHRASE
=
`
_j_getvar
${
STORAGEFILE
}
"passphrase"
`
PASSPHRASE
=
$(
_j_getvar
"
${
STORAGEFILE
}
"
"passphrase"
)
# timestamp or snapshot id
# timestamp or snapshot id
RESTORE_ITEM
=
RESTORE_ITEM
=
...
@@ -72,7 +72,7 @@
...
@@ -72,7 +72,7 @@
RESTORE_FILTER
=
RESTORE_FILTER
=
# full path of restore data
# full path of restore data
RESTORE_BASEDIR
=
`
_j_getvar
${
STORAGEFILE
}
"restore-path"
`
RESTORE_BASEDIR
=
$(
_j_getvar
"
${
STORAGEFILE
}
"
"restore-path"
)
RESTORE_TARGETPATH
=
RESTORE_TARGETPATH
=
# set vars for transfer plugin
# set vars for transfer plugin
...
@@ -80,15 +80,16 @@
...
@@ -80,15 +80,16 @@
# ----- Create default command line parameters
# ----- Create default command line parameters
export
ARGS_DEFAULT
ARGS_DEFAULT
=
"
$(
t_getParamDefault
$1
$2
)
"
ARGS_DEFAULT
=
"
$(
t_getParamDefault
$1
$2
)
"
sFileSshPrivkey
=
`
_j_getvar
${
STORAGEFILE
}
"ssh-privatekey"
`
sFileSshPrivkey
=
$(
_j_getvar
"
${
STORAGEFILE
}
"
"ssh-privatekey"
)
if
[
!
-z
$sFileSshPrivkey
]
;
then
if
[
-n
"
$sFileSshPrivkey
"
]
;
then
ARGS_DEFAULT
=
"
${
ARGS_DEFAULT
}
$(
t_getParamSshKey
$sFileSshPrivkey
)
"
ARGS_DEFAULT
=
"
${
ARGS_DEFAULT
}
$(
t_getParamSshKey
$sFileSshPrivkey
)
"
fi
fi
# task#3046 - add custom cache dir
# task#3046 - add custom cache dir
sCacheDir
=
`
_j_getvar
${
STORAGEFILE
}
"cachedir"
`
sCacheDir
=
$(
_j_getvar
"
${
STORAGEFILE
}
"
"cachedir"
)
ARGS_DEFAULT
=
"
${
ARGS_DEFAULT
}
$(
t_getParamCacheDir
$sCacheDir
)
"
ARGS_DEFAULT
=
"
${
ARGS_DEFAULT
}
$(
t_getParamCacheDir
$sCacheDir
)
"
...
@@ -115,7 +116,7 @@ function enterBackupDir(){
...
@@ -115,7 +116,7 @@ function enterBackupDir(){
echo
"Enter the full path; marked entries with (*) do not exist on this machine"
echo
"Enter the full path; marked entries with (*) do not exist on this machine"
echo
echo
local
sDirs
=
"
`
j_getDirs2Backup
`
"
local
sDirs
=
"
$(
j_getDirs2Backup
)
"
for
mydir
in
$sDirs
for
mydir
in
$sDirs
do
do
if
[
!
-d
"
$mydir
"
]
;
then
if
[
!
-d
"
$mydir
"
]
;
then
...
@@ -130,7 +131,7 @@ function enterBackupDir(){
...
@@ -130,7 +131,7 @@ function enterBackupDir(){
color input
color input
echo
-n
"[
$BACKUP_DIR
] >"
echo
-n
"[
$BACKUP_DIR
] >"
color reset
color reset
read
myinput
read
-r
myinput
setBackupDir
"
${
myinput
}
"
setBackupDir
"
${
myinput
}
"
...
@@ -143,7 +144,7 @@ function enterBackupDir(){
...
@@ -143,7 +144,7 @@ function enterBackupDir(){
# ----------------------------------------------------------------------
# ----------------------------------------------------------------------
function
setBackupDir
(){
function
setBackupDir
(){
if
[
!
-z
$1
]
;
then
if
[
!
-z
$1
]
;
then
sDirs2Backup
=
"
`
j_getDirs2Backup
`
"
sDirs2Backup
=
"
$(
j_getDirs2Backup
)
"
bFound
=
0
bFound
=
0
for
mydir
in
${
sDirs2Backup
}
for
mydir
in
${
sDirs2Backup
}
do
do
...
@@ -176,7 +177,7 @@ function setBackupDir(){
...
@@ -176,7 +177,7 @@ function setBackupDir(){
# set backup url and local restore path (based on given backup directory)
# set backup url and local restore path (based on given backup directory)
function
setVars
(){
function
setVars
(){
local
sSafeName
=
`
j_getSafename
"
$BACKUP_DIR
"
`
local
sSafeName
=
$(
j_getSafename
"
$BACKUP_DIR
"
)
RESTORE_TARGETPATH
=
"
${
RESTORE_BASEDIR
}
/
${
sSafeName
}
"
RESTORE_TARGETPATH
=
"
${
RESTORE_BASEDIR
}
/
${
sSafeName
}
"
STORAGE_TARGETPATH
=
"
$(
t_backupDirGetTarget
$BACKUP_DIR
)
"
STORAGE_TARGETPATH
=
"
$(
t_backupDirGetTarget
$BACKUP_DIR
)
"
}
}
...
@@ -193,7 +194,7 @@ function doRestore(){
...
@@ -193,7 +194,7 @@ function doRestore(){
fi
fi
mkdir
-p
"
${
RESTORE_TARGETPATH
}
"
mkdir
-p
"
${
RESTORE_TARGETPATH
}
"
echo
$restorecmd
echo
"
$restorecmd
"
color cmd
color cmd
$restorecmd
$restorecmd
fetchrc
fetchrc
...
@@ -205,9 +206,9 @@ function doRestore(){
...
@@ -205,9 +206,9 @@ function doRestore(){
echo
echo
echo
Restore is finished.
echo
Restore is finished.
echo
Have look to the output above.
echo
Have look to the output above.
echo
"The restore path has
`
find
${
RESTORE_TARGETPATH
}
|
wc
-l
`
items (
`
du
-hs
${
RESTORE_TARGETPATH
}
|
awk
'{ print $1 }'
`
)"
echo
"The restore path has
$(
find
${
RESTORE_TARGETPATH
}
|
wc
-l
)
items (
$(
du
-hs
${
RESTORE_TARGETPATH
}
|
awk
'{ print $1 }'
)
)"
echo
echo
echo
find
${
RESTORE_TARGETPATH
}
echo
"
find
${
RESTORE_TARGETPATH
}
"
exit
exit
}
}
...
@@ -222,14 +223,10 @@ function doRestore(){
...
@@ -222,14 +223,10 @@ function doRestore(){
t_checkRequirements
t_checkRequirements
setBackupDir
$1
setBackupDir
$1
if
[
-z
$BACKUP_DIR
]
;
then
if
[
-z
"
$BACKUP_DIR
"
]
;
then
enterBackupDir
enterBackupDir
fi
fi
# init vars of the backup tool
t_getParamDefault
>
/dev/null
# ----- menu and loop
# ----- menu and loop
while
true
while
true
...
@@ -257,7 +254,7 @@ function doRestore(){
...
@@ -257,7 +254,7 @@ function doRestore(){
echo
" restore to :
$RESTORE_TARGETPATH
"
echo
" restore to :
$RESTORE_TARGETPATH
"
echo
-n
" "
echo
-n
" "
if
[
-n
"
$RESTORE_TARGETPATH
"
]
;
then
if
[
-n
"
$RESTORE_TARGETPATH
"
]
;
then
ls
-d
$RESTORE_TARGETPATH
>
/dev/null 2>&1
ls
-d
"
$RESTORE_TARGETPATH
"
>
/dev/null 2>&1
if
[
$?
-eq
0
]
;
then
if
[
$?
-eq
0
]
;
then
color error
color error
echo
"WARNING: directory already exists! Backup will fail."
echo
"WARNING: directory already exists! Backup will fail."
...
@@ -274,7 +271,7 @@ function doRestore(){
...
@@ -274,7 +271,7 @@ function doRestore(){
echo
echo
showPrompt
"Select (not case sensitive) --> "
showPrompt
"Select (not case sensitive) --> "
read
action
read
-r
action
echo
echo
case
$action
in
case
$action
in
...
@@ -296,7 +293,7 @@ function doRestore(){
...
@@ -296,7 +293,7 @@ function doRestore(){
h2
"Search a file"
h2
"Search a file"
filefilter
=
".*"
filefilter
=
".*"
showPrompt
"Regex for filefilter;
${
filefilter
}
for all >"
showPrompt
"Regex for filefilter;
${
filefilter
}
for all >"
read
filefilter
read
-r
filefilter
test
-z
"
${
filefilter
}
"
||
t_restoreDoSearchFile
"
${
filefilter
}
"
test
-z
"
${
filefilter
}
"
||
t_restoreDoSearchFile
"
${
filefilter
}
"
;;
;;
# v|V)
# v|V)
...
@@ -306,7 +303,7 @@ function doRestore(){
...
@@ -306,7 +303,7 @@ function doRestore(){
h2
"Shell"
h2
"Shell"
echo
"HINT: type exit in the subshell to return to the menu."
echo
"HINT: type exit in the subshell to return to the menu."
echo
echo
export
PS1
=
"RESTIC [
`
basename
$0
`
\u
@
\h
\w
]
\$
"
export
PS1
=
"RESTIC [
$(
basename
$0
)
\u
@
\h
\w
]
\$
"
bash
--noprofile
bash
--noprofile
;;
;;
f|F
)
f|F
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment