Compare commits

...

4 Commits

Author SHA1 Message Date
Asif Bacchus 9ef05505a6 make sample borgvars file 2020-03-26 05:49:23 -06:00
Asif Bacchus 846789efe7 restore root-check 2020-03-26 05:43:10 -06:00
Asif Bacchus ff98225921 process exclusions 2020-03-26 05:40:23 -06:00
Asif Bacchus bcb6c9c5ef fix option string spacing issues, unquote them! 2020-03-26 05:37:03 -06:00
2 changed files with 40 additions and 12 deletions

View File

@ -4,15 +4,15 @@
"fsPath": "$ROOTPATH$/borghelper.sh",
"bookmarks": [
-1,
253,
151,
168,
-1,
-1,
-1,
-1,
-1,
-1,
84
105
]
}
]

View File

@ -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