Skip to content

Instantly share code, notes, and snippets.

@nicman23
Created December 17, 2022 15:44
Show Gist options
  • Save nicman23/151395663fe8038e5bc0a8c67e612a8a to your computer and use it in GitHub Desktop.
Save nicman23/151395663fe8038e5bc0a8c67e612a8a to your computer and use it in GitHub Desktop.
#!/bin/bash
find_list() {
a="$(zfs list -t filesystem,volume -s origin -H -o name,origin -r $1)"
grep -P -- '-$' <<< "$a" | cut -f1
grep -Pv -- '-$' <<< "$a"
}
SSH() {
ssh $remote_path $@
}
send_command() {
old=$3
has_mount=$2
new=$1
name=$(cut -f1 -d@ <<< "$new")
(
echo sending $(echo $new | cut -f 1 -d @) $([ ! -z "$old" ] && echo with incrimental $old)
SSH zfs create -p $trpool/$(dirname $name)
zfs send -Lc $([ ! -z "$old" ] && echo -i $old ) $new | #pv -s $(zfs list -t all -Ho used $new) |
SSH "zfs receive -Fu" $( [ "$has_mount" -eq 0 ] && echo -o mountpoint=none ) "$trpool/$name"
) < /dev/null
}
send() {
previous=$2
has_mount=$([[ "$(zfs get volsize zpool -Ho value)" != '-' ]]; echo $?)
zfs list -t snapshot -Ho name $1 | while read snapshot; do
send_command $snapshot $has_mount $previous
previous=$snapshot
done
}
remote_path=192.168.22.225
rpool=$(SSH zpool list -Ho name)
for zpool in $(zpool list -H -o name); do
trpool=$rpool/backups/$(hostname)
SSH zfs create -p $trpool
find_list $zpool | while read l; do
send $l
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment