AIX:JFS2 snaphots
Overview of JFS2 snapshots
The snapshot functionality was provided to create consistent and integrated snapshots of an online or offline JFS2 filesystem. A point-in-time copy of the source file system is created. The snapshot operation executes quickly and requires very little disk space. Multiple snapshots can be taken.
The snapshot retains the same permissions as the original file system. Once the image has been created, you can use it to restore files or an entire file system to a known point in time. Or, you can mount the snapped file system and perform a backup of it to tape. This could help reduce your backup time requirements.
The snapshot remains stable while the original file system is still being modified. You can perform the snapshot operation on a live file system, as it will automatically freeze I/O operations while the image is taken. You may need to briefly quiesce an application for the (very short) duration of the snapshot process. I/O is frozen to provide a greater level of file system consistency in the image. This is no different than if you were to use a similar copy service tool such as IBM's Flashcopy on the DS8000.
A snapshot maps its contents to the contents of the source file system. If the source is not modified, the snapshot does not store any of the files in its own physical disk space and has the same content as the original file system. According to the IBM documentation, a snapshot typically needs 2-6% of file system space. Highly active file systems may require around 15% of space. This space is used if a block in the original file system changes. Changed data is then copied to the snapshot.
When a write or delete occurs in the original file system, the affected blocks are copied into the snapshot. If the source is modified, the original contents of the blocks are copied to the disk space area of the snapshot file system. When the snapshot is modified, it either retrieves the data from the original file system (if it is not modified) or it retrieves it from its own disk storage (if the original was changed).
A read of the snapshot will require a lookup to determine whether the block needed should be read from the snapshot or from the original file system. For instance, the read will occur from the snapshot only if the source block has changed since the snapshot was created. If it is unchanged then the read will take place from the original file system.
There are two types of JFS2 snapshots. The first is an external snapshot which uses a separate logical volume for the snapshot image. The second type allocates space out of the original file system, this is known as an internal snapshot. An external snapshot can be mounted separately on its own mount point. A file system can use only one type of snapshot method at a time; that is, you cannot take an external snapshot of a file system and then take an internal snapshot of the same file system while the external exists (and vice versa).
It is also important to note that you cannot use internal snapshots unless the file system was enabled to support them at the time of file system creation. So if you want to use snapshots on an existing file system and you did not enable it for internal snapshots, you will need either to recreate the file system with the snapshot option or use an external snapshot.
Using JFS2 snapshots
In the following examples, I will demonstrate the use of external and internal JFS2 snapshots.
I needed to perform an upgrade of the lpar2rrd software on one of my AIX systems. Obviously, I wanted to take a backup of the associated file system prior to me applying the update, just in case anything went wrong. I also wanted a way to test the new version of the software and then easily revert to the previous version if I had any issues.
So, before I started, I took a snapshot of the lpar2rrd file system (/lpar2rrd). Of course, I would need to use an external snapshot, as I did not create this file system with the isnapshot=yes option. To avoid any possible data consistency issues during the upgrade, I shut down the httpd daemon and stopped the lpar2rrd script from running.
The file system in this example is very small, only 256MB in size. It is a regular JFS2 file system in a regular volume group. Snapshots of terabyte file systems are also supported!
# df -m /lpar2rrd Filesystem MB blocks Free %Used Iused %Iused Mounted on /dev/lpar2rrdlv 256.00 255.52 1% 10 1% /lpar2rrd # mount | grep lpar2 /dev/lpar2rrdlv /lpar2rrd jfs2 Feb 10 17:44 rw,log=/dev/log01 # grep -p lpar2rrd /etc/filesystems /lpar2rrd: dev = /dev/lpar2rrdl vfs = jfs2 log = /dev/log01 mount = true account = false
The /lpar2rrd file system contained the lpar2rrd code and the associated RRD data files for each of my managed systems. It also contained a tar zipped file of the new distribution I was about to install:
# pwd /lpar2rrd/data # ls -ltr total 184 drwxr-xr-x 2 lpar2rrd www 256 Feb 10 17:46 SN8379A99_p595-3 drwxr-xr-x 2 lpar2rrd www 256 Feb 10 17:46 SN8379A99_p595-2 drwxr-xr-x 2 lpar2rrd www 256 Feb 10 17:46 SN8379A98_p595-1 drwxr-xr-x 2 lpar2rrd www 256 Feb 10 17:46 SN1001C99_p570-1 -rwxr-xr-x 1 lpar2rrd www 90151 Feb 10 17:56 lpar2rrd-dist-2.51.tar.z
Creating an external snapshot
I executed the snapshot command to create an external snapshot of the file system. I specified a size of 128MB for the snapshot logical volume (LV). This was half the size of the original (source) logical volume. A new LV was created (fslv08) which contained the external snapshot.
# snapshot -o snapfrom=/lpar2rrd -o size=128M Snapshot for file system /lpar2rrd created on /dev/fslv08 # lsvg -l datavg | tail -2 lpar2rrdlv jfs2 2 2 1 open/syncd /lpar2rrd fslv08 jfs2 1 1 1 open/syncd N/A
To verify the status of the newly created snapshot, I ran the snapshot command with the –q flag. This provided me with information such as the date/time of the image, the location of the image (LV name), the size of the LV and the free space in the image. The * dentifies the current snapshot.
# snapshot -q /lpar2rrd Snapshots for /lpar2rrd Current Location 512-blocks Free Time * /dev/fslv08 262144 261376 Wed Feb 10 18:03:15 CST 2010