diff -ruN e-smith-backup-2.4.0.p29/root/etc/e-smith/events/actions/workstation-backup-dar e-smith-backup-2.4.0.p30/root/etc/e-smith/events/actions/workstation-backup-dar --- e-smith-backup-2.4.0.p29/root/etc/e-smith/events/actions/workstation-backup-dar 2014-03-20 22:04:42.000000000 -0700 +++ e-smith-backup-2.4.0.p30/root/etc/e-smith/events/actions/workstation-backup-dar 2014-03-21 07:25:38.000000000 -0700 @@ -441,14 +441,13 @@ { system("/usr/bin/dar_manager", "-Q", "-C", "$catalog") == 0 or ldie("Unable to create dar_manager catalog.\n"); + sleep 1; # sleep added to ensure the creation of a valid catalog } - # sleep added to ensure the creation of a valid catalog - sleep 1; - # find available backups for the server my $setbackuplist = sub {if($_ =~ /([\w|-]+)-(\d+)\..*\.dar/){$backupfiles{$2} = $File::Find::dir."/$1-$2";}}; - find { wanted => \&$setbackuplist, untaint => 1 }, $mntbkdir ; + find { wanted => \&$setbackuplist, untaint => 1 }, $mntbkdir ; + my @deletions; my $pid = open (DAR_LIST, "-|", "/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-l") or ldie ("Cannot start : $!"); my $catalogIndex; # Dar refers to each backup by an index @@ -456,9 +455,7 @@ while () { - next unless ($_ =~ /set/); - chomp; - $_ =~ /(\d+).*\s[\w|-]+-(\d+)/; + next unless ($_ =~ /(\d+).*\s[\w|-]+-(\d+)/); ($catalogIndex, $oldkey) = ($1,$2); if (defined($backupfiles{$oldkey})) # found on disk and in catalog @@ -467,21 +464,29 @@ } else { - system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-D", "$catalogIndex") == 0 - or ldie("Failed to delete set $catalogIndex from catalog.\n"); + push @deletions, $catalogIndex; # Will be deleted from the catalog } } waitpid ($pid, 0); my $err = WEXITSTATUS($?); close (DAR_LIST); - ldie ("Catalog error : $err") if $err; + ldie ("Catalog error : $err") if $err; + + # Delete backups from the catalog that were missing on disk in descending order + while (my $catIndex = pop @deletions) + { + system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-D", "$catIndex") == 0 + or ldie("Failed to delete set $catIndex from catalog. $!\n"); + sleep 1; # sleep added to ensure the creation of a valid catalog + } - # Now add backups that were missing from the catalog in chronological order + # Add backups that were missing from the catalog in chronological order foreach my $key (sort keys %backupfiles) { next unless ($key > $oldkey); # prevent adding old backups to the catalog system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-A", "$backupfiles{$key}") == 0 - or ldie("Failed to add set $backupfiles{$key} to catalog.\n"); + or ldie("Failed to add set $backupfiles{$key} to catalog. $!\n"); + sleep 1; # sleep added to ensure the creation of a valid catalog } }