dropdown menu

LVM - SNAPSHOT FS


SNAPSHOT - FS:

Snapshot:

Snapshot is the state of a system at a particular point in time. (This term was coined as an analogy in photography.) Snapshots later can be used to copy data from one system to another or it can be backed up without affecting the original data.

In AIX we can take a snapshot of:
- Volume Group (splitvg, joinvg)
- Logical Volume (splitlvcopy)
- Filesystem (snapshot)

For a filesystem snapshot we have these possibilities:
- External Snapshot
- Internal snapshot
- Backsnap

----------------------------

Filesystem (snapshot)

I. External snapshot: (starting with AIX 5.2) they are on different logical volume and can be mounted as a separate fs (with read only)
II. Internal snapshot: (starting with AIX 6.1) no additional filesystem is needed, allocates space of the original filesystem
III. Backsnap: it uses the snapshot command and does everything automatically, holds the backup in an archived file

As I saw External snapshot is the preferred method by most administrators, as an external snapshot can be mounted separately on its own mount point. One big advantage of using JFS2 snapshot is that not the whole filesystem is copied to the snapshot image, just a  fraction of it, so we can save time and storage space with this procedure.

----------------------------

I. External snapshot:

The JFS2 snapshot command will create an image of a filesystem at a point in time, allowing the user to back up data from the snapshot rather than from the original filesystem. With snapshot, the file system is frozen, ensuring you get a full copy, and avoid 'open file', 'running process' or 'file not found' issues. (There is no need to shut down an application, but it is better to do the snapshot in a quiet time.)

You can have up to 15 external snapshots of a JFS2 file system and using the rollback utility, external snapshots can be rolled back to the point when a snapshot was taken.

The concept used in the snapped filesystem is "copy on write", which is at first only the filesystem structure is created and when any modification is done on the original fs (write or delete), the original data is copied into the snapped filesystem. This means that usually a snapshot filesystem will only need 10% of the size of the original filesystem (due to this copy-on-write feature), but it is a good practice to create it with half a size as the original fs. Monitoring the usage of a snapshot is a good practice, as if it runs out of space all snapshots become unusable. (Checking free space can be done, if we mount the snapshot and check it with df.)

(Database file systems are usually not a very good subject for creating snapshots, because all database files change constantly when the database is active, causing a lot of copying of data from the original to the snapshot file system.)

----------------------------

Create and mount an external snapshot:

1. snapshot -o snapfrom=/origfs -o size=300M   <--creates a logical volume to hold the snapshot fs
2. snapshot -q /origfs                         <--lists all available snapshots of an fs, with timestamp when snapshot was created
   Current  Location          512-blocks        Free Time
            /dev/fslv00           786432      785664 Fri Jan 30 13:55:08 2015
   *        /dev/fslv01          1048576     1047808 Fri Jan 30 13:58:19 2015   <-- * denotes the most recent snapshot

3. mount -v jfs2 -o snapshot /dev/fslv00 /snap_origfs  <--mount the given snapshot fs (mount point (/snap_origfs) should be created first)
                                                         (snapped filesystem and all files are available now, but it is read only)

if needed:
snapshot -d /dev/fslv00                         <--remove given snapshot
snapshot -o size=+1 /dev/fslv00                 <--dynamically increase size by 1 partition (check fs usage with df after mounting it)

----------------------------

Rollback and restore an external snapshot:
(When a rollback occurs, all snapshots of that file system will be removed)

1. snapshot -q /origfs                          <--check available snapshots
2. umount /origfs                               <--umount original fs (if snapped fs is mounted too, umount that one as well)
3. rollback -v /origfs /dev/fslv01              <--rollback to /origfs to content of /dev/fslv01
4. mount /origfs                                <--after mounting fs, original content will be available again

----------------------------
----------------------------

II. Internal snapshot:

Internal snapshots can be used only, if the filesystem was created with isnapshot=yes flag. (If it is on 'no', fs has to be recreated.) When you make an internal snapshot a special directory (called .snapshot) will be created in the original file system. This directory is hidden to avoid unintentional deletion of the data (ls command will not show it), but viewing and copying files from this dir is possible (cd/cp commands are possible). This directory is read-only and contains a link to the location of the snapshot image.

Internal snaphots are using the space of the original fs and monitoring fs usage is necessary, because if fs gets full all snapshots will be unavailable (snapshot -q <fs> will show invalid state of the snapshot).


Create and vew files in an internal snapshot:
1. lsfs -q /test                    <--check if isnapshot flag is on yes (if needed:crfs -v jfs2 -d testlv -m /test -a isnapshot=yes)
2. snapshot -o snapfrom=/test -n test_isnap    <--create an internal snapshot from filesystem /test as test_isnap
3. snapshot -q /test                <--list snapshots of an fs
   Current  Name         Time      
   *        test_isnap   Mon Feb  2 08:14:49 2015 <--output is different from external snapshot (it does not show location and size)

4. ls -la /test                     <--it will not show .snapshot directory (it is hidden)
5. ls -l /test/.snapshot            <--it will show the internal snapshot
   drwxr-xr-x    3 root     system          256 Feb  2 08:14 test_isnap
6. ls -l /test/.snapshot/test_isnap <--it will show all the files in the snapshot (cd/cp is possible in this dir)

if needed:
rollback -v  -n test_isnap /test    <--rollback the whole fs (fs must be umounted first and snapshot will be deleted after rollback)
snapshot -d -n test_isnap /test     <--delete an internal snapshot

----------------------------

snapshot: /dev/origlv: Not owner

This error occured when I wanted to create an internal snapshot:

snapshot -o snapfrom=/origfs -n origsnap1
snapshot: /dev/origlv: Not owner


There are 2 reasons for this error:
- fs was not created with isnapshot=yes option --> recreate fs with this option
- fs has already a snapshot of other type (i.e want to create an internal snapshot, but it already has an external one) --> check and remove other snapshot

----------------------------
----------------------------


III. Backsnap:

Backsnap will do basically the same as above just it does automatically everything:
It creates a logical volume and then creates a snapshot for the given filesystem on the newly created logical volume. It then mounts the snapshot on the given mount point (-m) and backs up the files and directories in that file system to the given file (-f).

backsnap -m /backsnap_origfs -s size=600M -f /tmp/backup_origfs /origfs
    -m mountpoint used while backsnap command is running
    -s size used for creating the lv (fs)
    -f file used where snapshot backup exist

snapshot -q /origfs                    <--it will show snapshot as usual
restore -tvf /tmp/backup_origfs        <--list content of the given backup
restore -xvf...                        <--restore files from the backup

----------------------------

2 comments:

Pyable Labs said...

Hi, What is the limitation of snapshot utility on original size of the JFS2 filesystem? I have a JFS2 filesystem of 13TB which we would like to take snapshot before we make app/db related changes. Is it possible?

aix said...

Hi, it is written here https://www.ibm.com/developerworks/aix/library/au-jfs2_snapshot.html:
"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!"