Compare commits

..

No commits in common. "91359306aae0d03e7e7c46f2f201f85c1b961393" and "02a27f55a1b56825359fd5d9d82aad98045a70b3" have entirely different histories.

2 changed files with 10 additions and 114 deletions

View File

@ -1,19 +1,3 @@
{
"bookmarks": [
{
"fsPath": "$ROOTPATH$/borghelper.sh",
"bookmarks": [
-1,
253,
151,
-1,
-1,
-1,
-1,
-1,
-1,
84
]
}
]
"bookmarks": []
}

View File

@ -8,15 +8,6 @@
trap trapExit 1 2 3 6
### functions
cleanup () {
# remove borg temp directory, if it exists
if [ -d "${borgBaseDir}/tmp" ]; then
if ! rm -rf "${borgBaseDir}/tmp" > /dev/null 2>&1; then
consoleError 3 "Script completed successfully but could not remove temporary directory at $borgBaseDir/tmp. Sorry to be messy."
fi
fi
}
consoleError() {
printf "%s\n%s\n" "$err" "$2"
printf "Exiting.\n\n%s" "$norm"
@ -28,30 +19,23 @@ textblock() {
}
trapExit () {
cleanup
printf "%s\nScript execution terminated via signal.\n\n%s" "$err" "$norm"
exit 99
}
### text formatting presets
if command -v tput > /dev/null; then
err=$(tput bold)$(tput setaf 1)
norm=$(tput sgr0)
width=$(tput cols)
else
err="[ERROR] "
norm=""
width=80
fi
err=$(tput bold)$(tput setaf 1)
norm=$(tput sgr0)
width=$(tput cols)
### 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
@ -82,10 +66,6 @@ while [ $# -gt 0 ]; do
printf "\nStill working on the help text :-)\n\n"
exit 0
;;
-i|--info)
# show archive information
operation='info'
;;
-l|--list)
# list contents of specific backup
operation='viewarchive'
@ -103,10 +83,6 @@ while [ $# -gt 0 ]; do
restorePath="${2%/}"
shift
;;
--progress)
# show progress
commonOptions="$commonOptions --progress"
;;
-r|--restore)
# restore archive/file
operation='restore'
@ -122,10 +98,6 @@ while [ $# -gt 0 ]; do
varsFile="$2"
shift
;;
--verbose)
# display each file being processed
restoreOptions="$restoreOptions --list"
;;
*)
# invalid option
printf "%s\nUnknown option: %s\n" "$err" "$1"
@ -149,13 +121,8 @@ if [ -z "$varsFile" ]; then
consoleError 1 'You must provide a valid .borgvars file with information about your borg repo.'
fi
# info without archive
if [ "$operation" = 'info' ] && [ -z "$archiveName" ]; then
consoleError 1 "Info operation requested but no archive name provided. Please use '--list-all' for a list of all available archives."
fi
# list without archive
if [ "$operation" = 'viewarchive' ] && [ -z "$archiveName" ]; then
if [ "$operation" = 'list' ] && [ -z "$archiveName" ]; then
consoleError 1 "List operation requested but no archive name provided. Please use '--list-all' for a list of all available archives."
fi
@ -172,10 +139,6 @@ if [ "$fileName" ] && [ -z "$archiveName" ]; then
consoleError 1 "Filename specified without an associated archive name."
fi
# clean-up leading spaces in option strings
commonOptions=${commonOptions##[[:space:]]}
restoreOptions=${restoreOptions##[[:space:]]}
### read borg information file
@ -216,64 +179,13 @@ export BORG_REPO="${borgRepo}"
# check borg repo password
if [ -n "${borgRepoPassword}" ]; then
export BORG_PASSPHRASE="${borgRepoPassword}"
elif [ "${borgRepoPassword}" = 'none' ]; then
elif [ "${borgRepoPassword}" = '<none>' ]; then
export BORG_PASSPHRASE=""
else
consoleError 2 "$varsFile: 'borgRepoPassword' must be specified or must be 'none' if no password has been set (VERY INSECURE!)."
consoleError 2 "$varsFile: 'borgRepoPassword' must be specified or must be '<none>' if no password has been set (VERY INSECURE!)."
fi
# export borg remote path, if specified
if [ -n "${borgRemote}" ]; then export BORG_REMOTE_PATH="${borgRemote}"; fi
### create borg temp dir:
## python requires a writable temporary directory when unpacking borg and
## executing commands. This defaults to /tmp but many systems mount /tmp with
## the 'noexec' option for security. Thus, we will use/create a 'tmp' folder
## within the BORG_BASE_DIR and instruct python to use that instead of /tmp
# check if BORG_BASE_DIR/tmp exists, if not, create it
if [ ! -d "${borgBaseDir}/tmp" ]; then
if ! mkdir "${borgBaseDir}/tmp"; then
consoleError 3 'Unable to create temp working directory for borg.'
fi
fi
export TMPDIR="${borgBaseDir}/tmp"
### execute borg operations
# info operations
if [ "$operation" = 'info' ]; then
borg info ::"${archiveName}"
# list operations
elif [ "$operation" = 'listall' ]; then
borg list
elif [ "$operation" = 'viewarchive' ]; then
borg list ::"${archiveName}"
# restore operations
elif [ "$operation" = 'restore' ]; then
if [ -z "$fileName" ]; then
# restore entire archive
cd "$restorePath" || consoleError 4 'Could not change to restore directory.'
borg --show-rc "$commonOptions" extract "$restoreOptions" ::"${archiveName}"
elif [ "$fileName" ]; then
# restore single file
cd "$restorePath" || consoleError 4 'Could not change to restore directory.'
borg --show-rc "$commonOptions" extract "$restoreOptions" ::"${archiveName}" "${fileName}"
fi
fi
### exit gracefully
cleanup
exit 0
### exit codes
# 0: no errors, script completed successfully
# 1: parameter error (missing, non-existant or invalid input)
# 2: parameter missing/invalid in .borgvars file
# 3: could not create/remove borg tmp directory
#EOF