config/scripts/snaplink
Motiejus Jakštys 098fd77b3e add snaplink
I know snaplink should be put to the nix store, but currently I have no idea how to do it.
2023-01-05 13:23:29 +02:00

11 lines
498 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
_fatal() { >&2 echo "ERROR: $*"; exit 1; }
mountpoint=$(zfs list -H -t filesystem -o mountpoint "$SANOID_TARGET")
[[ -n "$mountpoint" ]] || _fatal "expected non-empty $SANOID_TARGET"
snap_path="$mountpoint/.zfs/snapshot/$SANOID_SNAPNAME"
[[ -d "$snap_path" ]] || _fatal "expected to find a directory in $snap_path"
link_path="$mountpoint/.snapshot-latest"
ln -sf "$snap_path" "$link_path"
>&2 printf "successfully created %s -> %s\n" "$link_path" "$snap_path"