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
18 enccmd=(~stargrave/bin/age -R /home/stargrave/.age/general.pub)
20 [[ $# -ge 2 ]] || usage
25 zmodload -F zsh/datetime b:strftime
26 now=$(strftime %Y%m%d%H%M)
27 [[ $what =~ / ]] && depth=1 || depth=${#${(s./.)what}}
28 snaps=$(zfs list -t snap -d $depth -o name -H | grep $what | sort -nr)
31 latest_filename=${latest:gs#/#%}
34 mkfifo $dst/$latest_filename.zfs.zst.age
35 echo $dst/$latest_filename.zfs.zst.age
40 zfs snap -r $what-$now
45 [[ "$what-$now" != $latest ]]
46 zfs snap -r $what-$now
50 [[ -d $dst ]] || usage
52 zfs send -Rwv $latest | zstdmt | $enccmd > $dst/$latest_filename.zfs.zst.age
54 touch $dst/$latest_filename.from
57 [[ -d $dst ]] || usage
58 latest_dst=($dst/*.from~$dst/.*(.Onn[1]))
60 latest_dst=${latest_dst[1]}
61 latest_dst=${${latest_dst##*/}%.from}
62 [[ $latest_dst != $latest_filename ]]
65 zfs send -Rwv -i ${latest_dst:gs#%#/} $latest | zstdmt | $enccmd > \
66 $dst/$latest_filename.zfs.zst.age
69 print $latest_dst > $dst/$latest_filename.from
73 [[ -n $count ]] || usage
74 count=$(( $count + 1 ))
75 for snap in $snaps ; do
76 count=$(( $count - 1 ))
77 [[ $count -le 0 ]] || continue