Two of the useful commands provided as part of Logical Volume Manager (LVM) is vgcfgbackup and vgcfgrestore. This command allows you to back up the metadata of a volume group. This may not seem like much, but there are a few scenarios where having a backup of the volume group metadata can save some time and maybe sanity as well. A cautionary note: vgcfgbackup backs up the volume group metadata only. It does not back up the data on the logical volumes.
Running vgcfgbackup is straightforward. The option -f specifies the file to use, otherwise, the default location is in /etc/lvm/backup. It is best to back the directory /etc/lvm up to a location that is backed up to tape or to another server. If no volume group is specified, then vgcfgbackup will back up all volume groups on the system. The command string to use is vgcfgbackup -f <filename> <volume group name>. An example is as follows.
root@gudaring:/etc/lvm# vgcfgbackup -f /tmp/vg01 vg01
Volume group "vg01" successfully backed up.
root@gudaring:/etc/lvm#
The output of the file generated in /etc/lvm/backup is shown below.
vg01 {
id = "K6a5ta-LVA1-PEx0-Dvic-3gTt-ZdTV-Rq6oJZ"
seqno = 42
status = ["RESIZEABLE", "READ", "WRITE"]
flags = []
extent_size = 8192 # 4 Megabytes
max_lv = 0
max_pv = 0
physical_volumes {
pv0 {
id = "UX9v6y-kF2k-3O98-7O1j-7AKd-4dAS-9KFHyZ"
device = "/dev/sda6" # Hint only
status = ["ALLOCATABLE"]
flags = []
dev_size = 29216768 # 13.9316 Gigabytes
pe_start = 384
pe_count = 3566 # 13.9297 Gigabytes
}
}
logical_volumes {
home {
id = "q9sZOd-O1N2-xn0W-8EVY-13L2-ln7d-UhcB8f"
status = ["READ", "WRITE", "VISIBLE"]
flags = []
segment_count = 1
segment1 {
start_extent = 0
extent_count = 2560 # 10 Gigabytes
type = "striped"
stripe_count = 1 # linear
stripes = [
"pv0", 0
]
}
}
lvol0 {
id = "JPavYt-GmNX-Ve8b-v6NW-xePP-25iB-QdlOOX"
status = ["READ", "WRITE", "VISIBLE"]
flags = []
segment_count = 1
segment1 {
start_extent = 0
extent_count = 512 # 2 Gigabytes
type = "striped"
stripe_count = 1 # linear
stripes = [
"pv0", 2560
]
}
}
}
}
There are a few sections here. The volume group section in this case contains the physical volume information and the logical volume information. Further information can be noted. The extent size for the volume group is shown. In the physical_volumes section the size of the device is shown. Under the logical_volumes section, information about the logical volumes in the volume group are shown. This includes which physical volumes are used by the logical volumes.
The practical step is using vgcfgrestore to recover the metadata. The options used are similar to those used for vgcfgbackup. The -f option can be used to specify a filename. One of the nice aspects of vgcfgrestore is that it can recover up to ten iterations back. The /etc/lvm/archive directory has the last ten configuration files.
To list which point you want to restore from, you can run vgcfgrestore with the -l option and the volume group. In this case, the command string used is vgcfgrestore -l vg01. This will list the last 10 restore points. The output is similar to below (only the last couple of lines are shown, for brevity).
File: /etc/lvm/archive/vg01_00043.vg
VG name: vg01
Description: Created *before* executing 'vgscan'
Backup Time: Mon Nov 21 22:25:23 2011
File: /etc/lvm/archive/vg01_00044.vg
VG name: vg01
Description: Created *before* executing 'vgscan'
Backup Time: Mon Nov 21 22:25:23 2011
File: /etc/lvm/backup/vg01
VG name: vg01
Description: Created *after* executing 'vgscan'
Backup Time: Mon Nov 21 22:25:23 2011
The output lists the full pathname of each backup file, along with a date stamp. Once you know which file you need to roll back to it is a matter of running the command string vgcfgrestore -f <filename>. For this example, we use the last filename.
root@gudaring:/etc/lvm# vgcfgrestore -f /etc/lvm/backup/vg01 vg01
Restored volume group vg01
root@gudaring:/etc/lvm#
The output indicates successful rollback.
The commands vgcfgbackup and vgcfgrestore are useful commands to use when you need to restore volume group metadata, as you may want to do if you have a failed disk in an array group, or a similar scenario. You can also use vgcfgrestore to restore an earlier version of the metadata.