Compare commits
6 Commits
9ef05505a6
...
d6eae39603
Author | SHA1 | Date | |
---|---|---|---|
|
d6eae39603 | ||
|
8331ff712c | ||
|
7cc69a616a | ||
|
cfd7d6ede0 | ||
|
4dc77ca3ae | ||
|
71b77857a6 |
18
.vscode/numbered-bookmarks.json
vendored
18
.vscode/numbered-bookmarks.json
vendored
@ -1,19 +1,3 @@
|
|||||||
{
|
{
|
||||||
"bookmarks": [
|
"bookmarks": []
|
||||||
{
|
|
||||||
"fsPath": "$ROOTPATH$/borghelper.sh",
|
|
||||||
"bookmarks": [
|
|
||||||
-1,
|
|
||||||
151,
|
|
||||||
168,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
105
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
#
|
#
|
||||||
## borg helper script for viewing and restoring backups
|
## 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
|
### trap
|
||||||
@ -12,7 +19,12 @@ cleanup () {
|
|||||||
# remove borg temp directory, if it exists
|
# remove borg temp directory, if it exists
|
||||||
if [ -d "${borgBaseDir}/tmp" ]; then
|
if [ -d "${borgBaseDir}/tmp" ]; then
|
||||||
if ! rm -rf "${borgBaseDir}/tmp" > /dev/null 2>&1; 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
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -23,10 +35,66 @@ consoleError() {
|
|||||||
exit "$1"
|
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() {
|
textblock() {
|
||||||
printf "%s\n" "$1" | fold -w "$width" -s
|
printf "%s\n" "$1" | fold -w "$width" -s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ptextblock() {
|
||||||
|
printf "%s%s%s\n" "$cyan" "$1" "$norm"
|
||||||
|
}
|
||||||
|
|
||||||
trapExit () {
|
trapExit () {
|
||||||
cleanup
|
cleanup
|
||||||
printf "%s\nScript execution terminated via signal.\n\n%s" "$err" "$norm"
|
printf "%s\nScript execution terminated via signal.\n\n%s" "$err" "$norm"
|
||||||
@ -36,11 +104,17 @@ trapExit () {
|
|||||||
|
|
||||||
### text formatting presets
|
### text formatting presets
|
||||||
if command -v tput > /dev/null; then
|
if command -v tput > /dev/null; then
|
||||||
|
bold=$(tput bold)
|
||||||
|
cyan=$(tput setaf 6)
|
||||||
err=$(tput bold)$(tput setaf 1)
|
err=$(tput bold)$(tput setaf 1)
|
||||||
|
magenta=$(tput setaf 5)
|
||||||
norm=$(tput sgr0)
|
norm=$(tput sgr0)
|
||||||
width=$(tput cols)
|
width=$(tput cols)
|
||||||
else
|
else
|
||||||
|
bold=""
|
||||||
|
cyan=""
|
||||||
err="[ERROR] "
|
err="[ERROR] "
|
||||||
|
magenta=""
|
||||||
norm=""
|
norm=""
|
||||||
width=80
|
width=80
|
||||||
fi
|
fi
|
||||||
@ -87,7 +161,7 @@ while [ $# -gt 0 ]; do
|
|||||||
;;
|
;;
|
||||||
-h|-\?|--help)
|
-h|-\?|--help)
|
||||||
# display help
|
# display help
|
||||||
printf "\nStill working on the help text :-)\n\n"
|
scriptHelp
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
-i|--info)
|
-i|--info)
|
||||||
@ -197,6 +271,21 @@ fi
|
|||||||
if [ "$commonOptions" ]; then commonOptions=${commonOptions##[[:space:]]}; fi
|
if [ "$commonOptions" ]; then commonOptions=${commonOptions##[[:space:]]}; fi
|
||||||
if [ "$restoreOptions" ]; then restoreOptions=${restoreOptions##[[: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
|
### read borg information file
|
||||||
|
|
||||||
@ -303,5 +392,7 @@ exit 0
|
|||||||
# 1: parameter error (missing, non-existant or invalid input)
|
# 1: parameter error (missing, non-existant or invalid input)
|
||||||
# 2: parameter missing/invalid in .borgvars file
|
# 2: parameter missing/invalid in .borgvars file
|
||||||
# 3: could not create/remove borg tmp directory
|
# 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
|
#EOF
|
Loading…
Reference in New Issue
Block a user