November 12, 2017

ZFS - Export snapshot to encrypted file

This post shows some basic steps how to install ZFS on Ubuntu 16.04, create ZFS pool and file system. It also will cover snapshot creation and export it to encrypted file.

# Install ZFS tools.
apt install zfsutils-linux

# Create ZFS pool called Pool1 from single disk (/dev/xvdb)
zpool create Pool1 /dev/xvdb -f


# Check newly created pool.
zpool list
NAME   SIZE ALLOC  FREE EXPANDSZ  FRAG  CAP  DEDUP  HEALTH  ALTROOT
Pool1 49.8G   50K 49.7G        -    0%   0%  1.00x  ONLINE  -

# Create ZFS file system.
zfs create Pool1/Volume1

# Check ZFS file systems.
zfs list
NAME            USED  AVAIL  REFER  MOUNTPOINT
Pool1          81.5K  48.2G    19K  /Pool1
Pool1/Volume1    19K  48.2G    19K  /Pool1/Volume1

# Create ZFS snapshot.
zfs snapshot Pool1/Volume1@snapshot1

# List snapshots.
zfs list -t snapshot
NAME                      USED  AVAIL  REFER  MOUNTPOINT
Pool1/Volume1@snapshot1      0      -    19K  -

# Export ZFS snapshot, archive it using gzip and encrypt it by password.
zfs send Pool1/Volume1@snapshot1 | gzip | openssl enc -aes-256-cbc -pass pass:Your_Password > snapshot1.gz.enc

# Decrypt the snapshot file.
openssl enc -d -aes-256-cbc -pass pass:Your_Password -in snapshot1.gz.enc -out snapshot1.gz

# Mount shapshot as dedicated ZFS volume.
gzip -c -d snapshot1.gz | zfs receive Pool1/Volume1_Snapshot

# Check ZFS volumes.
zfs list
NAME                     USED  AVAIL  REFER  MOUNTPOINT
Pool1                    273K  48.2G    19K  /Pool1
Pool1/Volume1             19K  48.2G    19K  /Pool1/Volume1
Pool1/Volume1_Snapshot    19K  48.2G    19K  /Pool1/Volume1_Snapshot

No comments:

Post a Comment