Skip to content

Instantly share code, notes, and snippets.

@i8degrees
Last active April 14, 2024 15:42
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 i8degrees/4bcd583a0e4a4b9455808babe2b41057 to your computer and use it in GitHub Desktop.
Save i8degrees/4bcd583a0e4a4b9455808babe2b41057 to your computer and use it in GitHub Desktop.
ZFS pool replication
#!/bin/bash
#
# Replicate source pool target with a destination pool target
#
# SOURCE[(https://www.truenas.com/community/threads/how-to-move-a-dataset-from-one-zfs-pool-to-another-zfs-pool.75912/#post-714236)
#
MY_POOL_DEVICE="offsite2_fs1"
ZFS_DEST_POOL="offsite2_fs1.tmp"
zpool create \
-o ashift=12 \
-o comment="${MY_DEST_POOL} pool created $( date +%Y/%m/%d )" \
-O atime=off \
-O mountpoint=legacy \
-O compression=lz4 \
-O aclinherit=passthrough \
-O acltype=posixacl \
-f ${MY_DEST_POOL} ${MY_POOL_DEVICE}
#
# Snapshot the source pool
#
zfs snapshot -r ${MY_SRC_POOL}@${MY_SNAP}
#
# Copy pool
#
zfs send -Rpv ${MY_SRC_POOL}@${MY_SNAP} | \
zfs receive -dFu ${MY_DEST_POOL}
#
# Clean up source pool
#
zfs destroy -rv ${MY_SRC_POOL}@${MY_SNAP}
#
# Clean up destination pool
#
zfs destroy -rv ${MY_DEST_POOL}@${MY_SNAP}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment