From a4e75f98d7c4e9474bdc8c1c4470b2cbf12094d5 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 1 May 2023 22:20:55 -0400 Subject: [PATCH] Add scripts for zfs send and recv for making full clones. I most often need to make full clones when doing zfs send or recv so this writes down all the flags I prefer to use in a script so I do not forget them. --- ansible/roles/zfs/files/zfs_clone_recv.bash | 12 ++++++++++++ ansible/roles/zfs/files/zfs_clone_send.bash | 16 ++++++++++++++++ ansible/roles/zfs/tasks/common.yaml | 13 +++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 ansible/roles/zfs/files/zfs_clone_recv.bash create mode 100644 ansible/roles/zfs/files/zfs_clone_send.bash diff --git a/ansible/roles/zfs/files/zfs_clone_recv.bash b/ansible/roles/zfs/files/zfs_clone_recv.bash new file mode 100644 index 0000000..6c33a8c --- /dev/null +++ b/ansible/roles/zfs/files/zfs_clone_recv.bash @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# +# A zfs-send alias that creates a perfect clone with good defaults. +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# -s if the stream is interrupted, save the partial stream. The stream can then be resumed by doing a zfs send -t token where token is the receive_resume_token prop on the dataset we received into. +# -u Do not mount the filesystem we are receiving. We can always mount afterwards but this avoids issues with streams with mountpoints to places like / +zfs recv -s -u + +# To delete an interrupted recv, run `zfs receive -A dataset` diff --git a/ansible/roles/zfs/files/zfs_clone_send.bash b/ansible/roles/zfs/files/zfs_clone_send.bash new file mode 100644 index 0000000..a2de904 --- /dev/null +++ b/ansible/roles/zfs/files/zfs_clone_send.bash @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# +# A zfs-send alias that creates a perfect clone with good defaults. +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# TODO: Do we want --backup ? +# We get --props automatically from --replicate +zfs send --compressed --replicate --large-block --embed --verbose "${@}" + +# On zfs recv side, may want to pass `-s` to make the stream resumable. + +# If the data is encrypted and you DONT want to decrypt it, pass the --raw flag on the send side +# You may need to remove --embed above for encrypted datasets (maybe only with --raw flag? very unsure) +# For unencrypted datasets, --raw will be equivalent to -Lec (large block, embed, compressed) diff --git a/ansible/roles/zfs/tasks/common.yaml b/ansible/roles/zfs/tasks/common.yaml index fef1101..5952dc2 100644 --- a/ansible/roles/zfs/tasks/common.yaml +++ b/ansible/roles/zfs/tasks/common.yaml @@ -1,3 +1,16 @@ +- name: Install scripts + copy: + src: "files/{{ item.src }}" + dest: "{{ item.dest }}" + mode: 0755 + owner: root + group: wheel + loop: + - src: "zfs_clone_send.bash" + dest: /usr/local/bin/zfs_clone_send + - src: "zfs_clone_recv.bash" + dest: /usr/local/bin/zfs_clone_recv + - import_tasks: tasks/freebsd.yaml when: 'os_flavor == "freebsd"'