diff -ruN e-smith-backup-2.4.0.old/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/backup e-smith-backup-2.4.0/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/backup
--- e-smith-backup-2.4.0.old/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/backup 2014-04-19 10:05:05.000000000 -0700
+++ e-smith-backup-2.4.0/root/etc/e-smith/locale/en-us/etc/e-smith/web/functions/backup 2014-04-19 20:55:51.000000000 -0700
@@ -637,10 +637,18 @@
Invalid Password
+ ERR_ALREADY_MOUNTED
+ Backup directory is already mounted
+
+
ERR_MOUNTING_SMBSHARE
Unable to mount workstation shared folder
+ ERR_NOT_MOUNTED
+ Backup directory is not mounted
+
+
WORKSTN_NOT_SET
You must first correctly configure your workstation backup
diff -ruN e-smith-backup-2.4.0.old/root/etc/e-smith/web/functions/backup e-smith-backup-2.4.0/root/etc/e-smith/web/functions/backup
--- e-smith-backup-2.4.0.old/root/etc/e-smith/web/functions/backup 2014-04-19 10:05:05.000000000 -0700
+++ e-smith-backup-2.4.0/root/etc/e-smith/web/functions/backup 2014-04-20 15:38:39.000000000 -0700
@@ -1725,9 +1725,8 @@
}
my %backupfiles = ();
- my $mntdir = $rec->prop('MountDir') || '/mnt/smb';
+ my $mntdir = $rec->prop('Mount') || '/mnt/smb';
my $mntbkdir;
- my $mounted;
my $key;
my $id = $rec->prop('Id') || $conf->get('SystemName')->value . "." . $conf->get('DomainName')->value;
my $smbhost = $rec->prop('SmbHost');
@@ -1749,38 +1748,22 @@
};
# Mounting backup shared folder
-
- unless (-d $mntdir)
+ my $error_message = bmount($mntdir,$smbhost,$smbshare,$VFSType);
+ if ($error_message)
{
- mkdir -p $mntdir;
+ esmith::cgi::genResult($q, $error_message, $id);
+ return;
}
- my $login = $rec->prop('Login') || 'backup';
- my $password = $rec->prop('Password') || 'backup';
-
- if ( $err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType) )
- {
- esmith::cgi::genResult(
- $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err
- );
- return;
- }
- else {$mounted = 1}
-
# Test if backup subdirectory for our server
-
- $mntbkdir = $mntdir . '/' . $id;
- unless ( -d $mntbkdir)
- {
- if ($mounted) {
- system("/bin/umount", "$mntdir") == 0
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n");
- }
- esmith::cgi::genResult(
- $q, $fm->localise('ERR_NO_HOST_DIR'), $id
- );
- return;
- }
+ $mntbkdir = $mntdir . "/$id";
+ unless (-d $mntbkdir)
+ {
+ $error_message = $fm->localise('ERR_NO_HOST_DIR')."\n";
+ $error_message .= bunmount($mntdir,$VFSType);
+ esmith::cgi::genResult($q, $error_message, $id);
+ return;
+ }
# Finding existing backups
@@ -1796,10 +1779,8 @@
$backups = push @blabels, $labkey;
}
- if ($mounted) {
- system("/bin/umount", "$mntdir") == 0
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n");
- }
+ $error_message = bunmount($mntdir,$VFSType);
+ die($error_message) if $error_message;
# Stops here if no backups
@@ -1877,43 +1858,34 @@
my $backupwkrec = $conf->get('backupwk');
my $smbhost = $backupwkrec->prop('SmbHost');
my $smbshare = $backupwkrec->prop('SmbShare');
- my $login = $backupwkrec->prop('Login');
- my $password = $backupwkrec->prop('Password');
- my $mntdir = $backupwkrec->prop('MountDir') || '/mnt/smb';
- my $mounted;
+ my $mntdir = $backupwkrec->prop('Mount') || '/mnt/smb';
my $key;
+ my $error_message;
my $id = $backupwkrec->prop('Id') ||
$conf->get('SystemName')->value . "." . $conf->get('DomainName')->value;
my $err;
my $VFSType = $backupwkrec->prop('VFSType') || 'cifs';
my $verifyref = $q->param ('backupset');
-
+
# Mounting backup shared folder
-
- if ($err = dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType))
- {
- esmith::cgi::genResult(
- $q, $fm->localise('ERR_MOUNTING_SMBSHARE') . "\n" . $err
- );
- return;
+ $error_message = bmount($mntdir,$smbhost,$smbshare,$VFSType);
+ if ($error_message)
+ {
+ esmith::cgi::genResult($q, $error_message, $id);
+ return;
}
- else {$mounted = 1}
# Test if backup subdirectory for our server
-
my $mntbkdir = $mntdir . "/$id";
unless (-d $mntbkdir)
- {
- if ($mounted)
- {
- system("/bin/umount", "$mntdir") == 0
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n");
- }
- esmith::cgi::genResult($q, $fm->localise('ERR_NO_HOST_DIR'), $id);
- return;
+ {
+ $error_message = $fm->localise('ERR_NO_HOST_DIR')."\n";
+ $error_message .= bunmount($mntdir,$VFSType);
+ esmith::cgi::genResult($q, $error_message, $id);
+ return;
}
- my $fullverify = $q->param('verifyall');
+ my $fullverify = $q->param('verifyall') || '';
if ( $fullverify eq "on" )
{
@@ -2010,62 +1982,53 @@
}
esmith::cgi::genFooter ($q);
- }
- else
- {
- select(STDOUT);
- $| = 1;
-
- my $file;
- foreach $file (@restorefiles)
- {
- if ($file =~ /^(.*)$/)
- {
- $file = $1;
- }
- else
- {
- if ($mounted)
- {
- system("/bin/umount", "$mntdir") == 0
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n");
- }
- die('Unsecure data : ' . $file);
- }
- print $q->p($fm->localise('TESTED_BACKUP') . " " . $file);
- system ("/usr/bin/dar", "-Q", "--test", "$file", "--noconf");
- }
+ }
+ else
+ {
+ select(STDOUT);
+ $| = 1;
- if ($mounted)
- {
- system("/bin/umount", "$mntdir") == 0
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n");
- }
+ my $file;
+ foreach $file (@restorefiles)
+ {
+ if ($file =~ /^(.*)$/)
+ {
+ $file = $1;
+ }
+ else
+ {
+ $error_message = "Unsecure data : $file\n";
+ $error_message .= bunmount($mntdir,$VFSType);
+ die ($error_message);
+ }
+ print $q->p($fm->localise('TESTED_BACKUP') . " " . $file);
+ system ("/usr/bin/dar", "-Q", "--test", "$file", "--noconf");
+ }
- exit(0);
- }
- return;
+ $error_message = bunmount($mntdir,$VFSType);
+ die($error_message) if $error_message;
+
+ exit(0);
+ }
+ return;
}
else
{
- # verify selected backup only
- # and display files saved in the backup
-
- my $backupkey = $verifyref;
+ # verify selected backup only
+ # and display files saved in the backup
+
+ my $backupkey = $verifyref;
if ($backupkey =~ /^(.*)$/)
- {
- $backupkey = $1;
- }
- else
- {
- if ($mounted)
- {
- system("/bin/umount", "$mntdir") == 0
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n");
- }
- die('Unsecure data : ' . $backupkey);
- }
+ {
+ $backupkey = $1;
+ }
+ else
+ {
+ $error_message = "Unsecure data : $backupkey\n";
+ $error_message .= bunmount($mntdir,$VFSType);
+ die ($error_message);
+ }
if (open(RD, "-|"))
{
@@ -2092,21 +2055,19 @@
esmith::cgi::genFooter ($q);
- }
- else
- {
- select(STDOUT);
- $| = 1;
-
- system ("/usr/bin/dar", "-Q", "--list", "$backupkey", "--noconf") == 0
- or die ($fm->localise('ERR_EXTRACT')." : ".$!);
-
- if ($mounted) {
- system("/bin/umount", "$mntdir") == 0
- or die($fm->localise('ERR_WHILE_UNMOUNTING'),"\n");
- }
- exit(0);
- }
+ }
+ else
+ {
+ select(STDOUT);
+ $| = 1;
+
+ system ("/usr/bin/dar", "-Q", "--list", "$backupkey", "--noconf") == 0
+ or die ($fm->localise('ERR_EXTRACT')." : ".$!);
+
+ $error_message = bunmount($mntdir,$VFSType);
+ die($error_message) if $error_message;
+ exit(0);
+ }
}
return;
@@ -3165,7 +3126,7 @@
return $size;
}
-sub dmount()
+sub dmount
{
# mount dar unit according to dar-workstation configuration
# return nothing if mount successfull
@@ -3215,6 +3176,66 @@
}
}
+sub checkMount
+{
+ # check if $mountdir is mounted
+ my $mountdir = shift;
+ return system("/bin/mountpoint", "-q", "$mountdir");
+}
+
+sub bmount
+{
+ my ($mntdir,$host,$share,$VFSType) = @_;
+ # verify backup directory not already mounted
+
+ if (!checkMount ($mntdir))
+ {
+ return if ($VFSType eq 'mnt');
+ return ($fm->localise('ERR_ALREADY_MOUNTED'));
+ }
+ else
+ {
+ if ($VFSType eq 'mnt')
+ {
+ return ($fm->localise('ERR_NOT_MOUNTED'));
+ }
+ }
+
+ # create the directory mount point if it does not exist
+ createTree ($mntdir);
+
+ # mount the backup directory
+ my $err = dmount($host,$share,$mntdir,'','',$VFSType);
+ return ($fm->localise('ERR_MOUNTING_SMBSHARE') . "/$host/$share>\n" . $err) if $err;
+
+ # verify $mntdir is mounted
+ 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))
+ {
+ return ($fm->localise('ERR_NOT_MOUNTED'));
+ }
+ }
+ return;
+}
+
+sub bunmount
+{
+ my ($mount,$type) = @_;
+ return if ($type eq 'mnt'); # Don't unmount for type 'mnt'
+
+ if (!checkMount ($mount))
+ {
+ system('/bin/umount', '-f', $mount) == 0
+ or return ($fm->localise('ERR_WHILE_UNMOUNTING'));
+ }
+ return;
+}
+
+
__DATA__