# Creating snapshots

This chapter discusses snapshotting and tells how to create a snapshot.

## What is a snapshot?

A snapshot represents a frozen image of a volume. The source of a snapshot is called an "original." When a snapshot is created, it looks exactly like the original at that point in time. As changes are made to the original, the snapshot remains the same and looks exactly like the original at the time the snapshot was created.

Snapshotting allows you to keep a volume online while a backup is created. This method is much more convenient than a data backup where a volume must be taken offline to perform a consistent backup. When snapshotting, a snapshot of the volume is created and the backup is taken from the snapshot, while the original remains in active use.

## Creating snapshot objects

You can create a snapshot object from any unused storage object in EVMS (disks, segments, regions, or feature objects). The size of this consumed object is the size available to the snapshot object. The snapshot object can be smaller or larger than the original volume. If the object is smaller, the snapshot volume could fill up as data is copied from the original to the snapshot, given sufficient activity on the original. In this situation, the snapshot is deactivated and additional I/O to the snapshot fails.

Base the size of the snapshot object on the amount of activity that is likely to take place on the original during the lifetime of the snapshot. The more changes that occur on the original and the longer the snapshot is expected to remain active, the larger the snapshot object should be. Clearly, determining this calculation is not simple and requires trial and error to determine the correct snapshot object size to use for a particular situation. The goal is to create a snapshot object large enough to prevent the shapshot from being deactivated if it fills up, yet small enough to not waste disk space. If the snapshot object is the same size as the original volume, or a little larger, to account for the snapshot mapping tables, the snapshot is never deactivated.

After you've created the snapshot object and saved the changes, the snapshot will be activated (as long as the snapshot child object is already active). This is a change from snapshots in EVMS 2.3.x and earlier, where the snapshot would not be activated until the object was made into an EVMS volume. If you wish to have an inactive snapshot, please add the name of the snapshot object to the "activate.exclude" line in the EVMS configuration file (see section about selective-activation for more details). If at any point you decide to deactivate a snapshot object while the original volume is still active, the snapshot will be reset. The next time that the snapshot object is activated, it will reflect the state of the original volume at that point in time, just as if the snapshot had just been created.

In order to mount the snapshot, the snapshot object must still be made into an EVMS volume. The name of this volume can be the same as or different than the name of the snapshot object.

## Example: create a snapshot

This section shows how to create a snapshot with EVMS:

> ### Create a snapshot of a volume

> Create a new snapshot of `/dev/evms/vol` on `lvm/Sample Container/Sample Region`, and call it "snap."

### Using the EVMS GUI

To create the snapshot using the GUI, follow these steps:

1. Select Actions Create Feature Object to see a list of EVMS feature objects.

2. Select Snapshot Feature.

3. Click Next.

4. Select lvm/Sample Container/Sample Region.

5. Click Next.

6. Select /dev/evms/vol from the list in the "Volume to be Snapshotted" field.

7. Type `snap` in the "Snapshot Object Name" field.

8. Click Create.

Alternatively, you can perform some of the steps to create a snapshot with the GUI context sensitive menu:

1. From the Available Objects tab, right click lvm/Sample Container/Sample Region.

2. Click Create Feature Object...

3. Continue creating the snapshot beginning with step 2 of the GUI instructions. You can skip steps 4 and 5 of the GUI instructions.

### Using Ncurses

To create the snapshot, follow these steps:

1. Select Actions Create Feature Object to see a list of EVMS feature objects.

2. Select Snapshot Feature.

3. Activate Next.

4. Select `lvm/Sample Container/Sample Region.`

5. Activate Next.

6. Press spacebar to edit the "Volume to be Snapshotted" field.

7. Highlight `/dev/evms/vol` and press spacebar to select.

8. Activate OK.

9. Highlight "Snapshot Object Name" and press spacebar to edit.

10. Type `snap` at the "::" prompt. Press Enter.

11. Activate Create.

Alternatively, you can perform some of the steps to create a snapshot with the context sensitive menu:

1. From the Available Objects view, press Enter on `lvm/Sample Container/Sample Region`.

2. Activate the Create Feature Object menu item.

3. Continue creating the snapshot beginning with step 6 of the Ncurses instructions.

### Using the CLI

Use the `create` command to create a snapshot through the CLI. You pass the "Object" keyword to the `create` command, followed by the plug-in and its options, and finally the objects.

To determine the options for the plug-in you are going to use, issue the following command:

    query: plugins, plugin=Snapshot, list options

Now construct the `create` command, as follows:

    create: object, Snapshot={original=/dev/evms/vol, snapshot=snap},
    "lvm/Sample Container/Sample Region"

## Reinitializing a snapshot

Snapshots can be reinitialized. Reinitializing causes all of the saved data to be erased and starts the snapshot from the current point in time. A reinitialized snapshot has the same original, chunk size, and writeable flags as the original snapshot.

To reinitialize a snapshot, use the `Reset` command on the snapshot object (not the snapshot volume). This command reinitializes the snapshot without requiring you to manually deactivate and reactivate the volume. The snapshot must be active but unmounted for it to be reinitialized.

This section continues the example from the previous section, where a snapshot object and volume were created. The snapshot object is called "snap" and the volume is called "/dev/evms/snap."

### Using the EVMS GUI or Ncurses

To reinitialize a snapshot, follow these steps:

1. Select Actions Other Storage Object Tasks

2. Select the volume "snap."

3. Click or activate Next.

4. Select Reset.

5. Click or activate Next.

6. Click or activate Reset on the action panel.

