Compare commits

..

No commits in common. "c73a3b85315b07b5645316468ec8001541979c34" and "29ab2c11a33ce96ef2878369061be4b0271453d2" have entirely different histories.

7 changed files with 156 additions and 215 deletions

View File

@ -1,13 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/.idea.borgScripts.iml
/modules.xml
/contentModel.xml
/projectSettingsUpdater.xml
# Datasource local storage ignored files
/../../../../../../../../../:\Redirected\Asif\Documents\RiderProjects\borgScripts\.idea\.idea.borgScripts.dir\.idea/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -1,12 +0,0 @@
<component name="ProjectDictionaryState">
<dictionary name="asif">
<words>
<w>borgbackup</w>
<w>borghelper</w>
<w>borgvars</w>
<w>listall</w>
<w>makevars</w>
<w>viewarchive</w>
</words>
</dictionary>
</component>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ContentModelUserStore">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="RIDER_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/../.." />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CommitMessageInspectionProfile">
<profile version="1.0">
<inspection_tool class="BodyLimit" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SubjectBodySeparation" enabled="true" level="ERROR" enabled_by_default="true" />
<inspection_tool class="SubjectLimit" enabled="true" level="ERROR" enabled_by_default="true" />
</profile>
</component>
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

3
.vscode/numbered-bookmarks.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"bookmarks": []
}

View File

