Compare commits
No commits in common. "d6eae39603e392b38540e83d2e04b940899dbf02" and "9ef05505a62eaf783995ae6382262ae6fd1e4786" have entirely different histories.
d6eae39603
...
9ef05505a6
18
.vscode/numbered-bookmarks.json
vendored
18
.vscode/numbered-bookmarks.json
vendored
@ -1,3 +1,19 @@
|
||||
{
|
||||
"bookmarks": []
|
||||
"bookmarks": [
|
||||
{
|
||||
"fsPath": "$ROOTPATH$/borghelper.sh",
|
||||
"bookmarks": [
|
||||
-1,
|
||||
151,
|
||||
168,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
-1,
|
||||
105
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -2,13 +2,6 @@
|
||||
|
||||
#
|
||||
## borg helper script for viewing and restoring backups
|
||||
##
|
||||
## script written by Asif Bacchus, last updated March 26, 2020.
|
||||
##
|
||||
## The author of this script is not affiliated with 'borgbackup' in any way and
|
||||
## does not warrant anything about this script, its operation, suitability or
|
||||
## fitness for use in any environment or under any conditions. You are using
|
||||
## this script entirely at your own risk.
|
||||
#
|
||||
|
||||
### trap
|
||||
@ -19,12 +12,7 @@ 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
|
||||
if [ -f "${restorePath}/touch.test" ]; then
|
||||
if ! rm -f "${restorePath}/touch.test" > /dev/null 2>&1; then
|
||||
consoleError 5 "Script completed successfully but could not remove test file at '$restorePath/touch.test'. Sorry to be messy."
|
||||
consoleError 3 "Script completed successfully but could not remove temporary directory at $borgBaseDir/tmp. Sorry to be messy."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
@ -35,66 +23,10 @@ consoleError() {
|
||||
exit "$1"
|
||||
}
|
||||
|
||||
scriptHelp() {
|
||||
printf "\n"
|
||||
textblock "${bold}Usage: borghelper.sh [parameters]${norm}"
|
||||
printf "\n"
|
||||
textblock "Simple script to read connection parameters from a flat text file and process borg 'info', 'list' and 'restore' commands without the very long command lines that are required when specifying repo names and passwords, etc."
|
||||
printf "\n"
|
||||
textblock "${magenta}The script has the following parameters:${norm}"
|
||||
printf "\n"
|
||||
textblock "${magenta}--- Required Parameters ---${norm}"
|
||||
printf "\n"
|
||||
ptextblock "-v|--vars"
|
||||
textblock "Path to the .borgvars file from which to read borg connection information. This is not required if run with '--makevars'."
|
||||
printf "\n"
|
||||
textblock "${magenta}--- Operation Modes ---${norm}"
|
||||
printf "\n"
|
||||
ptextblock "--makevars"
|
||||
textblock "Create a sample .borgvars file that you can fill in and use with this script."
|
||||
ptextblock "-i|--info"
|
||||
textblock "Get information about a specified borg repo archive. Requires you supply '--archive'."
|
||||
ptextblock "-l|--list"
|
||||
textblock "List contents of a specified borg repo archive. Requires you supply '--archive'."
|
||||
ptextblock "-la|--list-all"
|
||||
textblock "List all available archives within the repo specified in your .borgvars file."
|
||||
ptextblock "-r|--restore"
|
||||
textblock "Restore the specified borg repo archive/file(s). Requires you supply '--archive'."
|
||||
printf "\n"
|
||||
textblock "${magenta}--- Selector Parameters ---${norm}"
|
||||
printf "\n"
|
||||
ptextblock "-a|--archive"
|
||||
textblock "The archive within your borg repo you wish to work with."
|
||||
ptextblock "--exclude"
|
||||
textblock "Pattern (python/borg) of files to exclude from a restore operation."
|
||||
ptextblock "-f|--file"
|
||||
textblock "Specific file/pattern (python/borg) you want to restore from an archive. Requires that you supply '--archive'."
|
||||
ptextblock "-p|--path"
|
||||
textblock "Path to which you want your archive/files restored. This script will attempt to create the directory for you if it does not already exist."
|
||||
printf "\n"
|
||||
textblock "${magenta}--- Restore Options ---${norm}"
|
||||
printf "\n"
|
||||
ptextblock "--progress"
|
||||
textblock "Display progress indicator during restore operations. WARNING: This can drastically slow down operations on larger archives!"
|
||||
ptextblock "--verbose"
|
||||
textblock "List the individual files being processed during restore operations."
|
||||
printf "\n"
|
||||
textblock "${magenta}--- Other Parameters ---${norm}"
|
||||
printf "\n"
|
||||
ptextblock "-h|-?|--help"
|
||||
textblock "This help screen."
|
||||
printf "\n"
|
||||
exit 0
|
||||
}
|
||||
|
||||
textblock() {
|
||||
printf "%s\n" "$1" | fold -w "$width" -s
|
||||
}
|
||||
|
||||
ptextblock() {
|
||||
printf "%s%s%s\n" "$cyan" "$1" "$norm"
|
||||
}
|
||||
|
||||
trapExit () {
|
||||
cleanup
|
||||
printf "%s\nScript execution terminated via signal.\n\n%s" "$err" "$norm"
|
||||
@ -104,17 +36,11 @@ trapExit () {
|
||||
|
||||
### text formatting presets
|
||||
if command -v tput > /dev/null; then
|
||||
bold=$(tput bold)
|
||||
cyan=$(tput setaf 6)
|
||||
err=$(tput bold)$(tput setaf 1)
|
||||
magenta=$(tput setaf 5)
|
||||
norm=$(tput sgr0)
|
||||
width=$(tput cols)
|
||||
else
|
||||
bold=""
|
||||
cyan=""
|
||||
err="[ERROR] "
|
||||
magenta=""
|
||||
norm=""
|
||||
width=80
|
||||
fi
|
||||
@ -161,7 +87,7 @@ while [ $# -gt 0 ]; do
|
||||
;;
|
||||
-h|-\?|--help)
|
||||
# display help
|
||||
scriptHelp
|
||||
printf "\nStill working on the help text :-)\n\n"
|
||||
exit 0
|
||||
;;
|
||||
-i|--info)
|
||||
@ -271,21 +197,6 @@ fi
|
||||
if [ "$commonOptions" ]; then commonOptions=${commonOptions##[[:space:]]}; fi
|
||||
if [ "$restoreOptions" ]; then restoreOptions=${restoreOptions##[[:space:]]}; fi
|
||||
|
||||
# check/create restore path
|
||||
if [ -d "$restorePath" ]; then
|
||||
if ! touch "${restorePath}/touch.test" > /dev/null 2>&1; then
|
||||
consoleError 5 'Cannot write to specified restore directory.'
|
||||
fi
|
||||
else
|
||||
if ! mkdir -p "${restorePath}" > /dev/null 2>&1; then
|
||||
consoleError 5 'Cannot create specified restore directory.'
|
||||
else
|
||||
if ! touch "${restorePath}/touch.test" > /dev/null 2>&1; then
|
||||
consoleError 5 'Cannot write to specified restore directory.'
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
### read borg information file
|
||||
|
||||
@ -392,7 +303,5 @@ exit 0
|
||||
# 1: parameter error (missing, non-existant or invalid input)
|
||||
# 2: parameter missing/invalid in .borgvars file
|
||||
# 3: could not create/remove borg tmp directory
|
||||
# 4: could not write sample borgvars file (permissions?)
|
||||
# 5: cannot create/write to restore path or could not remove touch.test file
|
||||
|
||||
#EOF
|
Loading…
Reference in New Issue
Block a user