Remove snpashots after dump for image based disks

tags/virt-backup-0.2.12-1
Daniel Berteaud 11 years ago
parent 9d26a80866
commit f30ec3d649
  1. 17
      virt-backup

@ -230,7 +230,7 @@ foreach our $vm (@vms){
our $time = "_".time(); our $time = "_".time();
if ($opts{action} eq 'cleanup'){ if ($opts{action} eq 'cleanup'){
print "Running cleanup routine for $vm\n\n" if ($opts{debug}); print "Running cleanup routine for $vm\n\n" if ($opts{debug});
run_cleanup(); run_cleanup(1);
} }
elsif ($opts{action} eq 'unlock'){ elsif ($opts{action} eq 'unlock'){
print "Unlocking $vm\n\n" if ($opts{debug}); print "Unlocking $vm\n\n" if ($opts{debug});
@ -467,7 +467,7 @@ sub prepare_backup{
} }
# Are offline backups allowed ? # Are offline backups allowed ?
elsif (!$opts{offline}){ elsif (!$opts{offline}){
run_cleanup(); run_cleanup(1);
die "Offline backups disabled, sorry, I cannot continue\n\n"; die "Offline backups disabled, sorry, I cannot continue\n\n";
} }
} }
@ -515,6 +515,9 @@ sub run_dump{
} }
# And remove the lock file, unless the --keep-lock flag is present # And remove the lock file, unless the --keep-lock flag is present
unlock_vm() unless ($opts{keeplock}); unlock_vm() unless ($opts{keeplock});
# Cleanup snapshot and other tempm file
# but don't remove the dumps themself
run_cleanup(0);
} }
sub run_chunkmount{ sub run_chunkmount{
@ -537,7 +540,13 @@ sub run_chunkmount{
# Remove the dumps # Remove the dumps
sub run_cleanup{ sub run_cleanup{
my $rmDumps = shift;
if ($rmDumps){
print "\nRemoving backup files\n" if ($opts{debug}); print "\nRemoving backup files\n" if ($opts{debug});
}
else{
print "\nRemoving snapshots and temporary files\n" if ($opts{debug});
}
my $cnt = 0; my $cnt = 0;
my $meta = 0; my $meta = 0;
my $snap = 0; my $snap = 0;
@ -582,7 +591,6 @@ sub run_cleanup{
close MOUNTS; close MOUNTS;
} }
$cnt = unlink <$backupdir/*>;
if (open SNAPLIST, "<$backupdir.meta/snapshots"){ if (open SNAPLIST, "<$backupdir.meta/snapshots"){
sleep(1); sleep(1);
foreach (<SNAPLIST>){ foreach (<SNAPLIST>){
@ -605,6 +613,9 @@ sub run_cleanup{
rmdir "$backupdir/"; rmdir "$backupdir/";
rmdir "$backupdir.meta"; rmdir "$backupdir.meta";
rmdir "$backupdir.mount"; rmdir "$backupdir.mount";
if ($rmDumps){
$cnt = unlink <$backupdir/*>;
}
print "$cnt file(s) removed\n$snap LVM snapshots removed\n$meta metadata files removed\n\n" if $opts{debug}; print "$cnt file(s) removed\n$snap LVM snapshots removed\n$meta metadata files removed\n\n" if $opts{debug};
} }

Loading…
Cancel
Save