Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to send from an unencrypted zfs pool to an encrypted zfs pool
#!/bin/sh
set -e
set -u
send=$1
receive=$2
echo "from $send"
echo "to $receive"
for _fs in $(zfs list -H -o name -t filesystem -r "$send"); do
fs=${_fs#$send}
if [ -z "$fs" ]; then continue; fi
first=$(zfs list -H -o name -t snapshot -r "$send$fs"|grep "^$send$fs@"|sed -ne '1s/.*@//p')
last=$(zfs list -H -o name -t snapshot -r "$send$fs"|grep "^$send$fs@"|sed -ne '$s/.*@//p')
echo "filesystem : ${fs:-<root>} from $first to $last"
size=$(zfs send -nP -p "$send$fs@$first" | awk '$1 == "size" {print $2}')
echo "full stream of $send$fs@$first into $receive$fs@$first"
zfs send -p "$send$fs@$first" | pv -p -t -e -r -b -s "$size" | zfs receive -x encryption -u "$receive$fs"
size=$(zfs send -nP -p -I "@$first" "$send$fs@$last" | awk '$1 == "size" {print $2}')
echo "incremental stream from $send$fs@$first to @$last"
zfs send -p -I "@$first" "$send$fs@$last" | pv -p -t -e -r -b -s "$size" | zfs receive -u "$receive$fs"
done
# vim:set ts=4 sw=4 ft=sh et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment