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-07-09 22:05:36.000000000 -0700 +++ e-smith-backup-2.4.0/root/etc/e-smith/events/actions/workstation-backup-dar 2013-07-09 22:21:34.000000000 -0700 @@ -26,7 +26,7 @@ use esmith::templates; use Time::localtime; use File::Copy; -use File::Path; +use File::Path qw(make_path remove_tree mkpath rmtree); use File::Find; use POSIX ":sys_wait_h"; use File::Glob qw(bsd_glob); @@ -63,7 +63,6 @@ $confdb->get('SystemName')->value . "." . $confdb->get('DomainName')->value; my $err; my $ref = ""; -my $mntdone = 0; my $tim = ctime(); my $smbhost = $backupwk->prop('SmbHost'); @@ -81,7 +80,7 @@ my $VFSType = $backupwk->prop('VFSType') || 'cifs'; my $fullday = $backupwk->prop('FullDay'); $fullday = 7 unless defined $fullday; my $mail = $backupwk->prop('MailNotify') || 'yes'; -my $mntdir = $backupwk->prop('Mount') || '/mnt/smb'; +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 $ether = $internalinterface->prop('Name'); @@ -95,9 +94,6 @@ $report .= "================================== \n"; $report .= "Backup of ".$id." started at " .$tim . "\n"; $report .= "Backup of mysql databases has been done\n"; - -# mounting backup directory - $report .= "Mounting backup shared directory $smbhost/$smbshare \n"; # ping the SMB Host to see if it is awake @@ -110,99 +106,25 @@ } # verify backup directory not already mounted - -open FD, '/proc/mounts'; -if ( $VFSType ne 'usb' ) -{ - while () - { - next unless /\s\/$smbhost(.*)\/$smbshare\s/; - next unless /\s\/$mntdir\s/; - $err++ - } -} -else -{ - while () - { - next unless /\s\/$smbshare\s/; - $err++; - } -} -close FD; -if ($err) +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"); } -# mount the backup dir +# create the directory mount point if it does not exist +make_path ($mntdir) unless (-d $mntdir); -if ($VFSType eq 'cifs') -{ - $err = qx(/bin/mount -t cifs "//$smbhost/$smbshare" $mntdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1); - ldie("Error while mounting //$smbhost/$smbshare : \n" . $err) if $err; -} -elsif ($VFSType eq 'nfs') -{ - $err = qx(/bin/mount -t nfs -o nolock "$smbhost:/$smbshare" $mntdir 2>&1); - ldie("Error while mounting $smbhost:/$smbshare : \n" . $err) if $err; -} -elsif ($VFSType eq 'usb') -{ - 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); - $blkdev =~ m/^(\S+)/; - } - 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 $smbshare) { - $device = $blkdev; - } - } - - system("/bin/mkdir", "-p", "/$smbshare"); - - $err = qx(/bin/mount $device "/$smbshare" 2>&1); - if ($err) {ldie("Error while mounting $device /$smbshare : \n" . $err)}; - $mntdir = "/$smbshare"; -} -else -{ - ldie("Error while mounting $smbhost/$smbshare : $VFSType not supported.\n"); -} -$mntdone = 1; +# mount the backup directory +$err = &dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType); +ldie("Error while mounting //$smbhost/$smbshare : \n" . $err) if $err; -# verify $mntdir has an entry in /proc/mounts - -$err = 0; -open FD, '/proc/mounts'; -while () -{ - s/\\040/ /g; # /proc/mount returns spaces as \040 which causes problems in matching - next unless /\s$mntdir\s/; - $err++; -} -close FD; -if ($err == 0) -{ +# verify $mntdir is mounted +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") + Verify availability of your backup volume. Stopping the backup now.\n"); } $tmpdir = $mntdir . '/tmp_dir'; @@ -474,7 +397,7 @@ print MAIL $report; close(MAIL); } - system("/bin/umount", "$mntdir") if $mntdone; + system("/bin/umount", "$mntdir") if (!&checkMount ($mntdir)); die($errmsg); } @@ -537,3 +460,64 @@ close(INPUT); return $code; } + + +sub checkMount +{ + # check if $mountdir is mounted + my $mountdir = shift; + return system("/bin/mountpoint", "-q", "$mountdir"); +} + + +# dmount is copied from /etc/e-smith/web/functions/backup +# it could become a common function later +sub dmount() +{ + # 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) ); + } + elsif ($VFSType eq 'nfs') + { + return ( qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1) ); + } + elsif ($VFSType eq 'usb') + { + $_[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; + } + } + return ( qx(/bin/mount $device "/$share" 2>&1) ); + } + else + { + return ("Error while mounting $host/$share : $VFSType not supported.\n"); + } +}