To support high availability environments, providing an instant copy of the information on both the currently active machine and the hot backup is a critical part of the HA solution. There are many solutions to this problem, including Chapter 16, Replication and Section 14.1, “Using MySQL with DRBD”.
The ZFS filesystem provides functionality that allows you to create a snapshot of the filesystem contents and to then transfer the snapshot to another machine and extract the snapshot to recreate the filesystem. You can create a snapshot at any time, and you can create as many snapshots as you like. By continually creating, transferring and restoring snapshots you can provide synchronization between one ore more machines in a fashion similar to DRBD.
To understand the replication solution within ZFS, you must first
understand the ZFS environment. Below is a simple OpenSolaris system
running with two pools, the
root pool and another
pool mounted at
Filesystem size used avail capacity Mounted on rpool/ROOT/opensolaris-1 7.3G 3.6G 508M 88% / /devices 0K 0K 0K 0% /devices /dev 0K 0K 0K 0% /dev ctfs 0K 0K 0K 0% /system/contract proc 0K 0K 0K 0% /proc mnttab 0K 0K 0K 0% /etc/mnttab swap 465M 312K 465M 1% /etc/svc/volatile objfs 0K 0K 0K 0% /system/object sharefs 0K 0K 0K 0% /etc/dfs/sharetab /usr/lib/libc/libc_hwcap1.so.1 4.1G 3.6G 508M 88% /lib/libc.so.1 fd 0K 0K 0K 0% /dev/fd swap 466M 744K 465M 1% /tmp swap 465M 40K 465M 1% /var/run rpool/export 7.3G 19K 508M 1% /export rpool/export/home 7.3G 1.5G 508M 75% /export/home rpool 7.3G 60K 508M 1% /rpool rpool/ROOT 7.3G 18K 508M 1% /rpool/ROOT opt 7.8G 1.0G 6.8G 14% /opt
The MySQL data will be stored in a directory on
/opt. To help demonstrate some of the basic
replication functionality, there are also other items stored in
/opt as well:
total 17 drwxr-xr-x 31 root bin 50 Jul 21 07:32 DTT/ drwxr-xr-x 4 root bin 5 Jul 21 07:32 SUNWmlib/ drwxr-xr-x 14 root sys 16 Nov 5 09:56 SUNWspro/ drwxrwxrwx 19 1000 1000 40 Nov 6 19:16 emacs-22.1/
To create a snapshot of the filesystem, you use
snapshot, and then specify the pool and the snapshot name:
root-shell> zfs snapshot opt@snap1
To get a list of snapshots already taken:
root-shell> zfs list -t snapshot NAME USED AVAIL REFER MOUNTPOINT opt@snap1 0 - 1.03G - rpool@install 19.5K - 55K - rpool/ROOT@install 15K - 18K - rpool/ROOT/opensolaris-1@install 59.8M - 2.22G - rpool/ROOT/opensolaris-1@opensolaris-1 100M - 2.29G - rpool/ROOT/opensolaris-1/opt@install 0 - 3.61M - rpool/ROOT/opensolaris-1/opt@opensolaris-1 0 - 3.61M - rpool/export@install 15K - 19K - rpool/export/home@install 20K - 21K -
The snapshots themselves are stored within the filesystem metadata, and the space required to keep them will vary as time goes on because of the way the snapshots are created. The initial creation of a snapshot is really quick, because instead of taking an entire copy of the data and metadata required to hold the entire snapshot, ZFS merely records the point in time and metadata of when the snaphot was created.
As more changes to the original filesystem are made, the size of the snapshot increases because more space is required to keep the record of the old blocks. Furthermore, if you create lots of snapshots, say one per day, and then delete the snapshots from earlier in the week, the size of the newer snapshots may also increase, as the changes that make up the newer state have to be included in the more recent snapshots, rather than being spread over the seven snapshots that make up the week.
The only issue, from a backup perspective, is that snaphots exist
within the confines of the original filesystem. To get the snapshot
out into a format that you can copy to another filesystem, tape,
etc. you use the
zfs send command to create a
stream version of the snapshot.
For example, to write out the snapshot to a file:
root-shell> zfs send opt@snap1 >/backup/opt-snap1
root-shell> zfs send opt@snap1 >/dev/rmt/0
You can also write out the incremental changes between two snapshots
root-shell> zfs send opt@snap1 opt@snap2 >/backup/opt-changes
To recover a snapshot, you use
zfs recv which
applies the snapshot information either to a new filesytem, or to an