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 2013-12-12 21:37:57.000000000 -0800 +++ e-smith-backup-2.4.0/root/etc/e-smith/events/actions/workstation-backup-dar 2013-12-12 22:01:28.000000000 -0800 @@ -3,17 +3,17 @@ #---------------------------------------------------------------------- # copyright (C) 2006-2007 Jean-Paul Leclere # copyright (C) 2007 Charlie Brady -# +# # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA @@ -98,18 +98,18 @@ # 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 .= "$smbhost might be asleep, attempting to wake\n"; + system("ether-wake -i $ether $smbhostmac"); + $report .= "Waiting $smbhostdelay seconds...\n"; + sleep $smbhostdelay; } # verify backup directory not already mounted if (!&checkMount ($mntdir)) { ldie("Seems backup directory is already mounted. " . - "It should not happen and maybe there is a zombie process " . - "you must kill, or another backup in progress. \n"); + "It should not happen and maybe there is a zombie process " . + "you must kill, or another backup in progress. \n"); } # create the directory mount point if it does not exist @@ -133,14 +133,13 @@ } # rotating backup indicators - -++$incnum; +$incnum++; $incnum = 0 if ($dow == $fullday && $incnum > $daysinset-7) || ($fullday == 7 && $incnum >= $daysinset); if ($incnum == 0) { $setnum %= $setsmax; - ++$setnum; + $setnum++; } # if no set directory, make it @@ -158,7 +157,6 @@ } $report .= "Destination //$smbhost/$smbshare/$id/$setname\n"; - if ( $incnum == 0 ) { $bkname = "full-" . $bkname; @@ -171,26 +169,26 @@ opendir(DIR, $setdirname) or ldie("Can't open dir $setdirname $!"); while (defined($file = readdir(DIR))) { - next if $file =~ /^\.\.?$/; - if ($file =~ /dar$/) - { - $ref = $file; - } + next if $file =~ /^\.\.?$/; + if ($file =~ /dar$/) + { + $ref = $file; + } } closedir (DIR); # if no reference do full backup if ($ref eq "") { - $incnum = 0; - $report .= "No existing reference backup, will make full backup \n"; - $bkname = "full-" . $bkname; + $incnum = 0; + $report .= "No existing reference backup, will make full backup \n"; + $bkname = "full-" . $bkname; } else { - # removing .dar extension - $ref =~ s/\..*\.dar$//; - $ref = "--ref|" . $setdirname . "/" . $ref; # | will be used to split this string in run_backup() - $bkname = "inc-" . sprintf("%03d", $incnum) . "-". $bkname; + # removing .dar extension + $ref =~ s/\..*\.dar$//; + $ref = "--ref|" . $setdirname . "/" . $ref; # | will be used to split this string in run_backup() + $bkname = "inc-" . sprintf("%03d", $incnum) . "-". $bkname; } } @@ -244,7 +242,7 @@ foreach (bsd_glob("$tmpdir/$id/$bkname*")) { ldie("Error while moving backup file $_ from temporary dir $tmpdir/$id to $setdirname : $!") - unless move($_, $setdirname); + unless move($_, $setdirname); } &removeTree ("$tmpdir/$id"); } @@ -274,8 +272,8 @@ my $catalog = "$mntbkdir/dar-catalog"; 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"); + system("/usr/bin/dar_manager", "-Q", "-C", "$catalog") == 0 + or ldie("Unable to create dar_manager catalog.\n"); } # sleep added to ensure the creation of a valid catalog @@ -285,7 +283,7 @@ find { wanted => \&$setbackuplist, untaint => 1 }, $mntbkdir ; -# find backups in current catalog +# find backups in current catalog my $i = 0; my @bknum; @@ -295,10 +293,10 @@ while () { - next unless ($_ =~ /set/); - chomp; - ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); - $i++; + next unless ($_ =~ /set/); + chomp; + ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); + $i++; } close (DAR_LIST); @@ -307,51 +305,51 @@ my $j = $i; while ($j) { - unless (-e "$setd[$j-1]/$bkname[$j-1]\.1\.dar") - { - my $del = $bknum[$j-1]; - if ($del =~ /^(.*)$/) - { - $del = $1; - } - system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-D", "$del") == 0 - or ldie("Failed to delete set $del from catalog.\n"); - } - $j--; + unless (-e "$setd[$j-1]/$bkname[$j-1]\.1\.dar") + { + my $del = $bknum[$j-1]; + if ($del =~ /^(.*)$/) + { + $del = $1; + } + system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-D", "$del") == 0 + or ldie("Failed to delete set $del from catalog.\n"); + } + $j--; } # add to catalog new backups foreach $key (sort keys %backupfiles) { - my $exists = 0; - my $rf; - foreach $rf (@bkname) - { - $exists = 1 if ($rf eq $backupfiles{$key}[1]); - last if $exists; - } - do - { - my $add = "$mntbkdir/$backupfiles{$key}[0]/$backupfiles{$key}[1]"; - if ($add =~ /^(.*)$/) - { - $add = $1; - } - system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-A", "$add") == 0 - or ldie("Failed to add set $add to catalog.\n"); - } unless $exists; + my $exists = 0; + my $rf; + foreach $rf (@bkname) + { + $exists = 1 if ($rf eq $backupfiles{$key}[1]); + last if $exists; + } + do + { + my $add = "$mntbkdir/$backupfiles{$key}[0]/$backupfiles{$key}[1]"; + if ($add =~ /^(.*)$/) + { + $add = $1; + } + system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-A", "$add") == 0 + or ldie("Failed to add set $add to catalog.\n"); + } unless $exists; } # Check free disk space my $df = qx(/bin/df -Ph \"$mntdir\"); if ($df =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\d*%)/) { - $report .= "Destination disk usage $2, $4 full, $3 available\n"; + $report .= "Destination disk usage $2, $4 full, $3 available\n"; } else { - $report .= "Destination disk space not available\n"; + $report .= "Destination disk space not available\n"; } # unmount shared folder @@ -382,10 +380,10 @@ $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); + open (MAIL, "|/var/qmail/bin/qmail-inject") + || die "Cannot start mail program: $!: message was $errmsg\n"; + print MAIL $report; + close(MAIL); } system("/bin/umount", "$mntdir") if (!&checkMount ($mntdir)); die($errmsg); @@ -394,68 +392,75 @@ sub start_dar_killer { my ($darpid, $gracetime) = @_; - my $tick = $gracetime/10; - + my $tick = $gracetime/10; + my $killer = fork; return $killer if $killer; - POSIX::setsid; - chdir '/'; - #fork && exit; - - # wait for timeout or backup termination - while ($tick > 0) { - sleep 10; - $tick--; - exit unless (kill(0, $darpid)); - } - - if (kill(0, $darpid)) { - while (kill('QUIT', $darpid) != 1) { - warn "Failed to stop $darpid dar process\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"; + POSIX::setsid; + chdir '/'; + #fork && exit; + + # wait for timeout or backup termination + while ($tick > 0) + { + sleep 10; + $tick--; + exit unless (kill(0, $darpid)); + } - exit; + if (kill(0, $darpid)) + { + while (kill('QUIT', $darpid) != 1) + { + warn "Failed to stop $darpid dar process\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"; + + exit; } sub run_backup { - my $dest = shift; + my $dest = shift; my $data = undef; my $pid = undef; my $killerpid = undef; - eval { - ($pid = open INPUT, "-|", "/usr/bin/dar", "-Q", "--create", "$dest", split(/\|/,$ref), "-B", "/etc/dar/$job.dcf") or ldie("cannot start : $!" ); + eval + { + ($pid = open INPUT, "-|", "/usr/bin/dar", "-Q", "--create", "$dest", split(/\|/,$ref), "-B", "/etc/dar/$job.dcf") or ldie("cannot start : $!" ); - if ($pid) { - $killerpid = start_dar_killer($pid, $timeout); } - $data = do { local($/); }; - }; - $report .= $data; - - if ($killerpid && kill(0, $killerpid)) { - while (kill('TERM', $killerpid) != 1) { - warn "Failed to kill $killerpid killer process\n"; - } - - waitpid($killerpid, 0); - } - - waitpid($pid, 0); - my $code = WEXITSTATUS($?); - close(INPUT); - return $code; + if ($pid) + { + $killerpid = start_dar_killer($pid, $timeout); + } + $data = do { local($/); }; + }; + $report .= $data; + + if ($killerpid && kill(0, $killerpid)) + { + while (kill('TERM', $killerpid) != 1) + { + warn "Failed to kill $killerpid killer process\n"; + } + waitpid($killerpid, 0); + } + + waitpid($pid, 0); + my $code = WEXITSTATUS($?); + close(INPUT); + return $code; } sub checkMount { - # check if $mountdir is mounted + # check if $mountdir is mounted my $mountdir = shift; return system("/bin/mountpoint", "-q", "$mountdir"); } @@ -472,44 +477,45 @@ if ($VFSType eq 'cifs') { - return ( qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1) ); + return ( qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1) ); } elsif ($VFSType eq 'nfs') { - return ( qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1) ); + return ( qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1) ); } elsif ($VFSType eq 'usb') { - $_[2] = "/" . $share; + $_[2] = "/" . $share; my $device = ""; my $blkdev = ""; my $vollbl = ""; - 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") { - $blkdev = qx(hal-get-property --udi $1 --key block.device); - if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;} - } - 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"; - if ($vollbl eq $share) { - $device = $blkdev; - } + 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") + { + $blkdev = qx(hal-get-property --udi $1 --key block.device); + if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;} + } + 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"; + if ($vollbl eq $share) {$device = $blkdev;} } return ( qx(/bin/mount $device "/$share" 2>&1) ); } else { - return ("Mount of type $VFSType not supported.\n"); + return ("Mount of type $VFSType not supported.\n"); } } @@ -521,7 +527,7 @@ { eval {remove_tree("$tree")}; ldie("Error while deleting $tree : $@.\n") if $@; - } + } } sub createTree @@ -530,6 +536,6 @@ if (! -d "$tree") { eval {make_path("$tree")}; - ldie("Error while creating $tree : $@. Maybe insufficient rights directory.\n") if $@; + ldie("Error while creating $tree : $@. Maybe insufficient rights directory.\n") if $@; } }