1 |
wellsi |
1.1 |
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 |
2 |
|
|
--- e-smith-backup-2.4.0.old/root/etc/e-smith/events/actions/workstation-backup-dar 2013-07-09 22:05:36.000000000 -0700 |
3 |
|
|
+++ e-smith-backup-2.4.0/root/etc/e-smith/events/actions/workstation-backup-dar 2013-07-09 22:21:34.000000000 -0700 |
4 |
|
|
@@ -26,7 +26,7 @@ |
5 |
|
|
use esmith::templates; |
6 |
|
|
use Time::localtime; |
7 |
|
|
use File::Copy; |
8 |
|
|
-use File::Path; |
9 |
|
|
+use File::Path qw(make_path remove_tree mkpath rmtree); |
10 |
|
|
use File::Find; |
11 |
|
|
use POSIX ":sys_wait_h"; |
12 |
|
|
use File::Glob qw(bsd_glob); |
13 |
|
|
@@ -63,7 +63,6 @@ |
14 |
|
|
$confdb->get('SystemName')->value . "." . $confdb->get('DomainName')->value; |
15 |
|
|
my $err; |
16 |
|
|
my $ref = ""; |
17 |
|
|
-my $mntdone = 0; |
18 |
|
|
my $tim = ctime(); |
19 |
|
|
|
20 |
|
|
my $smbhost = $backupwk->prop('SmbHost'); |
21 |
|
|
@@ -81,7 +80,7 @@ |
22 |
|
|
my $VFSType = $backupwk->prop('VFSType') || 'cifs'; |
23 |
|
|
my $fullday = $backupwk->prop('FullDay'); $fullday = 7 unless defined $fullday; |
24 |
|
|
my $mail = $backupwk->prop('MailNotify') || 'yes'; |
25 |
|
|
-my $mntdir = $backupwk->prop('Mount') || '/mnt/smb'; |
26 |
|
|
+my $mntdir = ($VFSType eq 'usb') ? "\/$smbshare" : $backupwk->prop('Mount') || '/mnt/smb'; |
27 |
|
|
my $frommail = $backupwk->prop('FromMail') || 'admin-backup'; |
28 |
|
|
my $tomail = $backupwk->prop('ToMail') || 'admin'; |
29 |
|
|
my $ether = $internalinterface->prop('Name'); |
30 |
|
|
@@ -95,9 +94,6 @@ |
31 |
|
|
$report .= "================================== \n"; |
32 |
|
|
$report .= "Backup of ".$id." started at " .$tim . "\n"; |
33 |
|
|
$report .= "Backup of mysql databases has been done\n"; |
34 |
|
|
- |
35 |
|
|
-# mounting backup directory |
36 |
|
|
- |
37 |
|
|
$report .= "Mounting backup shared directory $smbhost/$smbshare \n"; |
38 |
|
|
|
39 |
|
|
# ping the SMB Host to see if it is awake |
40 |
|
|
@@ -110,99 +106,25 @@ |
41 |
|
|
} |
42 |
|
|
|
43 |
|
|
# verify backup directory not already mounted |
44 |
|
|
- |
45 |
|
|
-open FD, '/proc/mounts'; |
46 |
|
|
-if ( $VFSType ne 'usb' ) |
47 |
|
|
-{ |
48 |
|
|
- while (<FD>) |
49 |
|
|
- { |
50 |
|
|
- next unless /\s\/$smbhost(.*)\/$smbshare\s/; |
51 |
|
|
- next unless /\s\/$mntdir\s/; |
52 |
|
|
- $err++ |
53 |
|
|
- } |
54 |
|
|
-} |
55 |
|
|
-else |
56 |
|
|
-{ |
57 |
|
|
- while (<FD>) |
58 |
|
|
- { |
59 |
|
|
- next unless /\s\/$smbshare\s/; |
60 |
|
|
- $err++; |
61 |
|
|
- } |
62 |
|
|
-} |
63 |
|
|
-close FD; |
64 |
|
|
-if ($err) |
65 |
|
|
+if (!&checkMount ($mntdir)) |
66 |
|
|
{ |
67 |
|
|
ldie("Seems backup directory is already mounted. " . |
68 |
|
|
"It should not happen and maybe there is a zombie process " . |
69 |
|
|
"you must kill, or another backup in progress. \n"); |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
-# mount the backup dir |
73 |
|
|
+# create the directory mount point if it does not exist |
74 |
|
|
+make_path ($mntdir) unless (-d $mntdir); |
75 |
|
|
|
76 |
|
|
-if ($VFSType eq 'cifs') |
77 |
|
|
-{ |
78 |
|
|
- $err = qx(/bin/mount -t cifs "//$smbhost/$smbshare" $mntdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1); |
79 |
|
|
- ldie("Error while mounting //$smbhost/$smbshare : \n" . $err) if $err; |
80 |
|
|
-} |
81 |
|
|
-elsif ($VFSType eq 'nfs') |
82 |
|
|
-{ |
83 |
|
|
- $err = qx(/bin/mount -t nfs -o nolock "$smbhost:/$smbshare" $mntdir 2>&1); |
84 |
|
|
- ldie("Error while mounting $smbhost:/$smbshare : \n" . $err) if $err; |
85 |
|
|
-} |
86 |
|
|
-elsif ($VFSType eq 'usb') |
87 |
|
|
-{ |
88 |
|
|
- my $device = ""; |
89 |
|
|
- my $blkdev = ""; |
90 |
|
|
- my $vollbl = ""; |
91 |
|
|
- foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { |
92 |
|
|
- $udi =~ m/^(\S+)/; |
93 |
|
|
- my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); |
94 |
|
|
- |
95 |
|
|
- if ($is_mounted eq "false\n") { |
96 |
|
|
- $blkdev = qx(hal-get-property --udi $1 --key block.device); |
97 |
|
|
- $blkdev =~ m/^(\S+)/; |
98 |
|
|
- } |
99 |
|
|
- if ($is_mounted eq "false\n") { |
100 |
|
|
- $vollbl = qx(hal-get-property --udi $1 --key volume.label); |
101 |
|
|
- $vollbl =~ m/^(\S+)/; |
102 |
|
|
- if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} |
103 |
|
|
- } |
104 |
|
|
- |
105 |
|
|
- chomp $vollbl; |
106 |
|
|
- chomp $blkdev; |
107 |
|
|
- $vollbl = "media/$vollbl"; |
108 |
|
|
- if ($vollbl eq $smbshare) { |
109 |
|
|
- $device = $blkdev; |
110 |
|
|
- } |
111 |
|
|
- } |
112 |
|
|
- |
113 |
|
|
- system("/bin/mkdir", "-p", "/$smbshare"); |
114 |
|
|
- |
115 |
|
|
- $err = qx(/bin/mount $device "/$smbshare" 2>&1); |
116 |
|
|
- if ($err) {ldie("Error while mounting $device /$smbshare : \n" . $err)}; |
117 |
|
|
- $mntdir = "/$smbshare"; |
118 |
|
|
-} |
119 |
|
|
-else |
120 |
|
|
-{ |
121 |
|
|
- ldie("Error while mounting $smbhost/$smbshare : $VFSType not supported.\n"); |
122 |
|
|
-} |
123 |
|
|
-$mntdone = 1; |
124 |
|
|
+# mount the backup directory |
125 |
|
|
+$err = &dmount($smbhost,$smbshare,$mntdir,$login,$password,$VFSType); |
126 |
|
|
+ldie("Error while mounting //$smbhost/$smbshare : \n" . $err) if $err; |
127 |
|
|
|
128 |
|
|
-# verify $mntdir has an entry in /proc/mounts |
129 |
|
|
- |
130 |
|
|
-$err = 0; |
131 |
|
|
-open FD, '/proc/mounts'; |
132 |
|
|
-while (<FD>) |
133 |
|
|
-{ |
134 |
|
|
- s/\\040/ /g; # /proc/mount returns spaces as \040 which causes problems in matching |
135 |
|
|
- next unless /\s$mntdir\s/; |
136 |
|
|
- $err++; |
137 |
|
|
-} |
138 |
|
|
-close FD; |
139 |
|
|
-if ($err == 0) |
140 |
|
|
-{ |
141 |
|
|
+# verify $mntdir is mounted |
142 |
|
|
+if (&checkMount ($mntdir)) |
143 |
|
|
+{ |
144 |
|
|
ldie("Seems backup directory is not really mounted. It should not happen. \ |
145 |
|
|
- Verify availability of your backup volume. Stopping the backup now.\n") |
146 |
|
|
+ Verify availability of your backup volume. Stopping the backup now.\n"); |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
$tmpdir = $mntdir . '/tmp_dir'; |
150 |
|
|
@@ -474,7 +397,7 @@ |
151 |
|
|
print MAIL $report; |
152 |
|
|
close(MAIL); |
153 |
|
|
} |
154 |
|
|
- system("/bin/umount", "$mntdir") if $mntdone; |
155 |
|
|
+ system("/bin/umount", "$mntdir") if (!&checkMount ($mntdir)); |
156 |
|
|
die($errmsg); |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
@@ -537,3 +460,64 @@ |
160 |
|
|
close(INPUT); |
161 |
|
|
return $code; |
162 |
|
|
} |
163 |
|
|
+ |
164 |
|
|
+ |
165 |
|
|
+sub checkMount |
166 |
|
|
+{ |
167 |
|
|
+ # check if $mountdir is mounted |
168 |
|
|
+ my $mountdir = shift; |
169 |
|
|
+ return system("/bin/mountpoint", "-q", "$mountdir"); |
170 |
|
|
+} |
171 |
|
|
+ |
172 |
|
|
+ |
173 |
|
|
+# dmount is copied from /etc/e-smith/web/functions/backup |
174 |
|
|
+# it could become a common function later |
175 |
|
|
+sub dmount() |
176 |
|
|
+{ |
177 |
|
|
+ # mount dar unit according to dar-workstation configuration |
178 |
|
|
+ # return nothing if mount successfull |
179 |
|
|
+ |
180 |
|
|
+ my ($host,$share,$mountdir,$login,$password,$VFSType) = @_; |
181 |
|
|
+ |
182 |
|
|
+ if ($VFSType eq 'cifs') |
183 |
|
|
+ { |
184 |
|
|
+ return ( qx(/bin/mount -t cifs "//$host/$share" $mountdir -o credentials=/etc/dar/CIFScredentials,nounix 2>&1) ); |
185 |
|
|
+ } |
186 |
|
|
+ elsif ($VFSType eq 'nfs') |
187 |
|
|
+ { |
188 |
|
|
+ return ( qx(/bin/mount -t nfs -o nolock "$host:/$share" $mountdir 2>&1) ); |
189 |
|
|
+ } |
190 |
|
|
+ elsif ($VFSType eq 'usb') |
191 |
|
|
+ { |
192 |
|
|
+ $_[2] = "/" . $share; |
193 |
|
|
+ my $device = ""; |
194 |
|
|
+ my $blkdev = ""; |
195 |
|
|
+ my $vollbl = ""; |
196 |
|
|
+ foreach my $udi (qx(hal-find-by-property --key volume.fsusage --string filesystem)) { |
197 |
|
|
+ $udi =~ m/^(\S+)/; |
198 |
|
|
+ my $is_mounted = qx(hal-get-property --udi $1 --key volume.is_mounted); |
199 |
|
|
+ |
200 |
|
|
+ if ($is_mounted eq "false\n") { |
201 |
|
|
+ $blkdev = qx(hal-get-property --udi $1 --key block.device); |
202 |
|
|
+ if ($blkdev =~ m/^(\S+)/) {$blkdev = $1;} |
203 |
|
|
+ } |
204 |
|
|
+ if ($is_mounted eq "false\n") { |
205 |
|
|
+ $vollbl = qx(hal-get-property --udi $1 --key volume.label); |
206 |
|
|
+ $vollbl =~ m/^(\S+)/; |
207 |
|
|
+ if ($vollbl =~ /^\s/) {$vollbl = 'nolabel';} |
208 |
|
|
+ } |
209 |
|
|
+ |
210 |
|
|
+ chomp $vollbl; |
211 |
|
|
+ chomp $blkdev; |
212 |
|
|
+ $vollbl = "media/$vollbl"; |
213 |
|
|
+ if ($vollbl eq $share) { |
214 |
|
|
+ $device = $blkdev; |
215 |
|
|
+ } |
216 |
|
|
+ } |
217 |
|
|
+ return ( qx(/bin/mount $device "/$share" 2>&1) ); |
218 |
|
|
+ } |
219 |
|
|
+ else |
220 |
|
|
+ { |
221 |
|
|
+ return ("Error while mounting $host/$share : $VFSType not supported.\n"); |
222 |
|
|
+ } |
223 |
|
|
+} |