diff -ruN e-smith-backup-2.4.0.p24/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.p24/root/etc/e-smith/events/actions/workstation-backup-dar 2014-02-05 16:43:10.000000000 -0800 +++ e-smith-backup-2.4.0/root/etc/e-smith/events/actions/workstation-backup-dar 2014-02-08 14:46:56.000000000 -0800 @@ -36,21 +36,16 @@ sub run_backup; my $job = shift || 'DailyBackup'; -my $report; - my $confdb = esmith::ConfigDB->open; my $backupwk = $confdb->get('backupwk') or die "No backupwk db entry found\n"; -my $internalinterface = $confdb->get('InternalInterface') or die "No internalinterface db entry found\n"; - my $bkname = strftime '%Y%m%d%H%M%S', localtime; my $dow = strftime '%w', localtime; +my $ref = ""; my $id = $backupwk->prop('Id') || $confdb->get('SystemName')->value . "." . $confdb->get('DomainName')->value; -my $err; -my $ref = ""; - - +my $internalinterface = $confdb->get('InternalInterface') or die "No internalinterface db entry found\n"; +my $ether = $internalinterface->prop('Name'); my $smbhost = $backupwk->prop('SmbHost'); my $smbshare = $backupwk->prop('SmbShare'); my $smbhostmac = $backupwk->prop('SmbHostMAC'); @@ -66,29 +61,21 @@ my $VFSType = $backupwk->prop('VFSType') || 'cifs'; my $fullday = $backupwk->prop('FullDay'); $fullday = 7 unless defined $fullday; my $mail = $backupwk->prop('MailNotify') || 'yes'; -my $mntdir = ($VFSType eq 'usb') ? "\/$smbshare" : $backupwk->prop('Mount') || '/mnt/smb'; my $frommail = $backupwk->prop('FromMail') || 'admin-backup'; my $tomail = $backupwk->prop('ToMail') || 'admin'; +my $mntdir = ($VFSType eq 'usb') ? "\/$smbshare" : $backupwk->prop('Mount') || '/mnt/smb'; my $deleteearly = $backupwk->prop('DeleteEarly') || 'false'; -my $ether = $internalinterface->prop('Name'); - -$report .= "From: ".$frommail."\n"; +my $report = "From: $frommail\n"; $report .= "To: $tomail\n"; -$report .= "Subject: Daily Backup Report: ".$id."\n\n"; +$report .= "Subject: Daily Backup Report: $id\n\n"; $report .= "================================== \n"; $report .= "DAILY BACKUP TO WORKSTATION REPORT \n"; $report .= "================================== \n"; -$report .= "Backup of ".$id." started at " .localtime() . "\n"; +$report .= "Backup of $id started at " .localtime() . "\n"; # ping the SMB Host to see if it is awake - -if (defined($smbhostmac) && (system("ping -c1 $smbhost > /dev/null") != 0)) { - $report .= "$smbhost might be asleep, attempting to wake\n"; - system("ether-wake -i $ether $smbhostmac"); - $report .= "Waiting $smbhostdelay seconds...\n"; - sleep $smbhostdelay; -} +$report .= &wol ($ether,$smbhost,$smbhostmac,$smbhostdelay); # verify backup directory not already mounted if (!&checkMount ($mntdir)) @@ -102,7 +89,7 @@ createTree ($mntdir); # mount the backup directory -$err = &dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType); +my $err = &dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType); ldie("Error while mounting \n" . $err) if $err; # verify $mntdir is mounted @@ -129,8 +116,8 @@ } # if no set directory, make it -my $setname = "set" . $setnum; -my $setdirname = $mntdir . "/$id/" . $setname; +my $setname = "set$setnum"; +my $setdirname = "$mntdir/$id/$setname"; &createTree ($setdirname); $report .= "Destination //$smbhost/$smbshare/$id/$setname\n"; @@ -247,13 +234,8 @@ $report .= "Backup successfully terminated at ".localtime()."\n"; -if ($mail eq 'yes') -{ - open (MAIL, "|/var/qmail/bin/qmail-inject") - || die "Cannot start mail program: $!\n"; - print MAIL $report; - close(MAIL); -} +# Send the Workstation Backup report +if ($mail eq 'yes') {&sendReport ($report);} exit (0); @@ -265,10 +247,7 @@ $report .= $errmsg; if (($mail eq 'yes') || ($mail eq 'error')) { - open (MAIL, "|/var/qmail/bin/qmail-inject") - || die "Cannot start mail program: $!: message was $errmsg\n"; - print MAIL $report; - close(MAIL); + &sendReport ($report,$errmsg); } system("/bin/umount", "$mntdir") if (!&checkMount ($mntdir)); die($errmsg); @@ -425,6 +404,30 @@ } } +sub sendReport +{ + my $text = shift; + my $error = shift || ""; + open (MAIL, "|/var/qmail/bin/qmail-inject") + || die "Cannot start mail program: $! $error\n"; + print MAIL $text; + close(MAIL); +} + +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"); + $output .= "Waiting $delay seconds...\n"; + sleep $delay; + } + return $output; +} + sub updateDarCatalog () { # update dar_manager catalog @@ -467,7 +470,7 @@ } } waitpid ($pid, 0); - $err = WEXITSTATUS($?); + my $err = WEXITSTATUS($?); close (DAR_LIST); ldie ("Catalog error : $err") if $err;