Created
May 15, 2023 08:40
-
-
Save hilbix/16a94776ef687a092f4c338e76aa1069 to your computer and use it in GitHub Desktop.
Borg Backup Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # vim: ft=bash | |
| # | |
| # borg init -enone `hostname -f` | |
| STDOUT() { printf '%q' "$1"; printf ' %q' "${@:2}"; printf '\n'; } | |
| STDERR() { local e=$?; STDOUT "$@" >&2; return $e; } | |
| OOPS() { STDERR OOPS: "$@"; exit 23; } | |
| x() { "$@"; STDERR exec $?: "$@"; } | |
| o() { x "$@" || OOPS fail $?: "$@"; } | |
| v() { local -n __var__="$1"; __var__="$("${@:2}")"; } | |
| ov() { v "$@" || OOPS fail $?: set "$1" from "${@:2}"; } | |
| ov DIR dirname -- "$0" | |
| o cd "$DIR" | |
| ov HOST hostname -f | |
| [ -d "$HOST" ] && [ -f "$HOST/README" ] && [ -d "$HOST/data" ] || OOPS please create "$HOST" first | |
| o printf -v NAME '%s::backup-%(%Y%m%d-%H%M%S)T' "$HOST" -1 | |
| LIST=() | |
| declare -A FS | |
| while read -ru6 src dst rest | |
| do | |
| case "$src" in | |
| (/dev/loop*) continue;; # ignore snap | |
| (/*) ;; # only use real mounts | |
| (*) continue;; # ignore synthetic | |
| esac | |
| # Record SRC only once (SNAP uses binding mounts) | |
| [ -n "${FS["$src"]}" ] && continue | |
| FS["$src"]="$dst" | |
| LIST+=("$dst") | |
| done 6</proc/mounts | |
| o borg create --stats --progress --one-file-system "$NAME" "${LIST[@]}" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Resistance is
futileBUPI stopped using Borg and now rather use
BUP.Because it just works and reuses the
gitstructures.