Chapter 14. Volume Snapshots

Contents

14.1. Understanding Volume Snapshots
14.2. Creating Linux Snapshots with LVM
14.3. Monitoring a Snapshot
14.4. Deleting Linux Snapshots

A file system snapshot is a copy-on-write technology that monitors changes to an existing volume’s data blocks so that when a write is made to one of the blocks, the block’s value at the snapshot time is copied to a snapshot volume. In this way, a point-in-time copy of the data is preserved until the snapshot volume is deleted.

14.1. Understanding Volume Snapshots

A file system snapshot contains metadata about and data blocks from an original volume that have changed since the snapshot was taken. When you access data via the snapshot, you see a point-in-time copy the original volume. There is no need to restore data from backup media or to overwrite the changed data.

In a Xen host environment, the virtual machine must be using an LVM logical volume as its storage back-end, as opposed to using a virtual disk file.

Linux snapshots allow you to create a backup from a point-in-time view of the file system. The snapshot is created instantly and persists until you delete it. You can backup the file system from the snapshot while the volume itself continues to be available for users. The snapshot initially contains some metadata about the snapshot, but no actual data from the original volume. Snapshot uses copy-on-write technology to detect when data changes in an original data block. It copies the value it held when the snapshot was taken to a block in the snapshot volume, then allows the new data to be stored in the original block. As blocks change from their original value, the snapshot size grows.

When you are sizing the snapshot, consider how much data is expected to change on the original volume and how long you plan to keep the snapshot. The amount of space that you allocate for a snapshot volume can vary, depending on the size of the original volume, how long you plan to keep the snapshot, and the number of data blocks that are expected to change during the snapshot’s lifetime. The snapshot volume cannot be resized after it is created. As a guide, create a snapshot volume that is about 10% of the size of the original logical volume. If you anticipate that every block in the original volume will change at least one time before you delete the snapshot, then the snapshot volume should be at least as large as the original volume plus some additional space for metadata about the snapshot volume. Less space is required if the data changes infrequently or if the expected lifetime is sufficiently brief.

[Important]

During the snapshot’s lifetime, the snapshot must be mounted before its original volume can be mounted.

When you are done with the snapshot, it is important to remove it from the system. A snapshot eventually fills up completely as data blocks change on the original volume. When the snapshot is full, it is disabled, which prevents you from remounting the original volume.

Remove snapshots in a last created, first deleted order.

14.2. Creating Linux Snapshots with LVM

The Logical Volume Manager (LVM) can be used for creating snapshots of your file system.

  • Open a terminal console, log in as the root user, then enter

    lvcreate -s -L 1G -n snap_volume source_volume_path
    

    For example:

    lvcreate -s -L 1G -n linux01-snap /dev/lvm/linux01
    

    The snapshot is created as the /dev/lvm/linux01-snap volume.

14.3. Monitoring a Snapshot

  • Open a terminal console, log in as the root user, then enter

    lvdisplay snap_volume
    

    For example:

    lvdisplay /dev/vg01/linux01-snap
    
    --- Logical volume ---
      LV Name                /dev/lvm/linux01
      VG Name                vg01
      LV UUID                QHVJYh-PR3s-A4SG-s4Aa-MyWN-Ra7a-HL47KL
      LV Write Access        read/write
      LV snapshot status     active destination for /dev/lvm/linux01
      LV Status              available
      # open                 0
      LV Size                80.00 GB
      Current LE             1024
      COW-table size         8.00 GB
      COW-table LE           512
      Allocated to snapshot  30%
      Snapshot chunk size    8.00 KB
      Segments               1
      Allocation             inherit
      Read ahead sectors     0
      Block device           254:5
    

14.4. Deleting Linux Snapshots

  • Open a terminal console, log in as the root user, then enter

    lvremove snap_volume_path
    

    For example:

    lvremove /dev/lvm/linux01-snap