Brett's Notes

Tuesday, April 05, 2005

FSSNAP: Snap me baby!

Well, I decided to learn to use fssnap to take a 'snapshot' backup of a mounted filesystem.

This is the command I used to execute the backup ov /export/home:

fssnap -F ufs -o bs=/solstor /export/home

I haven't tried a restore, so I can't be sure that it worked. That will be my next post!

Following is the article I found that let me to this command syntax.

NOTE: This document is not intended to be a troubleshooting document. It is simply designed to explain FSSNAP on the most basic level. This is a good document for a Solaris[TM] user who is curious as to what the new fssnap utility is and how it works. Again, it is important to note that this is not a troubleshooting doc nor is it an all encompassing doc. It is a good simple explanation of fssnap at it's most basic level.

FSSNAP - GENERAL OVERVIEW

When discussing FSSNAP, the first thing to consider is what was this utility created for. One of the biggest issues system administrators have to face is their ability to back up their systems. Backup is necessary, but many utilities require that the machine be in a single user mode in order to properly backup. This requires downtime which is not a luxury most system administrators have in today's environment. There are utilities that can back up live filesystems but they are costly. One of the more popular utilities for backups is ufsdump and ufsrestore as it is easy to work, has been around forever (so it is well known), and it's free. The problem is that ufsdump was not created to run on a active filesystem. It is most successful when run in a single user mode or better yet, on an unmounted filesystem.

The fssnap utility was designed to take a "snapshot" of the filesystem, and store it in such away that the snapshot can then be backed up using the ufsdump utility. Thus the ability to backup a live filesystem using ufsdump and have it be successful is now a possibility without having to pay for a utility that will do the same thing.

Fssnap can also be used for other purposes – the above statement is just a one example.

FSSNAP - HOW DOES IT WORK?

Fssnap works with three items: The filesystem being "snapped", a backing-store file created by the user, and the snapshot in a form of a pseudo-device. In this example we will be using fssnap to take a snapshot of /opt filesystem.

Note: in this example /data directory has to exist. It also needs to have enough free space available to contain the /opt filesystem (a worse case scenario).

So, we snap the /opt filesystem as such:

#fssnap -F ufs -o bs=/data/snapshot /opt

/dev/fssnap/0

What will happen here is that activity within the filesystem itself will be brought to a brief halt (similar to if the fslock command was used, but not as intrusive). This happens so that a snapshot of the filesystem can be taken. Once taken, the process within the filesystem will resume. It is a short and usually unnoticeable pause.

Note: One cannot take a snapshot of a filesystem that has a lock on it - xntp in particular puts a lock on root, so in this case, one would have to stop xntp before creating the snapshot. Also, the backing store file can't exist prior to creating the snapshot.

You will notice that when the command is given, it gives you a response of:

/dev/fssnap/0

Fssnap also creates a /data/snapshot file which appears approximately the size of the file system /opt.

So what are each of these two things? Lets start with the /dev/fssnap/0. This is the actual "snapshot" of the /opt filesystem. One can actually mount this device if you wanted to and it would look exactly as /opt did when the snapshot was taken. The /dev/fssnap/0 is a pseudo device and it does not take up any actual space. It is simply a device through which you have access to the snapshot of /opt. But since it is a device, it can be mounted like any other filesystem. Also, like any other unmounted device, you can also run ufsdump on it (Aha!). For visualization purposes, one could view this as a frozen in time workable picture of /opt. For obvious reasons, it is read-only.

What exactly is the backing-store file? In this example, the backing-store file is /data/snapshot. Each filesystem snapped is going to need its own unique backing-store file. This file is actually a sparse file that represents the entire size of the partition on which the filesystem snapped resides. When this file is created, it appears the same size as the filesystem, but it is completely empty (has no space allocated to it). As the original filesystem is updated or modified, so too is the backing-store file. If the filesystem is never updated or modified (since the snapshot was taken), the backing-store file will remain empty.

So, if any data is to be modified on the original /opt filesystem (such as modifying or deleting a file), before the /opt filesystem is modified the current (old) data is first placed in the backing store file, then the /opt filesystem is updated. This way the snapshot will always contain an image of the filesystem from a certain point in time (static).

For example...

We have snapped /opt

it's backing file is /data/snapshot

After we snap the filesystem, JohnUser goes into /opt and updates /opt/anyfile. Before the changes JohnUser made are written to disk, a copy of the original file is saved to the backing-store file (in this case /data/snapshot). Therefore the /opt/anyfile is stored in it's original state(i.e. the way it looked when it was snapped). This copy only has to be done once during the snapshot, even if the file is modified several times (since we only care about the original image of the file and not any subsequent updates). This change is reported to the /dev/fssnap/0 which know knows that when it needs /opt/anyfile it needs to retrieve it from the backing store file and not from the current /opt. Therefore the overall snapped image remains intact. This entire operation is transparent to users (done within the kernel).

That is what fssnap does. When a filesystem is snapped, a device representing that filesystem is created. A sparse backing store file is created which will retain the original data of the filesystem should any of it be altered after the snapshot was taken. When one accesses the /dev/fssnap/0 it looks to both the original filesystem (/opt) and the backing store file (/data/snapshot) to recreate /opt as it existed when the snapshot was taken. All of this is also transparent to the users.

Note that the backing store file cannot be created on the filesystem that is being snapped - if OS is installed as a flat filesystem with no additional filesystems available, one will not be able to use fssnap! Also, more than one snapshot of a filesystem at the same time can't be done. A "device busy" error will result.

FSSNAP - Clearing out the snap shots

Once the fssnap is taken there are only two ways to clear it.

First, a reboot. This will clear the backing-store file as well as the /dev/fsssnap created.

Second, use the fssnap -d option to delete it. Deleting the snapshot will not remove the backing-store file unless the 'unlink' option was given when the snapshot was created, e.g., 'fssnap -F ufs -o bs=/data/snapshot,unlink /opt'.

If the backing store file is not removed, this will not fully remove the snapshot from your system.

For more information, refer to the fssnap_ufs(1M) man page - it contains useful examples of using fssnap with ufsdump.



1 Comments:

Post a Comment

<< Home