Add an exclusive lock to be sure we correctly count the number of running backups

This also ensure only one LVM snapshot is created at a time, which is a good thing to prevent overloading the system
tags/virt-backup-0.2.19-1
Daniel Berteaud 6 years ago
parent 6adf94d537
commit 02ba5c0f1a
  1. 5
      README
  2. 13
      virt-backup
  3. 1
      virt-backup.spec

@ -47,9 +47,10 @@ Keep the lock file present after the dump
virt-backup --dump --vm=devsrv --snapsize=10G --keep-lock
Backup devsrv, and disable LVM snapshots
Backup devsrv, and disable LVM snapshots. Also fails if
there's already 2 backups running
virt-backup --dump --vm=devsrv --no-snapshot
virt-backup --dump --max-backups=2 --vm=devsrv --no-snapshot
Backup mail01, and enable debug (verbose output)

@ -28,6 +28,7 @@ use Sys::Virt;
use Getopt::Long;
use File::Copy;
use File::Spec;
use LockFile::Simple;
# Set umask
umask(022);
@ -231,6 +232,15 @@ our $libvirt = $libvirt1;
print "\n" if ($opts{debug});
# Acquire an exclusive lock so we can ensure only one copy
# of virt-backup can run at a time
my $locker = LockFile::Simple->make(
-max => 20,
-delay => 1
);
print "Trying to acquire an exclusive lock\n" if ($opts{debug});
die "Can't acquire exclusive lock" unless $locker->lock($opts{lockdir} . '/virt-backup');
foreach our $vm (@vms){
# Create a new object representing the VM
print "Checking $vm status\n\n" if ($opts{debug});
@ -280,6 +290,9 @@ foreach our $vm (@vms){
}
}
print "Releasing exclusive lock\n" if ($opts{debug});
$locker->unlock($opts{lockdir} . "/virt-backup");
exit 0;
############################################################################
############## FUNCTIONS ####################

@ -15,6 +15,7 @@ Requires: util-linux
Requires: lzop, bzip2, gzip, xz
Requires: perl(Sys::Virt) => 0.2.3
Requires: perl(XML::Simple)
Requires: perl(LockFile::Simple)
Requires: fuse-chunkfs
AutoReq: no

Loading…
Cancel
Save