|
|
|
@ -2,6 +2,13 @@
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
## 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
|
|
|
|
@ -12,7 +19,12 @@ 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."
|
|
|
|
|
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."
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
@ -23,10 +35,66 @@ 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"
|
|
|
|
@ -36,11 +104,17 @@ 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
|
|
|
|
@ -87,7 +161,7 @@ while [ $# -gt 0 ]; do
|
|
|
|
|
;;
|
|
|
|
|
-h|-\?|--help)
|
|
|
|
|
# display help
|
|
|
|
|
printf "\nStill working on the help text :-)\n\n"
|
|
|
|
|
scriptHelp
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
-i|--info)
|
|
|
|
@ -197,6 +271,21 @@ 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
|
|
|
|
|
|
|
|
|
@ -303,5 +392,7 @@ 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
|