diff options
| -rwxr-xr-x | bin/bust | 104 | ||||
| -rwxr-xr-x | bin/bust-hostfs | 40 |
2 files changed, 144 insertions, 0 deletions
diff --git a/bin/bust b/bin/bust new file mode 100755 index 0000000..572b30c --- /dev/null +++ b/bin/bust @@ -0,0 +1,104 @@ +#!/usr/bin/env bash + +## :bocs: +## :section: X +## :heading: authors +## +## - Patrick Spek `<p.spek@tyil.nl>` + +readonly BUST_BIN_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" + +main() { + while getopts ":lnh" OPT; do + case "$OPT" in + l) + PATH="$BUST_BIN_DIR:$PATH" + ;; + n) + export BUST_DRYRUN=1 + ;; + h) + usage + exit 0 + ;; + *) + usage + ;; + esac + done + shift $(( OPTIND - 1 )) + + local script="$1" ; shift + + # Make sure there is a backup script given + if [[ -z "$script" ]] + then + usage + exit 1 + fi + + # Check if the desired backup script exists + if ! command -v "bust-$script" > /dev/null + then + usage + exit 1 + fi + + export BUST_SCRIPT="$script" + export -f passphrase + + exec "bust-$script" "$@" +} + +## :bocs: +## :section: 1 +## :heading: synopsis +## +## ``` +## bust -h +## bust [-l] database-psql +## bust [-l] filesystem +## ``` + +## :bocs: +## :section: 1 +## :heading: description +## +## **bust** is a set of Bash scripts to call Borg to create backups of your +## data. + +## :bocs: +## :section: 1 +## :heading: examples +## +## NYI + +## :bocs: +## :section: 1 +## :heading: see also +## +## - bust-filesystem +## - bust-database-psql + +usage() { + cat <<EOF +Usage: + $0 -h + $0 [-l] database-psql + $0 [-l] filesystem + +Options: + -l Prepend the directory containing the bust program to your PATH. + Useful for testing purposes. + +Create borg-based backups with a single command. +EOF +} + +passphrase() { + [[ -n $BORG_PASSPHRASE ]] && printf "%s" "$BORG_PASSPHRASE" && return + [[ -x /etc/bust/passphrase ]] && /etc/bust/passphrase && return + [[ -f /etc/bust/passphrase ]] && cat /etc/bust/passphrase && return +} + +main "$@" diff --git a/bin/bust-hostfs b/bin/bust-hostfs new file mode 100755 index 0000000..4b62e3d --- /dev/null +++ b/bin/bust-hostfs @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +main() { + while read -r repo proto + do + mkbackup "$repo" "$proto" + done < /etc/bust/repositories +} + +mkbackup() { + local repo="$1" ; shift + local proto="$1" ; shift + + local borg + + export BORG_PASSPHRASE="$(passphrase)" + + borg=( + "borg" "create" + "--one-file-system" + "--remote-path" "$proto" + "$repo/hostfs::$(date -u "+%FT%TZ")" + ) + + while read -r path + do + borg+=("$path") + done < /etc/bust/filesystem.d/paths + + printf "> %s\n" "${borg[*]}" + + if [[ -n $BUST_DRYRUN ]] + then + return 0 + fi + + ${borg[@]} +} + +main "$@" |
