diff -ruN e-smith-backup-2.4.0.p30/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.p30/root/etc/e-smith/events/actions/workstation-backup-dar 2014-03-21 07:25:38.000000000 -0700 +++ e-smith-backup-2.4.0/root/etc/e-smith/events/actions/workstation-backup-dar 2014-03-21 07:46:55.000000000 -0700 @@ -75,10 +75,10 @@ $report .= "Backup of $id started at " .localtime() . "\n"; # ping the SMB Host to see if it is awake -$report .= &wol ($ether,$smbhost,$smbhostmac,$smbhostdelay); +$report .= wol ($ether,$smbhost,$smbhostmac,$smbhostdelay); # verify backup directory not already mounted -if (!&checkMount ($mntdir)) +if (!checkMount ($mntdir)) { ldie("Seems backup directory is already mounted. " . "It should not happen and maybe there is a zombie process " . @@ -86,19 +86,19 @@ } # create the directory mount point if it does not exist -&createTree ($mntdir); +createTree ($mntdir); # mount the backup directory -my $err = &dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType); -ldie("Error while mounting \n" . $err) if $err; +my $err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType); +ldie("Error while mounting \n" . $err) if $err; # verify $mntdir is mounted -if (&checkMount ($mntdir)) -{ +if (checkMount ($mntdir)) +{ # The mount should have suceeded, but sometimes it needs more time, # so sleep and then check again. sleep 5; - if (&checkMount ($mntdir)) + if (checkMount ($mntdir)) { ldie("Seems backup directory is not really mounted. It should not happen. \ Verify availability of your backup volume. Stopping the backup now.\n"); @@ -107,7 +107,7 @@ # rotating backup indicators $incnum++; -$incnum = 0 if ($dow == $fullday && $incnum > $daysinset-7) || +$incnum = 0 if ($dow == $fullday && $incnum > $daysinset-7) || ($fullday == 7 && $incnum >= $daysinset); if ($incnum == 0) { @@ -118,7 +118,7 @@ # if no set directory, make it my $setname = "set$setnum"; my $setdirname = "$mntdir/$id/$setname"; -&createTree ($setdirname); +createTree ($setdirname); $report .= "Destination //$smbhost/$smbshare/$id/$setname\n"; @@ -190,11 +190,11 @@ my $destination = ($deleteearly ne 'true') ? "$mntdir/$id/$bkname" : "$setdirname/$bkname"; # Perform the actual backup -my $rc = run_backup($destination); - -if ($rc != 0 && $rc != 11) -{ - ldie("Error while running dar: $rc"); +my $rc = run_backup($destination); + +if ($rc != 0 && $rc != 11) +{ + ldie("Error while running dar: $rc"); } if ($deleteearly ne 'true') # Not DeleteEarly so move backup to $setdirname @@ -214,7 +214,7 @@ } # update dar_manager catalog -&updateDarCatalog ("$mntdir/$id"); +updateDarCatalog ("$mntdir/$id"); # Check free disk space my $df = qx(/bin/df -Ph \"$mntdir\"); @@ -237,11 +237,11 @@ $report .= "Backup successfully terminated at ".localtime()."\n"; # Send the Workstation Backup report -if ($mail eq 'yes') {&sendReport ($report);} +if ($mail eq 'yes') {sendReport ($report);} exit (0); -sub ldie +sub ldie { my $errmsg = shift; $report =~ s/Report:/Failed:/; @@ -249,9 +249,9 @@ $report .= $errmsg; if (($mail eq 'yes') || ($mail eq 'error')) { - &sendReport ($report,$errmsg); + sendReport ($report,$errmsg); } - system("/bin/umount", "$mntdir") if (!&checkMount ($mntdir)); + system("/bin/umount", "$mntdir") if (!checkMount ($mntdir)); die($errmsg); } @@ -268,21 +268,21 @@ #fork && exit; # wait for timeout or backup termination - while ($tick > 0) + while ($tick > 0) { sleep 10; $tick--; exit unless (kill(0, $darpid)); } - if (kill(0, $darpid)) + if (kill(0, $darpid)) { - while (kill('QUIT', $darpid) != 1) + while (kill('QUIT', $darpid) != 1) { warn "Failed to stop $darpid dar process\n"; } } - warn "Partial backup stored on backup workstation.\n", + warn "Partial backup stored on backup workstation.\n", "Session cleanly closed by timeout after $timeout seconds.\n", "Not an error, backup process will continue next night.\n"; @@ -296,11 +296,11 @@ my $pid = undef; my $killerpid = undef; - eval + eval { ($pid = open INPUT, "-|", "/usr/bin/dar", "-Q", "--create", "$dest", split(/\|/,$ref), "-B", "/etc/dar/$job.dcf") or ldie("cannot start : $!" ); - if ($pid) + if ($pid) { $killerpid = start_dar_killer($pid, $timeout); } @@ -308,9 +308,9 @@ }; $report .= $data; - if ($killerpid && kill(0, $killerpid)) + if ($killerpid && kill(0, $killerpid)) { - while (kill('TERM', $killerpid) != 1) + while (kill('TERM', $killerpid) != 1) { warn "Failed to kill $killerpid killer process\n"; } @@ -324,7 +324,7 @@ } -sub checkMount +sub checkMount { # check if $mountdir is mounted my $mountdir = shift; @@ -334,13 +334,13 @@ # dmount is copied from /etc/e-smith/web/functions/backup # it could become a common function later -sub dmount() +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) = @_; - + if ($VFSType eq 'cifs') { return ( qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1) ); @@ -355,23 +355,23 @@ my $device = ""; my $blkdev = ""; my $vollbl = ""; - foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) + foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { $udi =~ m/^(\S+)/; my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); - if ($is_mounted eq "false\n") + if ($is_mounted eq "false\n") { $blkdev = qx(hal-get-property --udi $1 --key block.device); if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;} } - if ($is_mounted eq "false\n") + if ($is_mounted eq "false\n") { $vollbl = qx(hal-get-property --udi $1 --key volume.label); $vollbl =~ m/^(\S+)/; if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} } - + chomp $vollbl; chomp $blkdev; $vollbl = "media/$vollbl"; @@ -394,6 +394,7 @@ eval {remove_tree("$tree")}; ldie("Error while deleting $tree : $@.\n") if $@; } + return; } sub createTree @@ -404,6 +405,7 @@ eval {make_path("$tree")}; ldie("Error while creating $tree : $@. Maybe insufficient rights directory.\n") if $@; } + return; } sub sendReport @@ -414,13 +416,14 @@ || die "Cannot start mail program: $! $error\n"; print MAIL $text; close(MAIL); + return; } sub wol { my ($ether,$host,$mac,$delay) = @_; my $output=""; - + if (defined($mac) && (system("ping -c1 $host > /dev/null") != 0)) { $output .= "$host might be asleep, attempting to wake\n"; system("ether-wake -i $ether $mac"); @@ -430,7 +433,7 @@ return $output; } -sub updateDarCatalog () +sub updateDarCatalog { # update dar_manager catalog my $mntbkdir = shift; @@ -438,7 +441,7 @@ 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 @@ -487,6 +490,7 @@ 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; }