Browse Source

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 2 years ago
parent
commit
02ba5c0f1a
3 changed files with 18 additions and 3 deletions
  1. +3
    -2
      README
  2. +14
    -1
      virt-backup
  3. +1
    -0
      virt-backup.spec

+ 3
- 2
README View File

@ -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)


+ 14
- 1
virt-backup View File

@ -28,6 +28,7 @@ use Sys::Virt;
use Getopt::Long;
use File::Copy;
use File::Spec;
use LockFile::Simple;
# Set umask
umask(022);
@ -230,7 +231,16 @@ if (defined $connect[1]){
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 ####################


+ 1
- 0
virt-backup.spec View File

@ -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