FreeBSD 5.0 offers a new feature in conjunction with Soft Updates: File system snapshots.
Snapshots allow a user to create images of specified file systems, and treat them as a file. Snapshot files must be created in the file system that the action is performed on, and a user may create no more than 20 snapshots per file system. Active snapshots are recorded in the superblock so they are persistent across unmount and remount operations along with system reboots. When a snapshot is no longer required, it can be removed with the standard rm(1) command. Snapshots may be removed in any order, however all the used space may not be acquired because another snapshot will possibly claim some of the released blocks.
During initial creation, the schg flag (see the chflags(1) manual page) is set to ensure that even root cannot write to the snapshot. The unlink(1) command makes an exception for snapshot files since it allows them to be removed with the schg flag set, so it is not necessary to clear the schg flag before removing a snapshot file.
Snapshots are created with the mount(8) command. To place a snapshot of /var in the file /var/snapshot/snap use the following command:
# mount -u -o snapshot /var/snapshot/snap /var
Once a snapshot has been created, they have several uses:
Some administrators will use a snapshot file for backup purposes, because the snapshot can be transfered to CDs or tape.
File integrity, fsck(8) may be ran on the snapshot. Assuming that the file system was clean when it was mounted, you should always get a clean (and unchanging) result. This is essentially what the background fsck(8) process does.
Run the dump(8) utility on the snapshot. A dump will be returned that is consistent with the file system and the timestamp of the snapshot. dump(8) can also take a snapshot, create a dump image and then remove the snapshot in one command using the -L flag.
mount(8) the snapshot as a frozen image of the file system. To mount(8) the snapshot /var/snapshot/snap run:
# mdconfig -a -t vnode -f /var/snapshot/snap -u 4
# mount -r /dev/md4 /mnt
You can now walk the hierarchy of your frozen /var file system mounted at /mnt. Everything will be in the same state it was during the snapshot creation time. The only exception is that any earlier snapshots will appear as zero length files. When the use of a snapshot has delimited, it can be unmounted with:
# umount /mnt
# mdconfig -d -u 4
For more information about softupdates and file system snapshots, including technical papers, you can visit Marshall Kirk McKusick's website at http://www.mckusick.com.
This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.
For questions about FreeBSD, read the documentation before contacting <[email protected]>.
For questions about this documentation, e-mail <[email protected]>.