Compare commits
No commits in common. "02a27f55a1b56825359fd5d9d82aad98045a70b3" and "bce1d63c9bc5e88ee3e2eeda77c31c192e84800f" have entirely different histories.
02a27f55a1
...
bce1d63c9b
81
.gitattributes
vendored
81
.gitattributes
vendored
@ -1,81 +0,0 @@
|
|||||||
# Common settings that generally should always be used with your language specific settings
|
|
||||||
|
|
||||||
# Auto detect text files and perform LF normalization
|
|
||||||
# https://www.davidlaing.com/2012/09/19/customise-your-gitattributes-to-become-a-git-ninja/
|
|
||||||
* text=auto
|
|
||||||
|
|
||||||
#
|
|
||||||
# The above will handle all files NOT found below
|
|
||||||
#
|
|
||||||
|
|
||||||
# Documents
|
|
||||||
*.bibtex text diff=bibtex
|
|
||||||
*.doc diff=astextplain
|
|
||||||
*.DOC diff=astextplain
|
|
||||||
*.docx diff=astextplain
|
|
||||||
*.DOCX diff=astextplain
|
|
||||||
*.dot diff=astextplain
|
|
||||||
*.DOT diff=astextplain
|
|
||||||
*.pdf diff=astextplain
|
|
||||||
*.PDF diff=astextplain
|
|
||||||
*.rtf diff=astextplain
|
|
||||||
*.RTF diff=astextplain
|
|
||||||
*.md text
|
|
||||||
*.tex text diff=tex
|
|
||||||
*.adoc text
|
|
||||||
*.textile text
|
|
||||||
*.mustache text
|
|
||||||
*.csv text
|
|
||||||
*.tab text
|
|
||||||
*.tsv text
|
|
||||||
*.txt text
|
|
||||||
*.sql text
|
|
||||||
|
|
||||||
# Graphics
|
|
||||||
*.png binary
|
|
||||||
*.jpg binary
|
|
||||||
*.jpeg binary
|
|
||||||
*.gif binary
|
|
||||||
*.tif binary
|
|
||||||
*.tiff binary
|
|
||||||
*.ico binary
|
|
||||||
# SVG treated as an asset (binary) by default.
|
|
||||||
*.svg text
|
|
||||||
# If you want to treat it as binary,
|
|
||||||
# use the following line instead.
|
|
||||||
# *.svg binary
|
|
||||||
*.eps binary
|
|
||||||
|
|
||||||
# Scripts
|
|
||||||
*.bash text eol=lf
|
|
||||||
*.fish text eol=lf
|
|
||||||
*.sh text eol=lf
|
|
||||||
# These are explicitly windows files and should use crlf
|
|
||||||
*.bat text eol=crlf
|
|
||||||
*.cmd text eol=crlf
|
|
||||||
*.ps1 text eol=crlf
|
|
||||||
|
|
||||||
# Serialisation
|
|
||||||
*.json text
|
|
||||||
*.toml text
|
|
||||||
*.xml text
|
|
||||||
*.yaml text
|
|
||||||
*.yml text
|
|
||||||
|
|
||||||
# Archives
|
|
||||||
*.7z binary
|
|
||||||
*.gz binary
|
|
||||||
*.tar binary
|
|
||||||
*.tgz binary
|
|
||||||
*.zip binary
|
|
||||||
|
|
||||||
# Text files where line endings should be preserved
|
|
||||||
*.patch -text
|
|
||||||
|
|
||||||
#
|
|
||||||
# Exclude files from exporting
|
|
||||||
#
|
|
||||||
|
|
||||||
.gitattributes export-ignore
|
|
||||||
.gitignore export-ignore
|
|
||||||
.vscode export-ignore
|
|
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,10 +0,0 @@
|
|||||||
.vscode/*
|
|
||||||
!.vscode/settings.json
|
|
||||||
!.vscode/tasks.json
|
|
||||||
!.vscode/launch.json
|
|
||||||
!.vscode/extensions.json
|
|
||||||
*.code-workspace
|
|
||||||
!.vscode/numbered-bookmarks.json
|
|
||||||
|
|
||||||
# don't track testing version of .vars file
|
|
||||||
*.borgvars
|
|
3
.vscode/numbered-bookmarks.json
vendored
3
.vscode/numbered-bookmarks.json
vendored
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"bookmarks": []
|
|
||||||
}
|
|
@ -1,3 +1,3 @@
|
|||||||
# borgScripts
|
# borgScripts
|
||||||
|
|
||||||
Pull various environment variables from a central file and save the typing associated with viewing and restoring borg archives.
|
semi-automate viewing and restoring data from borg repos
|
191
borghelper.sh
191
borghelper.sh
@ -1,191 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
#
|
|
||||||
## borg helper script for viewing and restoring backups
|
|
||||||
#
|
|
||||||
|
|
||||||
### trap
|
|
||||||
trap trapExit 1 2 3 6
|
|
||||||
|
|
||||||
### functions
|
|
||||||
consoleError() {
|
|
||||||
printf "%s\n%s\n" "$err" "$2"
|
|
||||||
printf "Exiting.\n\n%s" "$norm"
|
|
||||||
exit "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
textblock() {
|
|
||||||
printf "%s\n" "$1" | fold -w "$width" -s
|
|
||||||
}
|
|
||||||
|
|
||||||
trapExit () {
|
|
||||||
printf "%s\nScript execution terminated via signal.\n\n%s" "$err" "$norm"
|
|
||||||
exit 99
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
### text formatting presets
|
|
||||||
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
|
|
||||||
|
|
||||||
# has a parameter been passed to this script?
|
|
||||||
if [ -z "$1" ]; then
|
|
||||||
consoleError 1 "No operation requested. Please run this script with '--help' for valid parameters."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# process startup parameters
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
-a|--archive)
|
|
||||||
# name of backup archive
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
consoleError 1 "Please provide the name of the backup archive you want to work with or use '--list-all' to get a full list."
|
|
||||||
fi
|
|
||||||
archiveName="$2"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-f|--file)
|
|
||||||
# specific file to restore
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
consoleError 1 'Please provide the name of the specific file you want to restore.'
|
|
||||||
fi
|
|
||||||
fileName="$2"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-h|-\?|--help)
|
|
||||||
# display help
|
|
||||||
printf "\nStill working on the help text :-)\n\n"
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
-l|--list)
|
|
||||||
# list contents of specific backup
|
|
||||||
operation='viewarchive'
|
|
||||||
;;
|
|
||||||
|
|
||||||
-la|--list-all)
|
|
||||||
# list all backup archives
|
|
||||||
operation='listall'
|
|
||||||
;;
|
|
||||||
-p|--path)
|
|
||||||
# path to restore files
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
consoleError 1 'Please specify a path where you want files restored.'
|
|
||||||
fi
|
|
||||||
restorePath="${2%/}"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
-r|--restore)
|
|
||||||
# restore archive/file
|
|
||||||
operation='restore'
|
|
||||||
;;
|
|
||||||
-v|--vars)
|
|
||||||
# location of borgvars file
|
|
||||||
if [ -z "$2" ]; then
|
|
||||||
consoleError 1 'Please provide the path to the file with your borg connection information.'
|
|
||||||
elif [ ! -f "$2" ]; then
|
|
||||||
consoleError 1 'The specified borg connection information file does not exist.'
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
varsFile="$2"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
# invalid option
|
|
||||||
printf "%s\nUnknown option: %s\n" "$err" "$1"
|
|
||||||
printf "Use '--help' for valid options.\n\n%s" "$norm"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
|
|
||||||
### check parameter validity
|
|
||||||
|
|
||||||
# no operation
|
|
||||||
if [ -z "$operation" ]; then
|
|
||||||
consoleError 1 'Nothing to do!'
|
|
||||||
fi
|
|
||||||
|
|
||||||
# no borg information file
|
|
||||||
if [ -z "$varsFile" ]; then
|
|
||||||
consoleError 1 'You must provide a valid .borgvars file with information about your borg repo.'
|
|
||||||
fi
|
|
||||||
|
|
||||||
# list without archive
|
|
||||||
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
|
|
||||||
|
|
||||||
# restore with no path
|
|
||||||
if [ "$operation" = 'restore' ] && [ -z "$restorePath" ]; then
|
|
||||||
consoleError 1 "Restore operation requested but no restore path provided."
|
|
||||||
# restore with no archive
|
|
||||||
elif [ "$operation" = 'restore' ] && [ -z "$archiveName" ]; then
|
|
||||||
consoleError 1 "Restore operation requested but no archive name provided."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# file provided but no archive
|
|
||||||
if [ "$fileName" ] && [ -z "$archiveName" ]; then
|
|
||||||
consoleError 1 "Filename specified without an associated archive name."
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
### read borg information file
|
|
||||||
|
|
||||||
# check if file was provided as a relative or absolute path
|
|
||||||
case "${varsFile}" in
|
|
||||||
/*)
|
|
||||||
# absolute path, no need to rewrite variable
|
|
||||||
. "${varsFile}"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
# relative path, prepend './' to create absolute path
|
|
||||||
. "./${varsFile}"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# verify borg base directory
|
|
||||||
if [ -z "${borgBaseDir}" ]; then
|
|
||||||
consoleError 2 "$varsFile: 'borgBaseDir' is not specified."
|
|
||||||
elif [ ! -d "${borgBaseDir}" ]; then
|
|
||||||
consoleError 2 "$varsFile: 'borgBaseDir' does not exist."
|
|
||||||
fi
|
|
||||||
export BORG_BASE_DIR="${borgBaseDir%/}"
|
|
||||||
|
|
||||||
## check path to SSH keyfile
|
|
||||||
if [ -z "${sshKeyFile}" ]; then
|
|
||||||
consoleError 2 "$varsFile: 'sshKeyFile' is not specified."
|
|
||||||
elif [ ! -f "${sshKeyFile}" ]; then
|
|
||||||
consoleError 2 "$varsFile: 'sshKeyFile' does not exist."
|
|
||||||
fi
|
|
||||||
export BORG_RSH="ssh -i ${sshKeyFile}"
|
|
||||||
|
|
||||||
# check borg repo connect string
|
|
||||||
if [ -z "${borgRepo}" ]; then
|
|
||||||
consoleError 2 "$varsFile: 'borgRepo' is not specified."
|
|
||||||
fi
|
|
||||||
export BORG_REPO="${borgRepo}"
|
|
||||||
|
|
||||||
# check borg repo password
|
|
||||||
if [ -n "${borgRepoPassword}" ]; then
|
|
||||||
export BORG_PASSPHRASE="${borgRepoPassword}"
|
|
||||||
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!)."
|
|
||||||
fi
|
|
||||||
|
|
||||||
# export borg remote path, if specified
|
|
||||||
if [ -n "${borgRemote}" ]; then export BORG_REMOTE_PATH="${borgRemote}"; fi
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user