diff -ruN e-smith-backup-2.4.0.old/root/etc/e-smith/events/actions/workstation-backup-dar e-smith-backup-2.4.0/root/etc/e-smith/events/actions/workstation-backup-dar --- e-smith-backup-2.4.0.old/root/etc/e-smith/events/actions/workstation-backup-dar 2014-04-19 10:05:05.000000000 -0700 +++ e-smith-backup-2.4.0/root/etc/e-smith/events/actions/workstation-backup-dar 2014-04-19 10:43:57.000000000 -0700 @@ -38,8 +38,8 @@ my $job = shift || 'DailyBackup'; my $confdb = esmith::ConfigDB->open; my $backupwk = $confdb->get('backupwk') or die "No backupwk db entry found\n"; -my $bkname = strftime '%Y%m%d%H%M%S', localtime; -my $dow = strftime '%w', localtime; +my $bkname = strftime '%Y%m%d%H%M%S', localtime; +my $dow = strftime '%w', localtime; my $ref = ""; my $id = $backupwk->prop('Id') || @@ -336,8 +336,8 @@ # it could become a common function later sub dmount { - # mount dar unit according to dar-workstation configuration - # return nothing if mount successfull + # mount dar unit according to dar-workstation configuration + # return nothing if mount successfull my ($host,$share,$mountdir,$login,$password,$VFSType) = @_; @@ -394,7 +394,7 @@ eval {remove_tree("$tree")}; ldie("Error while deleting $tree : $@.\n") if $@; } - return; + return; } sub createTree @@ -405,7 +405,7 @@ eval {make_path("$tree")}; ldie("Error while creating $tree : $@. Maybe insufficient rights directory.\n") if $@; } - return; + return; } sub sendReport @@ -416,7 +416,7 @@ || die "Cannot start mail program: $! $error\n"; print MAIL $text; close(MAIL); - return; + return; } sub wol @@ -433,64 +433,64 @@ return $output; } -sub updateDarCatalog -{ - # update dar_manager catalog - my $mntbkdir = shift; - my $catalog = "$mntbkdir/dar-catalog"; - my %backupfiles = (); # hash of backup files found on the disk. - - unless ( -e $catalog) # Create an empty catalog if none found - { - 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 - } - - # find available backups for the server - my $setbackuplist = sub {if($_ =~ /([\w|-]+)-(\d+)\..*\.dar/){$backupfiles{$2} = $File::Find::dir."/$1-$2";}}; +sub updateDarCatalog +{ + # update dar_manager catalog + my $mntbkdir = shift; + my $catalog = "$mntbkdir/dar-catalog"; + my %backupfiles = (); # hash of backup files found on the disk. + + unless ( -e $catalog) # Create an empty catalog if none found + { + 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 + } + + # 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 ; - 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 - my $oldkey=0; # The key for %backupfiles is the timestamp - - while () - { - next unless ($_ =~ /(\d+).*\s[\w|-]+-(\d+)/); - ($catalogIndex, $oldkey) = ($1,$2); - - if (defined($backupfiles{$oldkey})) # found on disk and in catalog - { - delete $backupfiles{$oldkey}; # so that it will not be added in the next step. - } - else - { - push @deletions, $catalogIndex; # Will be deleted from the catalog - } - } - waitpid ($pid, 0); - my $err = WEXITSTATUS($?); - close (DAR_LIST); + 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 + my $oldkey=0; # The key for %backupfiles is the timestamp + + while () + { + next unless ($_ =~ /(\d+).*\s[\w|-]+-(\d+)/); + ($catalogIndex, $oldkey) = ($1,$2); + + if (defined($backupfiles{$oldkey})) # found on disk and in catalog + { + delete $backupfiles{$oldkey}; # so that it will not be added in the next step. + } + else + { + push @deletions, $catalogIndex; # Will be deleted from the catalog + } + } + waitpid ($pid, 0); + my $err = WEXITSTATUS($?); + close (DAR_LIST); 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 - } - - # Add backups that were missing from the catalog in chronological order - foreach my $key (sort keys %backupfiles) - { + 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 + } + + # 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"); - sleep 1; # sleep added to ensure the creation of a valid catalog + system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-A", "$backupfiles{$key}") == 0 + or ldie("Failed to add set $backupfiles{$key} to catalog. $!\n"); + sleep 1; # sleep added to ensure the creation of a valid catalog } - return; -} + return; +}