Skip to content

Instantly share code, notes, and snippets.

@hilbix
Created May 15, 2023 08:40
Show Gist options
  • Select an option

  • Save hilbix/16a94776ef687a092f4c338e76aa1069 to your computer and use it in GitHub Desktop.

Select an option

Save hilbix/16a94776ef687a092f4c338e76aa1069 to your computer and use it in GitHub Desktop.
Borg Backup Script
#!/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[@]}"
@hilbix
Copy link
Author

hilbix commented Oct 6, 2025

Resistance is futile BUP

I stopped using Borg and now rather use BUP.

Because it just works and reuses the git structures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment