Compare commits
4 Commits
91359306aa
...
9ef05505a6
Author | SHA1 | Date | |
---|---|---|---|
|
9ef05505a6 | ||
|
846789efe7 | ||
|
ff98225921 | ||
|
bcb6c9c5ef |
4
.vscode/numbered-bookmarks.json
vendored
4
.vscode/numbered-bookmarks.json
vendored
@ -4,15 +4,15 @@
|
||||
"fsPath": "$ROOTPATH$/borghelper.sh",
|
||||
"bookmarks": [
|
||||
-1,
|
||||
253,
|
||||
151,
|
||||
168,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
84
|
||||
105
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -49,9 +49,9 @@ fi
|
||||
### pre-requisites
|
||||
|
||||
# is user root?
|
||||
#if [ ! "$( id -u )" -eq 0 ]; then
|
||||
# consoleError 1 'You must be root to run this script.'
|
||||
#fi
|
||||
if [ ! "$( id -u )" -eq 0 ]; then
|
||||
consoleError 1 'You must be root to run this script.'
|
||||
fi
|
||||
|
||||
# has a parameter been passed to this script?
|
||||
if [ -z "$1" ]; then
|
||||
@ -69,6 +69,14 @@ while [ $# -gt 0 ]; do
|
||||
archiveName="$2"
|
||||
shift
|
||||
;;
|
||||
--exclude)
|
||||
# exclude files from restore
|
||||
if [ -z "$2" ]; then
|
||||
consoleError 1 "Please provide a list of exclusions in the proper borg format."
|
||||
fi
|
||||
exclusions="$2"
|
||||
shift
|
||||
;;
|
||||
-f|--file)
|
||||
# specific file to restore
|
||||
if [ -z "$2" ]; then
|
||||
@ -95,6 +103,10 @@ while [ $# -gt 0 ]; do
|
||||
# list all backup archives
|
||||
operation='listall'
|
||||
;;
|
||||
--makevars)
|
||||
# make a borgvars template file
|
||||
operation='makevars'
|
||||
;;
|
||||
-p|--path)
|
||||
# path to restore files
|
||||
if [ -z "$2" ]; then
|
||||
@ -137,6 +149,15 @@ while [ $# -gt 0 ]; do
|
||||
done
|
||||
|
||||
|
||||
### process 'makevars' operation
|
||||
if [ "$operation" = 'makevars' ]; then
|
||||
if ! printf "sshKeyFile=\nborgBaseDir=\nborgRepo=\nborgRepoPassword=\nborgRemote=\n" > ./sample.borgvars; then
|
||||
consoleError 4 'Could not write sample borgvars file.'
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
### check parameter validity
|
||||
|
||||
# no operation
|
||||
@ -173,8 +194,8 @@ if [ "$fileName" ] && [ -z "$archiveName" ]; then
|
||||
fi
|
||||
|
||||
# clean-up leading spaces in option strings
|
||||
commonOptions=${commonOptions##[[:space:]]}
|
||||
restoreOptions=${restoreOptions##[[:space:]]}
|
||||
if [ "$commonOptions" ]; then commonOptions=${commonOptions##[[:space:]]}; fi
|
||||
if [ "$restoreOptions" ]; then restoreOptions=${restoreOptions##[[:space:]]}; fi
|
||||
|
||||
|
||||
### read borg information file
|
||||
@ -253,14 +274,21 @@ elif [ "$operation" = 'viewarchive' ]; then
|
||||
borg list ::"${archiveName}"
|
||||
# restore operations
|
||||
elif [ "$operation" = 'restore' ]; then
|
||||
cd "$restorePath" || consoleError 4 'Could not change to restore directory.'
|
||||
if [ -z "$fileName" ]; then
|
||||
# restore entire archive
|
||||
cd "$restorePath" || consoleError 4 'Could not change to restore directory.'
|
||||
borg --show-rc "$commonOptions" extract "$restoreOptions" ::"${archiveName}"
|
||||
if [ "$exclusions" ]; then
|
||||
borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}" --exclude "${exclusions}"
|
||||
else
|
||||
borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}"
|
||||
fi
|
||||
elif [ "$fileName" ]; then
|
||||
# restore single file
|
||||
cd "$restorePath" || consoleError 4 'Could not change to restore directory.'
|
||||
borg --show-rc "$commonOptions" extract "$restoreOptions" ::"${archiveName}" "${fileName}"
|
||||
# restore file/pattern
|
||||
if [ "$exclusions" ]; then
|
||||
borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}" "${fileName}" --exclude "${exclusions}"
|
||||
else
|
||||
borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}" "${fileName}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user