@ -3,7 +3,7 @@
# #
## borg helper script for viewing and restoring backups ## borg helper script for viewing and restoring backups
## ##
## script written by Asif Bacchus, last updated May 15, 2021. ## script written by Asif Bacchus, last updated March 26, 2020.
## ##
## The author of this script is not affiliated with 'borgbackup' in any way and ## 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 ## does not warrant anything about this script, its operation, suitability or
@ -17,7 +17,6 @@ trap trapExit 1 2 3 6
### functions ### functions
cleanup () { cleanup () {
# remove borg temp directory, if it exists # remove borg temp directory, if it exists
# shellcheck disable=SC2154
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."
@ -38,61 +37,61 @@ consoleError() {
scriptHelp() { scriptHelp() {
printf "\n" printf "\n"
textBlock "${bold}Usage: borghelper.sh [parameters]${norm}" textblock "${bold}Usage: borghelper.sh [parameters]${norm}"
printf "\n" 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." 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" printf "\n"
textBlock "${magenta}The script has the following parameters:${norm}" textblock "${magenta}The script has the following parameters:${norm}"
printf "\n" printf "\n"
textBlock "${magenta}--- Required Parameters ---${norm}" textblock "${magenta}--- Required Parameters ---${norm}"
printf "\n" printf "\n"
textBlockParams "-v|--vars" ptextblock "-v|--vars"
textBlock "Path to the .borgvars file from which to read borg connection information. This is not required if run with '--makevars'." textblock "Path to the .borgvars file from which to read borg connection information. This is not required if run with '--makevars'."
printf "\n" printf "\n"
textBlock "${magenta}--- Operation Modes ---${norm}" textblock "${magenta}--- Operation Modes ---${norm}"
printf "\n" printf "\n"
textBlockParams "--makevars" ptextblock "--makevars"
textBlock "Create a sample .borgvars file that you can fill in and use with this script." textblock "Create a sample .borgvars file that you can fill in and use with this script."
textBlockParams "-i|--info" ptextblock "-i|--info"
textBlock "Get information about a specified borg repo archive. Requires you supply '--archive'." textblock "Get information about a specified borg repo archive. Requires you supply '--archive'."
textBlockParams "-l|--list" ptextblock "-l|--list"
textBlock "List contents of a specified borg repo archive. Requires you supply '--archive'. You can optionally specify a file/pattern to search for using '--file'." textblock "List contents of a specified borg repo archive. Requires you supply '--archive'. You can optionally specify a file/pattern to search for using '--file'."
textBlockParams "-la|--list-all" ptextblock "-la|--list-all"
textBlock "List all available archives within the repo specified in your .borgvars file." textblock "List all available archives within the repo specified in your .borgvars file."
textBlockParams "-r|--restore" ptextblock "-r|--restore"
textBlock "Restore the specified borg repo archive/file(s). Requires you supply '--archive'." textblock "Restore the specified borg repo archive/file(s). Requires you supply '--archive'."
printf "\n" printf "\n"
textBlock "${magenta}--- Selector Parameters ---${norm}" textblock "${magenta}--- Selector Parameters ---${norm}"
printf "\n" printf "\n"
textBlockParams "-a|--archive" ptextblock "-a|--archive"
textBlock "The archive within your borg repo you wish to work with." textblock "The archive within your borg repo you wish to work with."
textBlockParams "--exclude" ptextblock "--exclude"
textBlock "Pattern (python/borg) of files to exclude from a restore operation." textblock "Pattern (python/borg) of files to exclude from a restore operation."
textBlockParams "-f|--file" ptextblock "-f|--file"
textBlock "Specific file/pattern (python/borg) within an archive for which you want to restore or search. Requires that you supply '--archive'." textblock "Specific file/pattern (python/borg) within an archive for which you want to restore or search. Requires that you supply '--archive'."
textBlockParams "-p|--path" 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." 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" printf "\n"
textBlock "${magenta}--- Restore Options ---${norm}" textblock "${magenta}--- Restore Options ---${norm}"
printf "\n" printf "\n"
textBlockParams "--progress" ptextblock "--progress"
textBlock "Display progress indicator during restore operations. WARNING: This can drastically slow down operations on larger archives!" textblock "Display progress indicator during restore operations. WARNING: This can drastically slow down operations on larger archives!"
textBlockParams "--verbose" ptextblock "--verbose"
textBlock "List the individual files being processed during restore operations." textblock "List the individual files being processed during restore operations."
printf "\n" printf "\n"
textBlock "${magenta}--- Other Parameters ---${norm}" textblock "${magenta}--- Other Parameters ---${norm}"
printf "\n" printf "\n"
textBlockParams "-h|-?|--help" ptextblock "-h|-?|--help"
textBlock "This help screen." textblock "This help screen."
printf "\n" printf "\n"
exit 0 exit 0
} }
textBlock() { textblock() {
printf "%s\n" "$1" | fold -w "$width" -s printf "%s\n" "$1" | fold -w "$width" -s
} }
textBlockParams() { ptextblock() {
printf "%s%s%s\n" "$cyan" "$1" "$norm" printf "%s%s%s\n" "$cyan" "$1" "$norm"
} }
@ -102,6 +101,7 @@ trapExit() {
exit 99 exit 99
} }
### text formatting presets ### text formatting presets
if command -v tput > /dev/null; then if command -v tput > /dev/null; then
bold=$(tput bold) bold=$(tput bold)
@ -119,6 +119,7 @@ else
width=80 width=80
fi fi
### pre-requisites ### pre-requisites
# is user root? # is user root?
@ -128,7 +129,7 @@ fi
# has a parameter been passed to this script? # has a parameter been passed to this script?
if [ -z "$1" ]; then if [ -z "$1" ]; then
scriptHelp consoleError 1 "No operation requested. Please run this script with '--help' for valid parameters."
fi fi
# process startup parameters # process startup parameters
@ -161,6 +162,7 @@ while [ $# -gt 0 ]; do
-h|-\?|--help) -h|-\?|--help)
# display help # display help
scriptHelp scriptHelp
exit 0
;; ;;
-i|--info) -i|--info)
# show archive information # show archive information
@ -220,9 +222,10 @@ while [ $# -gt 0 ]; do
shift shift
done done
### process 'makevars' operation ### process 'makevars' operation
if [ "$operation" = 'makevars' ]; then if [ "$operation" = 'makevars' ]; then
if ! printf "sshKeyFile=\nborgBaseDir=\nborgRepo=\nborgRepoPassword=\nborgRepoKey=\nborgRemote=\n" >./sample.borgvars; then if ! printf "sshKeyFile=\nborgBaseDir=\nborgRepo=\nborgRepoPassword=\nborgRemote=\n" > ./sample.borgvars; then
consoleError 4 'Could not write sample borgvars file.' consoleError 4 'Could not write sample borgvars file.'
else else
exit 0 exit 0
@ -273,8 +276,8 @@ if [ "$operation" = 'restore' ]; then
if [ -d "$restorePath" ]; then if [ -d "$restorePath" ]; then
# convert to absolute path # convert to absolute path
restorePath=$( restorePath=$(
cd "$restorePath" || cd "$restorePath" || \
consoleError 5 'Cannot access specified restore directory.' consoleError 5 'Cannot access specified restore directory.'; \
pwd -P pwd -P
) )
if ! touch "${restorePath}/touch.test" > /dev/null 2>&1; then if ! touch "${restorePath}/touch.test" > /dev/null 2>&1; then
@ -286,8 +289,8 @@ if [ "$operation" = 'restore' ]; then
else else
# convert to absolute path # convert to absolute path
restorePath=$( restorePath=$(
cd "$restorePath" || cd "$restorePath" || \
consoleError 5 'Cannot access specified restore directory.' consoleError 5 'Cannot access specified restore directory.'; \
pwd -P pwd -P
) )
if ! touch "${restorePath}/touch.test" > /dev/null 2>&1; then if ! touch "${restorePath}/touch.test" > /dev/null 2>&1; then
@ -303,12 +306,10 @@ fi
case "${varsFile}" in case "${varsFile}" in
/*) /*)
# absolute path, no need to rewrite variable # absolute path, no need to rewrite variable
# shellcheck disable=SC1090
. "${varsFile}" . "${varsFile}"
;; ;;
*) *)
# relative path, prepend './' to create absolute path # relative path, prepend './' to create absolute path
# shellcheck disable=SC1090
. "./${varsFile}" . "./${varsFile}"
;; ;;
esac esac
@ -322,7 +323,6 @@ fi
export BORG_BASE_DIR="${borgBaseDir%/}" export BORG_BASE_DIR="${borgBaseDir%/}"
## check path to SSH keyfile ## check path to SSH keyfile
# shellcheck disable=SC2154
if [ -z "${sshKeyFile}" ]; then if [ -z "${sshKeyFile}" ]; then
consoleError 2 "$varsFile: 'sshKeyFile' is not specified." consoleError 2 "$varsFile: 'sshKeyFile' is not specified."
elif [ ! -f "${sshKeyFile}" ]; then elif [ ! -f "${sshKeyFile}" ]; then
@ -331,14 +331,12 @@ fi
export BORG_RSH="ssh -i ${sshKeyFile}" export BORG_RSH="ssh -i ${sshKeyFile}"
# check borg repo connect string # check borg repo connect string
# shellcheck disable=SC2154
if [ -z "${borgRepo}" ]; then if [ -z "${borgRepo}" ]; then
consoleError 2 "$varsFile: 'borgRepo' is not specified." consoleError 2 "$varsFile: 'borgRepo' is not specified."
fi fi
export BORG_REPO="${borgRepo}" export BORG_REPO="${borgRepo}"
# check borg repo password # check borg repo password
# shellcheck disable=SC2154
if [ -n "${borgRepoPassword}" ]; then if [ -n "${borgRepoPassword}" ]; then
export BORG_PASSPHRASE="${borgRepoPassword}" export BORG_PASSPHRASE="${borgRepoPassword}"
elif [ "${borgRepoPassword}" = 'none' ]; then elif [ "${borgRepoPassword}" = 'none' ]; then
@ -347,16 +345,10 @@ 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 fi
# check borg keyfile if supplied
# shellcheck disable=SC2154
if [ -n "${borgRepoKey}" ]; then
export BORG_KEY_FILE="${borgRepoKey}"
fi
# export borg remote path, if specified # export borg remote path, if specified
# shellcheck disable=SC2154
if [ -n "${borgRemote}" ]; then export BORG_REMOTE_PATH="${borgRemote}"; fi if [ -n "${borgRemote}" ]; then export BORG_REMOTE_PATH="${borgRemote}"; fi
### create borg temp dir: ### create borg temp dir:
## python requires a writable temporary directory when unpacking borg and ## python requires a writable temporary directory when unpacking borg and
## executing commands. This defaults to /tmp but many systems mount /tmp with ## executing commands. This defaults to /tmp but many systems mount /tmp with
@ -371,6 +363,7 @@ if [ ! -d "${borgBaseDir}/tmp" ]; then
fi fi
export TMPDIR="${borgBaseDir}/tmp" export TMPDIR="${borgBaseDir}/tmp"
### execute borg operations ### execute borg operations
# info operations # info operations
@ -391,31 +384,29 @@ elif [ "$operation" = 'restore' ]; then
if [ -z "$fileName" ]; then if [ -z "$fileName" ]; then
# restore entire archive # restore entire archive
if [ "$exclusions" ]; then if [ "$exclusions" ]; then
# shellcheck disable=SC2086
borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}" --exclude "${exclusions}" borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}" --exclude "${exclusions}"
else else
# shellcheck disable=SC2086
borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}" borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}"
fi fi
elif [ "$fileName" ]; then elif [ "$fileName" ]; then
# restore file/pattern # restore file/pattern
if [ "$exclusions" ]; then if [ "$exclusions" ]; then
# shellcheck disable=SC2086
borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}" "${fileName}" --exclude "${exclusions}" borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}" "${fileName}" --exclude "${exclusions}"
else else
# shellcheck disable=SC2086
borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}" "${fileName}" borg --show-rc ${commonOptions} extract ${restoreOptions} ::"${archiveName}" "${fileName}"
fi fi
fi fi
fi fi
### exit gracefully ### exit gracefully
cleanup cleanup
exit 0 exit 0
### exit codes ### exit codes
# 0: no errors, script completed successfully # 0: no errors, script completed successfully
# 1: parameter error (missing, non-existent 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?) # 4: could not write sample borgvars file (permissions?)