Skip to content

Instantly share code, notes, and snippets.

@mat813
Created January 7, 2021 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mat813/1df8289812275f8964c3379c2e60b225 to your computer and use it in GitHub Desktop.
Save mat813/1df8289812275f8964c3379c2e60b225 to your computer and use it in GitHub Desktop.
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