Link Search Menu Expand Document

Duplicate ZFS pool over SSH

To duplicate a zfs pool over ssh you must first create a recursive snapshot of the pool you want to copy

# zfs snapshot -r [email protected]
# zfs list -t snapshot
NAME                              USED  AVAIL  REFER  MOUNTPOINT
[email protected]                      0      -    21K  -
tank/[email protected]              136K      -   573M  -
tank/[email protected]                 0      -    16K  -
tank/[email protected]                  0      -  5.28M  -
tank/[email protected]               182K      -  6.26G  -
tank/[email protected]               352K      -   116M  -

On the target server setup the target pool

# zpool create tank mirror gpt/disk01 gpt/disk02
# zpool status
  pool: tank
 state: ONLINE
 scan: none requested

	tank            ONLINE       0     0     0
	  mirror-0      ONLINE       0     0     0
	    gpt/disk00  ONLINE       0     0     0
	    gpt/disk01  ONLINE       0     0     0

errors: No known data errors

Now make sure you can ssh to the target server from the source server, you will need to do this as root. You may need to edit your /etc/ssh/sshd_config and set PermitRootLogin yes. Then restart ssh, killall -1 sshd or /etc/rc.d/sshd restart.

Make sure you can login

If this works you can now send the pool over ssh to the target server.

# zfs send -R [email protected] | ssh "zfs recv -vFd tank"

Once finished your target zpool will look like this

# zfs list -t all
NAME                              USED  AVAIL  REFER  MOUNTPOINT
tank                              127G   145G    21K  none
[email protected]                      0      -    21K  -
tank/root                         573M   145G   573M  /mnt
tank/[email protected]                 0      -   573M  -
tank/swap                        4.00G   149G    16K  -
tank/[email protected]                 0      -    16K  -
tank/tmp                         5.28M   145G  5.28M  /mnt/tmp
tank/[email protected]                  0      -  5.28M  -
tank/usr                         6.40G   145G  6.26G  /mnt/usr
tank/[email protected]                  0      -  6.26G  -
tank/var                          116M   145G   116M  /mnt/var
tank/[email protected]                  0      -   116M  -

If you wish you can delete the snapshot.

If you plan on booting of the target pool you will also need to set the bootfs on the pool

# zpool set bootfs=tank/root tank

Import and Export to make sure all changes are written to the disk and the copy the cache to the new pool.

# zpool export data

Again if you are using zpool v28 then add the cache file path

# zpool import -o altroot=/mnt -o cachefile=/boot/zfs/zpool.cache data

Other wise

# zpool import -o altroot=/mnt data


# cp /boot/zfs/zpool.cache /mnt/boot/zfs/

Now you can reboot