8 Usage: $0 DATASET@SNAPPREFIX snap-initial
9 $0 DATASET@SNAPPREFIX snap
10 $0 DATASET@SNAPPREFIX sync-initial DST
11 $0 DATASET@SNAPPREFIX sync DST
12 $0 DATASET@SNAPPREFIX clean COUNT
20 mkfifo $dst/$latest_filename.zfs.zst.age
21 echo $dst/$latest_filename.zfs.zst.age
25 enccmd=(~stargrave/bin/age -R /home/stargrave/.age/general.pub)
27 [[ $# -ge 2 ]] || usage
32 zmodload -F zsh/datetime b:strftime
33 now=$(strftime %Y%m%d%H%M)
34 [[ $what =~ / ]] && depth=1 || depth=${#${(s./.)what}}
35 snaps=$(zfs list -t snap -d $depth -o name -H | grep $what | sort -nr)
38 latest_filename=${latest:gs#/#%}
43 zfs snap -r $what-$now
48 [[ "$what-$now" != $latest ]]
49 zfs snap -r $what-$now
53 [[ -d $dst ]] || usage
56 zfs send -Rwv $latest | zstdmt | $enccmd > $dst/$latest_filename.zfs.zst.age
58 touch $dst/$latest_filename.from
61 [[ -d $dst ]] || usage
63 latest_dst=($dst/*.from~$dst/.*(.Onn[1]))
65 latest_dst=${latest_dst[1]}
66 latest_dst=${${latest_dst##*/}%.from}
67 [[ $latest_dst != $latest_filename ]]
70 zfs send -Rwv -i ${latest_dst:gs#%#/} $latest | zstdmt | $enccmd > \
71 $dst/$latest_filename.zfs.zst.age
74 print $latest_dst > $dst/$latest_filename.from
78 [[ -n $count ]] || usage
79 count=$(( $count + 1 ))
80 for snap in $snaps ; do
81 count=$(( $count - 1 ))
82 [[ $count -le 0 ]] || continue