ZFS is a great filesystem: it’s based on a copy-on-write transactional model, it supports dynamic striping of data across all devices, it supports a transparent compression and many more features, but the more interesting feature to me is the support for snapshot and clones.
I feel interesting snapshots and clones primarily for backups: using a snapshot could be very trivial making a backup of the filesystem, moreover it’s possible making incremental backup with snapshots.
Although ZFS is developed primary for Solaris and OpenSolaris, it’s possible to use it on GNU/Linux through FUSE (Filesytem in Userspace), so it’s possible to use ZFS on GNU/Linux for all purposes (although could be very trouble using it for the root filesystem).
Fedora (10 or 11 ones) is pretty ready for using ZFS: it’s available a package (zfs-fuse) for ZFS-FUSE on the official repository, so the first step for using ZFS is installing this package with yum:
yum install zfs-fuse
Then it’s possible to create the pool of devices containing the filesystems and the filesystems; first of all I’ve created a pool on a partition of one of the harddisks of mine; before creating the book I’ve labelled the partition “ZFS” using “Palimpsest Disk Utility”, so I’ve created the pool with:
zpool create zfs /dev/disk/by-label/ZFS
And then the filesystems, setting the use of compression and disabling the storing of file access time:
zfs create zfs/home zfs set compression=on zfs/home zfs set atime=off zfs/home zfs create zfs/home/cjg
Finally I’ve setted the mount point for the home filesystem:
zfs set mountpoint=/home zfs/home
Les jeux sont fait! From the next reboot I’ll use ZFS for my /home partition.
Now I had to create a new pool for storing the backups, I’ve created it on another partition of another disk (the partition is labelled “ZFSBACKUP”):
zpool create zfsbackup /dev/disk/by-label/ZFSBACKUP zfs create zfs/home zfs set compression=on zfs/home zfs set atime=off zfs/home
I want that all backups will be stored on the zfsbackup pool and I want, also, to use incremental backups, so I’ve setted up a simple script for making incremental backups from the zfs pool to the zfsbackup pool:
#!/bin/bash DATE=`date +%F-%H-%M` zfs snapshot zfs/home/cjg@$DATE zfs send -i latest zfs/home/cjg@$DATE > dump zfs recv zfsbackup/home/cjg < dump rm dump zfs destroy zfs/home/cjg@latest zfs rename zfs/home/cjg@$DATE zfs/home/cjg@latest # End Of File
Simply it creates a snapshot of the zfs/home/cjg filesystem and calling it with the current date and time, then with “zfs send” it creates an incremental replication from the latest snapshot, then the replication it’s importend on zfsbackup/home/cjg, the latest snapshot on zfs/home/cjg is removed and the current snapshot is renamed as the latest.
In this way all the snapshot’s history is stored only on the zfsbackup pool.
Before using this script for the first time I had to create the “latest” snapshot on zfs/home/cjg and send it to zfsbackup/home/cjg with:
zfs snapshot zfs/home/cjg@latest zfs send zfs/home/cjg@latest > dump zfs recv zfsbackup/home/cjg < dump
To access a particular snapshot it’s possible to use:
zfs clone zfsbackup/home/cjg@2009-05-02-12-33 zfsbackup/home/2009-05-02-12-33
So it’s possible to access to the snapshot file through “/zfsbackup/home/2009-05-02-12-33″; of course it’s possible to use “zfs rollback” to restore the filesystem from a snapshot.
When the clone isn’t needed anymore it’s possible to remove it with
zfs destroy zfsbackup/home/2009-05-02-12-33