7. Click or activate Reset on the warning panel.

Alternatively, you can perform these same steps with the context sensitive menus:

1. From the Feature Objects panel, right click (or press Enter on) the object snap.

2. Click or activate Reset on the popup menu.

3. Click or activate Reset on the action panel.

4. Click or activate Reset on the warning panel.

### Using the CLI

Follow these steps to reinitialize a snapshot with the CLI:

1. Issue the following command to the CLI:

       task:reset,snap

2. Press Enter to select "Reset" (the default choice) at the warning message.

## Expanding a snapshot

As mentioned in , as data is copied from the original volume to the snapshot, the space available for the snapshot might fill up, causing the snapshot to be invalidated. This situation might cause your data backup to end prematurely, as the snapshot volume begins returning I/O errors after it is invalidated.

To solve this problem, EVMS now has the ability to expand the storage space for a snapshot object while the snapshot volume is active and mounted. This feature allows you to initially create a small snapshot object and expand the object as necessary as the space begins to fill up.

In order to expand the snapshot object, the underlying object must be expandable. Continuing the example from the previous sections, the object "snap" is built on the LVM region `lvm/Sample Container/Sample Region`. When we refer to expanding the "snap" object, the region `lvm/Sample Container/Sample Region` is the object that actually gets expanded, and the object "snap" simply makes use of the new space on that region. Thus, to have expandable snapshots, you will usually want to build your snapshot objects on top of LVM regions that have extra freespace available in their LVM container. DriveLink objects and some disk segments also work in certain situations.

One notable quirk about expanding snapshots is that the snapshot object and volume do not actually appear to expand after the operation is complete. Because the snapshot volume is supposed to be a frozen image of the original volume, the snapshot volume always has the same size as the original, even if the snapshot has been expanded. However, you can verify that the snapshot object is using the additional space by displaying the details for the snapshot object and comparing the percent-full field before and after the expand operation.

### Using the EVMS GUI or Ncurses

To create the snapshot using the GUI or Ncurses, follow these steps:

1. Select Actions Expand Volume to see a list of EVMS feature objects.

2. Select the volume /dev/evms/snap.

3. Click or activate Next.

4. Select lvm/Sample Container/Sample Region. This object is the object that will actually be expanded.

5. Click or activate Next.

6. Select the options for expanding the LVM region, including the amount of extra space to add to the region.

7. Click or activate Expand.

Alternatively, you can perform the same steps using the context sensitive menus.

1. From the Volumes panel, right click (or press Enter on) /dev/evms/snap.

2. Select Expand from the popup menu.

3. Click or activate Next.

4. Select the region lvm/Sample Container/Sample Region. This is the object that will actually be expanded.

5. Click or activate Next.

6. Select the options for expanding the LVM region, including the amount of extra space to add to the region.

7. Click or activate Expand.

### Using the CLI

The CLI expands volumes by targeting the object to be expanded. The CLI automatically handles expanding the volume and other objects above the volume in the volume stock. As with a regular expand operation, the options are determined by the plug-in that owns the object being expanded.

Issue the following command to determine the expand options for the region `lvm/Sample Container/Sample Region`:

    query:region,region="lvm/Sample Container/Sample Region",lo

The option to use for expanding this region is called "add_size." Issue the following command to expand the snapshot by 100 MB:

    expand:"lvm/Sample Container/Sample Region", add_size=100MB

## Deleting a snapshot

When a snapshot is no longer needed, you can remove it by deleting the EVMS volume from the snapshot object, and then deleting the snapshot object. Because the snapshot saved the initial state of the original volume (and not the changed state), the original is always up-to-date and does not need any modifications when a snapshot is deleted.

No options are available for deleting snapshots.

## Rolling back a snapshot

Situations can arise where a user wants to restore the original volume to the saved state of the snapshot. This action is called a rollback. One such scenario is if the data on the original is lost or corrupted. Snapshot rollback acts as a quick backup and restore mechanism, and allows the user to avoid a more lengthy restore operation from tapes or other archives.

Another situation where rollback can be particularly useful is when you are testing new software. Before you install a new software package, create a writeable snapshot of the target volume. You can then install the software to the snapshot volume, instead of to the original, and then test and verify the new software on the snapshot. If the testing is successful, you can then roll back the snapshot to the original and effectively install the software on the regular system. If there is a problem during the testing, you can simply delete the snapshot without harming the original volume.

You can perform a rollback when the following conditions are met:

- Both the snapshot and the original volumes are unmounted and otherwise not in use.

- There is only a single snapshot of an original.

  If an original has multiple snapshots, all but the desired snapshot must be deleted before rollback can take place.

No options are available for rolling back snapshots.

### Using the EVMS GUI or Ncurses

Follow these steps to roll back a snapshot with the EVMS GUI or Ncurses:

1. Select Actions Other Storage Object Tasks .

2. Select the object "snap."

3. Click or activate Next.

4. Select Rollback.

5. Click or activate Next.

6. Click or activate Rollback on the action panel.

7. Click or activate Rollback on the warning panel.

Alternatively, you can perform these same steps with the context-sensitive menus:

1. From the Feature Objects panel, right click (or press Enter on) the object "snap."

2. Click or activate Rollback on the popup menu.

3. Click or activate Rollback on the action panel.

4. Click or activate Rollback on the warning panel.

### Using the CLI

Follow these steps to roll back a snapshot with the CLI:

1. Issue the following command to the CLI:

       task:rollback,snap

2. Press Enter to select "Rollback" (the default choice) at the warning message.