[ "$BACKUP_SNAP" -eq 1 ] && bsnap on
+cd "$BACKUP_PATH"
+
borg create \
$([ -t 0 ] && echo --progress) \
--info --stats \
--compression lz4 \
--exclude-from "$BACKUP_EXCLUDE_FILE" \
- "${BACKUP_REPO}::{hostname}-{now}" "$BACKUP_PATH"
+ "${BACKUP_REPO}::{hostname}-{now}" .
borg prune \
--info --stats \
cd "$(dirname "$0")"
-BORG_PASSPHRASE="$(dd if=/dev/urandom of=/dev/stdout bs=1 count=15 2>/dev/null | base64)"
+install -m 0755 backup /usr/local/bin/
+
+if [ "${1:-}" != "full" ]; then
+ exit 0
+fi
-install -m 0755 bsnap backup /usr/local/bin/
+BORG_PASSPHRASE="$(dd if=/dev/urandom of=/dev/stdout bs=1 count=15 2>/dev/null | base64)"
install -m 0644 -T etc-borg-exclude /etc/borg-exclude
install -m 0600 -T etc-borg-env /etc/borg-env
sed -i "s|SECRET|$BORG_PASSPHRASE|" /etc/borg-env
+++ /dev/null
-#!/bin/bash
-
-set -eux
-
-cd "$(dirname "$0")"
-
-install -m 0755 bsnap backup /usr/local/bin/
-
-grep -q BACKUP_PATH /etc/borg-env || sed -i '1s|^|BACKUP_PATH=/a\n|' /etc/borg-env
-grep -q BACKUP_SNAP /etc/borg-env || sed -i '1s|^|BACKUP_SNAP=1\n|' /etc/borg-env
-grep -q BACKUP_EXCLUDE_FILE /etc/borg-env || sed -i '1s|^|BACKUP_EXCLUDE_FILE=/etc/borg-exclude\n|' /etc/borg-env
-
-sed -i 's|backup$|backup /etc/borg-env|' /etc/cron.d/backup
--- /dev/null
+#!/bin/bash
+
+set -eux
+
+cd "$(dirname "$0")"
+
+install -m 0755 bsnap /usr/local/bin/
--- /dev/null
+#!/bin/bash
+
+set -eu
+
+function snap {
+ unsnap
+
+ znap-list | xargs -n1 znap-mount /a
+}
+
+function unsnap {
+ znap-umount-all /a
+}
+
+if [ "$(id -u)" -ne 0 ]; then
+ echo "Must be root"
+ exit 1
+fi
+
+mkdir -p /a
+
+if [ "${1:-}" = "off" ]; then
+ unsnap
+elif [ "${1:-}" = "on" ]; then
+ snap
+else
+ echo "Usage: $0 on|off"
+ exit 1
+fi
--- /dev/null
+#!/bin/bash
+
+set -eux
+
+cd "$(dirname "$0")"
+
+install -m 0755 bsnap znap-list znap-mount znap-umount-all /usr/local/bin/
--- /dev/null
+#!/bin/bash
+
+set -eu
+
+function root_dataset {
+ mount | grep 'on / ' | cut -d' ' -f1
+}
+
+function find_latest_snapshot_timestamp {
+ zfs list -H -t snapshot -r "$(root_dataset)" -o name -S creation \
+ | grep @znap | head -n1 | cut -d'@' -f2
+}
+
+function list_snapshots {
+ local timestamp="$1"
+ zfs list -H -t snapshot -o name | grep "$timestamp"
+}
+
+list_snapshots "$(find_latest_snapshot_timestamp)"
--- /dev/null
+#!/bin/bash
+
+if [ -z "$1" ] || [ -z "$2" ]; then
+ echo "Usage: $0 prefix snapshot"
+ exit 1
+fi
+
+set -eu
+
+PREFIX="$1"
+SNAPSHOT="$2"
+DATASET="${SNAPSHOT%@*}"
+MOUNTPOINT="${PREFIX}/$(echo "$DATASET" | cut -d@ -f1 | cut -d/ -f2- | tr '/' '_')"
+
+if [ "$(zfs get -H -o value backup:skip "$DATASET")" = "true" ]; then
+ exit 0
+fi
+
+set -x
+mkdir -p "$MOUNTPOINT"
+mount -t zfs "$SNAPSHOT" "$MOUNTPOINT"
--- /dev/null
+#!/bin/bash
+
+if [ -z "$1" ]; then
+ echo "Usage: $0 prefix"
+ exit 1
+fi
+
+set -eu
+
+PREFIX="$1"
+
+set -x
+
+if ls &> /dev/null "$PREFIX"/*; then
+ umount "$PREFIX"/* || true
+ rmdir "$PREFIX"/* || true
+fi
+rmdir "$PREFIX" || true