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[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is how I use it:
/zfs/
Then to backup I just
/zfs/backup/.x
Easy and convenient.
Please note that I do not use BTRFS because I read too many horrible stories about what can go wrong. The solution always is "call a BTRFS expert".
In contrast, in over 10 years of ZFS use on Linux with LUKS, mirror, RAID and encrypted ZFS volumes, there was not a single issue, which ZFS was unable to automatically(!) repair. And I had many of them (over 100 drives used). ZFS survived even a catastrophic half NUL of a drive. And backing up ZFS with
zfs send | zfs receive
is already fully automated at my side. All I need to do to backup is to create a snapshot, which then is automatically picked up by my the ZFS backup server (well, I had to script this myself, but it works).When I read about BTRFS, it always is said:
zpool import
)zpool import
to go back in time or find it's structures.Note that I use ZFS on top of LVM and often LUKS.
This way I can use LVM to expand ZFS devices.
This works fully online if done properly.
But:
ZFS is not good for people who are not careful enough.
Because 90% of all guides out there tell plain bullshit, are highly dangerous or lead you into some dead end.
So before you follow what others tell you, test it first with some scratch system!
Read:
In contrast to BTRFS (not my experience but what I read):
None of these problems should be problems, as ZFS manages to overcome them all. The worst thing to repair all this was to reboot ..
That it is said that BTRFS needs less system resources is a nice-to-have which does not bring me to even test BTRFS. If BTRFS is ever reported as stable (repair wise for even weird problems) as ZFS, I will start to consider it.
Compare: