Created
January 7, 2021 12:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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