The FreeBSD 5 UFS2 filesystem provides the possibility to create snapshots of live filesystems. It is already best known (and can be easily used) for allowing fsck(8) to run in the background (see rc.conf variable background_fsck) and to create consistent filesystem dumps (see dump(8) option -L).
Additionally, with the help of md(4) and mdconfig(8) you can mount snapshots as read-only filesystems, too. For illustration purposes, look at this sample session where a snapshot of /var is created:
# echo "before" >/var/tmp/foo.txt # ls -l /var/tmp/foo.txt -rw-r--r-- 1 root wheel 7 Sep 3 16:19 /var/tmp/foo.txt # test -d /var/.snap || mkdir /var/.snap # mount -u -o snapshot /var/.snap/test /var # ls -l /var/.snap/test -r-------- 1 root operator 2147483784 Sep 3 16:19 /var/.snap/test # echo "after" >/var/tmp/foo.txt # ls -l /var/tmp/foo.txt -rw-r--r-- 1 root wheel 6 Sep 3 16:20 /var/tmp/foo.txt # mdconfig -a -t vnode -f /var/.snap/test -u 1 # mount -o ro /dev/md1 /mnt # ls -l /mnt/tmp/foo.txt /var/tmp/foo.txt -rw-r--r-- 1 root wheel 7 Sep 3 16:19 /mnt/tmp/foo.txt -rw-r--r-- 1 root wheel 6 Sep 3 16:20 /var/tmp/foo.txt # cat /mnt/tmp/foo.txt /var/tmp/foo.txt before after # umount /mnt # mdconfig -d -u 1 # rm -f /var/.snap/test
As you can see, one can easily create a filesystem snapshot and use it to recover old states of files. Unfortunately, this is all our FreeBSD base system currently provided out-of-the-box. There is neither an easy way to regularily create new and expire old snapshots nor an easy -- or even unpriviledged -- way to access the snapshot data. Additionally, although the involved steps and commands are not really complicated, they are not convenient enough for daily work.
Keep in mind that regular filesystem backup snapshots are a great solution for easily recovering old file states within a small time frame. But only if the interface for the end-user follows the KISS principle. And at least this is IMHO not the case under our FreeBSD until now.
On the other hand, at work my home directory is placed on an NFS-mounted WAFL® filesystem provided by an ONTAP® based Filer from Network Appliance. For instance, after you have configured scheduled snapshots with the ONTAP® command "snap sched 0 0 4", you can easily and at any time recover old states (as a regular user) in hourly steps for the last 4 hours:
$ echo "before" >foo.txt $ sleep 3601 $ echo "middle" >foo.txt $ sleep 3601 $ echo "after" >foo.txt $ ls -la | fgrep .snapshot $ cat .snapshot/hourly.1/foo.txt .snapshot/hourly.0/foo.txt foo.txt before middle after
# snapshot list /var Filesystem User User% Snap Snap% Snapshot # snapshot make -g4 /var:test # snapshot list /var Filesystem User User% Snap Snap% Snapshot /var 1172MB 14.8% 4MB 0.1% test.0 # snapshot make -g4 /var:test # snapshot list /var Filesystem User User% Snap Snap% Snapshot /var 1176MB 14.8% 4MB 0.1% test.0 /var 1176MB 14.8% 4MB 0.1% test.1 # snapshot make -g4 /var:test # snapshot list /var Filesystem User User% Snap Snap% Snapshot /var 1181MB 14.9% 4MB 0.1% test.0 /var 1181MB 14.9% 4MB 0.1% test.1 /var 1181MB 14.9% 4MB 0.1% test.2 # snapshot make -g4 /var:test # snapshot list /var Filesystem User User% Snap Snap% Snapshot /var 1186MB 15.0% 4MB 0.1% test.0 /var 1186MB 15.0% 4MB 0.1% test.1 /var 1186MB 15.0% 4MB 0.1% test.2 /var 1186MB 15.0% 4MB 0.1% test.3 # snapshot make -g4 /var:test # snapshot list /var Filesystem User User% Snap Snap% Snapshot /var 1186MB 15.0% 4MB 0.1% test.0 /var 1186MB 15.0% 4MB 0.1% test.1 /var 1186MB 15.0% 4MB 0.1% test.2 /var 1186MB 15.0% 4MB 0.1% test.3 # snapshot mount /var:test.2 /mnt # ls /mnt .snap crash games lost+found obj rwho account cron heimdal mail opkg spool at db lib msgs preserve tmp backups empty log named run yp # snapshot umount /mnt # snapshot make -g0 /var:test # snapshot list /var Filesystem User User% Snap Snap% Snapshot
$ grep ^snapshot_ /etc/periodic.conf
snapshot_enable="YES"
snapshot_schedule="/,/usr:0:2:0 /var:0:2:4 /home:2:7:8@8,12,16,20"
$ df | egrep '(/snap|/.am)'; ls -l /snap pid1562@en2:/snap 0 0 0 100% /snap $ cd /home/rse $ echo "before" >foo.txt $ sleep 3601 $ echo "middle" >foo.txt $ sleep 3601 $ echo "after" >foo.txt $ cat /snap/home:hourly.1/rse/foo.txt /snap/home:hourly.0/rse/foo.txt foo.txt before middle after $ df | egrep '(/snap|/.am)'; ls -l /snap pid1562@en2:/snap 0 0 0 100% /snap /dev/md1 2026030 2464 1861484 0% /.am/en2/snap/var:hourly.0 lrwxrwxrwx 1 root wheel 26 Sep 3 16:38 var:hourly.0 -> /.am/en2/snap/var:hourly.0 $ sleep 3600 $ df | egrep '(/snap|/.am)'; ls -l /snap pid1562@en2:/snap 0 0 0 100% /snapAs the surrounding df(1) and ls(1) calls show, amd(8) on demand mounts the snapshot files and after about 5 minutes of no access it automatically unmounts them again.
With those three solutions, FreeBSD UFS2 snapshots are available to our unprivileged users as a short-time backup solution allowing them to easily recover their older file states.
# tar zxf freebsd-snapshot-*.tar.gz # cd freebsd-snapshot-* # make install # /etc/rc.d/amd start(If you later want to remove it again, just run "make uninstall")