CentOS / RHEL LVM : Backing Up Volume Group Metadata

– LVM metadata contains configuration details of volume groups.
– Metadata backups and archives are automatically created on every volume group and logical volume configuration change.
– Backups are stored in /etc/lvm/backup.
– Archives are stored in /etc/lvm/archive.
– Configuration settings are stored in /etc/lvm/lvm.conf.
– You can also use lvm dumpconfig command to display configuration settings.

# lvm dumpconfig
config {
 checks=1
 abort_on_errors=0
 profile_dir="/etc/lvm/profile"
}
.....
backup {
 backup=1
 backup_dir="/etc/lvm/backup"
 archive=1
 archive_dir="/etc/lvm/archive"
 retain_min=10
 retain_days=30
}
....

If you check the backup directory, you would already find a backup of all the VGs (in my case centos VG).

# ls /etc/lvm/backup
centos

The file centos would contain all the information required to rebuild the VG. For example PVs, LVs and all the other attributes.

# cat centos
...
description = "Created *after* executing 'lvextend -L 500m centos/mythinpool'"
...
myvolg {
...
physical_volumes {
        pv0 {
...
    device = "/dev/sda2" 
...

logical_volumes {
        mythinvol {
...

Note that the description states the backup file was created “after” executing the lvcreate command.

Similarly, you would find archives in the directory /etc/lvm/archive.

# ls /etc/lvm/archive
centos_00000-1969725188.vg  centos_00001-514510045.vg ....
# cat centos_00001-514510045.vg
...
description = "Created *before* executing 'vgextend centos /dev/sdb'"
...
myvolg {
...
   physical_volumes {
        pv0 {
...
     device = "/dev/sda2" 
...

Creating metadata backup

You can manually back up the metadata by using the vgcfgbackup command. For example, the following command backs up the metadata of the centos volume group to the /etc/lvm/backup/centos file:

# vgcfgbackup centos
  Volume group "centos" successfully backed up.

You can also include the –f file_today argument to the vgcfgbackup command to backup the metadata to a different location.

# vgcfgbackup -f /var/tmp/centos_metadata.bkp centos
  Volume group "centos" successfully backed up.

You can use the diff command to compare the differences between two metadata backups taken.

Related Post