Archiving Data with Snapshots in LVM2

Simplify the time-consuming data backup process with zero downtime using LVM2 snapshot.
Best Practices

In some cases, it is advised to ensure that enough storage space is allocated for the snapshot or (as discussed below) a backup directory that will contain all of the archived snapshot data for restoring purposes. To extend an existing volume group, a new PV needs to be labeled. To do so, identify the physical storage device, and using fdisk, sfdisk or parted, create the desired partition size. Verify the partition by reading back the partition table. Then, continue to create the PV:

$ sudo sfdisk -l /dev/sde

Disk /dev/sde: 261 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, 
        counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sde1          0+    260     261-   2096451   83  Linux
/dev/sde2          0       -       0          0           0   Empty
/dev/sde3          0       -       0          0           0   Empty
/dev/sde4          0       -       0          0           0   Empty

$ sudo pvcreate /dev/sde1
  Physical volume "/dev/sde1" successfully created

Append a newly labeled PV to an existing VG with the vgextend command:

$ sudo vgextend VolGroup /dev/sde1
  Volume group "VolGroup" successfully extended

If at some point the PV needs to be removed from a VG, use the vgreduce command followed by the names of the VG and the PV:

$ sudo vgreduce VolGroup /dev/sde1

If the VG is being extended for the purpose of creating a backups directory to archive routine snapshots, following the normal lvcreate procedure, define the name, size and VG for the desired LV. Then, format the LV with a filesystem, and for file I/O accessibility, mount it to a directory path:

$ sudo lvcreate --name backups --size 1G VolGroup
  Logical volume "backups" created
$ sudo mke2fs -j /dev/VolGroup/backups
$ sudo mkdir -p /mnt/VolGroup/backups
$ sudo mount /dev/VolGroup/backups /mnt/VolGroup/backups

When the snapshot has been created, an archive can be made with the tar command, located in the newly created backups directory:

$ sudo tar -pczf /mnt/VolGroup/backups/rootsnapshot.tar.gz 

In an event of failure or if older revisions of files need to be retrieved, the archived snapshot can be used to restore the original data contents. This is an extremely ideal backup strategy when running a high-availability production environment. No downtime is required. Although this backup does not necessarily need to be written to a file, using the tar or dd commands, the snapshot can be written directly to another physical storage device, including a tape drive:

$ sudo tar -cf /dev/st0 /mnt/VolGroup/rootsnapshot


LVM2 comes prepackaged with some of the more common Linux-based distributions. In some cases, it even is used as part of the default filesystem layout. Its snapshot feature is one of those lesser-known treasures that really can be used to one's advantage, ranging from personal to larger-scale environments. All it takes is a little time, a little knowledge and a plan on design, deployment and configuration.

Petros Koutoupis is a full-time Linux kernel, device driver and application developer for embedded and server platforms. He has been working in the data storage industry for more than six years and enjoys discussing the same technologies.


Petros Koutoupis is a full-time Linux kernel, device-driver and application developer for embedded and server platforms. He has been working in the data storage industry for more than six years and enjoys discussing the same technologies.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState