diff --git a/devices/teal/config/usr/local/bin/appdata-backup-cleanup.sh b/devices/teal/config/usr/local/bin/appdata-backup-cleanup.sh new file mode 100644 index 0000000..2f55ffc --- /dev/null +++ b/devices/teal/config/usr/local/bin/appdata-backup-cleanup.sh @@ -0,0 +1,13 @@ +#!/bin/bash +if [ -f /run/appdata_active_snapshot.txt ]; then + SNAPSHOT_NAME=$(cat /run/appdata_active_snapshot.txt) + + # Unmount and clean up scratch directory + umount -R /mnt/appdata-scratch || true + rmdir /mnt/appdata-scratch || true + + # Destroy the recursive snapshot tree across all appdata datasets + zfs destroy -r tank/appdata@"$SNAPSHOT_NAME" + + rm -f /run/appdata_active_snapshot.txt +fi diff --git a/devices/teal/config/usr/local/bin/appdata-backup-prep.sh b/devices/teal/config/usr/local/bin/appdata-backup-prep.sh new file mode 100644 index 0000000..333bb52 --- /dev/null +++ b/devices/teal/config/usr/local/bin/appdata-backup-prep.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -e + +SNAPSHOT_NAME="restic-auto-$(date +%Y%m%d_%H%M%S)" +echo "$SNAPSHOT_NAME" > /run/appdata_active_snapshot.txt + +# 1. Take a recursive snapshot from the top-level tank/appdata parent +zfs snapshot -r tank/appdata@"$SNAPSHOT_NAME" + +# 2. Mount the parent snapshot to a temporary scratch directory +mkdir -p /mnt/appdata-scratch +mount -t zfs tank/appdata@"$SNAPSHOT_NAME" /mnt/appdata-scratch