Fix LVM device name for file backed disks, so snapshot can be created. Also only use the nouuid for xfs filesystems

tags/virt-backup-0.2.12-1
Daniel Berteaud 11 years ago
parent 5cd7b832ed
commit 89a82b0b9a
  1. 15
      virt-backup

@ -64,6 +64,8 @@ $opts{compress} = 'none';
$opts{lvcreate} = '/sbin/lvcreate -c 512'; $opts{lvcreate} = '/sbin/lvcreate -c 512';
# lvremove path # lvremove path
$opts{lvremove} = '/sbin/lvremove'; $opts{lvremove} = '/sbin/lvremove';
# lvs path
$opts{lvs} = '/sbin/lvs';
# Override path to the LVM backend # Override path to the LVM backend
# Usefull if you have a layer between the filesystem # Usefull if you have a layer between the filesystem
# and the LVM volume, like GlusterFS # and the LVM volume, like GlusterFS
@ -333,8 +335,13 @@ sub prepare_backup{
# If the disk is a file # If the disk is a file
elsif ($disk->{type} eq 'file'){ elsif ($disk->{type} eq 'file'){
# Try to find the mount point, and the backing device # Try to find the mount point, and the backing device
my @df = `df -P $source`; my @df = `df -PT $source`;
my ($dev,undef,undef,undef,undef,$mount) = split /\s+/, $df[1]; my ($dev,$type,undef,undef,undef,undef,$mount) = split /\s+/, $df[1];
# Ok, we now have the backing device which probably looks like /dev/mapper/vg-lv
# We cannot pass this arg to lvcreate to take a snapshot, wee need to detect Volume Group
# name and Logical Volume name
my (undef,$lv,$vg) = split (/\s+/, `/sbin/lvs --noheadings -o lv_name,vg_name $dev </dev/null`);
$dev = '/dev/'. $vg . '/' . $lv
# The backing device can be detected, but can also be overwritten with --lvm=/dev/data/vm # The backing device can be detected, but can also be overwritten with --lvm=/dev/data/vm
# This can be usefull for example when you use GlusterFS. Df will return something like # This can be usefull for example when you use GlusterFS. Df will return something like
# localhost:/vmstore as the device, but this GlusterFS volume might be backed by an LVM # localhost:/vmstore as the device, but this GlusterFS volume might be backed by an LVM
@ -361,7 +368,9 @@ sub prepare_backup{
my $snap = $lvm.$time; my $snap = $lvm.$time;
mkdir $mp || die "Couldn't create $mp: $!"; mkdir $mp || die "Couldn't create $mp: $!";
# -o nouuid is needed if XFS is used # -o nouuid is needed if XFS is used
system("/bin/mount -o nouuid $snap $mp"); my $option = ($type eq 'xfs') ? '-o nouuid': '';
print "Mounting $snap on $mp\n (as an $type filesystem)\n" if ($opts{debug});
system("/bin/mount $option $snap $mp");
open MOUNT, ">$backupdir.meta/mount"; open MOUNT, ">$backupdir.meta/mount";
print MOUNT $lvm; print MOUNT $lvm;
close MOUNT; close MOUNT;

Loading…
Cancel
Save