3 setopt ERR_EXIT EXTENDED_GLOB
7 Usage: $0 DATASET@SNAPPREFIX snap-initial
8 $0 DATASET@SNAPPREFIX snap
9 $0 DATASET@SNAPPREFIX sync-initial DST
10 $0 DATASET@SNAPPREFIX sync DST
11 $0 DATASET@SNAPPREFIX clean COUNT
19 mkfifo $dst/$latest_filename.zfs.zst.age
20 echo $dst/$latest_filename.zfs.zst.age
24 enccmd=(~stargrave/bin/age -R /home/stargrave/.age/general.pub)
26 [[ $# -ge 2 ]] || usage
31 zmodload -F zsh/datetime b:strftime
32 now=$(strftime %Y%m%d%H%M)
33 [[ $what =~ / ]] && depth=1 || depth=${#${(s./.)what}}
34 snaps=$(zfs list -t snap -d $depth -o name -H | grep $what | sort -nr)
37 latest_filename=${latest:gs#/#%}
42 zfs snap -r $what-$now
47 [[ "$what-$now" != $latest ]]
48 zfs snap -r $what-$now
52 [[ -d $dst ]] || usage
55 zfs send -Rwv $latest | zstdmt | $enccmd > $dst/$latest_filename.zfs.zst.age
57 touch $dst/$latest_filename.from
60 [[ -d $dst ]] || usage
62 latest_dst=($dst/*.from~$dst/.*(.Onn[1]))
64 latest_dst=${latest_dst[1]}
65 latest_dst=${${latest_dst##*/}%.from}
66 [[ $latest_dst != $latest_filename ]]
69 zfs send -Rwv -i ${latest_dst:gs#%#/} $latest | zstdmt | $enccmd > \
70 $dst/$latest_filename.zfs.zst.age
73 print $latest_dst > $dst/$latest_filename.from
77 [[ -n $count ]] || usage
78 count=$(( $count + 1 ))
79 for snap in $snaps ; do
80 count=$(( $count - 1 ))
81 [[ $count -le 0 ]] || continue