Snapshots Make File Recovery a Snap

Edit: Changed the first link to a Youtube video, the second link no longer works but when you search for JFS2 snapshots you can find information on the IBM website.

Originally posted November 25, 2008 on AIXchange

Watching this technical demo by Nigel Griffiths got me thinking. I like taking snapshots and flash copies on my external SAN devices. What if I want to take a snapshot of a file system on my AIX machine that isn’t connected to a SAN?

Read more about these capabilities here.

http://publib.boulder.ibm.com/infocenter/systems/index.jsp?topic=/com.ibm.aix.baseadmn/doc/baseadmndita/jfs2_snapshots.htm

From the document:

“You can make a point-in-time image of a JFS2 file system that you can then use for backup purposes. The point-in-time image for a JFS2 file system is called a snapshot. The snapshot remains static and retains the same security permissions that the original file system (called the snappedFS) had when the snapshot was made. Also, you can create a JFS2 snapshot without unmounting the file system, or quiescing the file system. You can use a JFS2 snapshot to:

* Access the files or directories as they existed when the snapshot was taken.
* Backup to removable media.

“There are two types of JFS2 snapshots: internal and external. A JFS2 external snapshot is created in a separate logical volume from the file system. The external snapshot can be mounted separately from the file system at its own unique mount point.”

So how do I do it? I’ll duplicate what Nigel did in his video demo using my test machine that runs AIX 6.1.

First, I use the following command to create a file system in rootvg that’s 500MB in size:

crfs -v jfs2 –g rootvg -a size=500M –m /snaptest -a isnapshot=yes

Then I mount the file system:

mount /snaptest

Then run two commands:

touch hello this is a test

echo “this is a test” > test.out

Finally, I run:

ls -la
drwxr-xr-x    3 root     system          256 Oct 23 14:42 .
drwxr-xr-x   22 root     system         4096 Oct 23 14:37 ..
-rw-r–r–    1 root     system            0 Oct 23 14:38 a
-rw-r–r–    1 root     system            0 Oct 23 14:38 hello
-rw-r–r–    1 root     system            0 Oct 23 14:38 is
drwxr-xr-x    2 root     system          256 Oct 23 14:37 lost+found
-rw-r–r–    1 root     system            0 Oct 23 14:38 test
-rw-r–r–    1 root     system           15 Oct 23 14:42 test.out
-rw-r–r–    1 root     system            0 Oct 23 14:38 this

To see the available menu options, go here:

smitty > system storage management > file systems > add change show delete filesystems > enhanced journaled filesystems

The menu options are:

List Snapshots for an Enhanced Journaled File System
Create Snapshot for an Enhanced Journaled File System
Mount Snapshot for an Enhanced Journaled File System
Remove Snapshot for an Enhanced Journaled File System
Unmount Snapshot for an Enhanced Journaled File System
Change Snapshot for an Enhanced Journaled File System
Rollback an Enhanced Journaled File System to a Snapshot

In our case we want to create a snapshot. This can also be done from the command line:

snapshot -o snapfrom=/snaptest –n testsnap

Running ls –la reveals no additions in the file system, but if you cd to .snapshot, you’ll find the files you just created.

I cd into /snaptest/.snapshot/testsnap and run ls to find all of the files that were in my file system when I took the snapshot.

Creating a snapshot allows you to easily recover files should someone delete them, without having to resort to restoring from a TSM machine or some other backup mechanism.