1 |
slords |
1.1 |
--- e-smith-backup-2.0.0/root/etc/e-smith/events/actions/workstation-backup-dar.timeout 2008-10-07 11:34:31.000000000 -0600 |
2 |
|
|
+++ e-smith-backup-2.0.0/root/etc/e-smith/events/actions/workstation-backup-dar 2008-10-20 09:32:14.000000000 -0600 |
3 |
|
|
@@ -30,6 +30,8 @@ |
4 |
|
|
use esmith::ConfigDB; |
5 |
|
|
|
6 |
|
|
sub ldie; |
7 |
|
|
+sub start_dar_killer; |
8 |
|
|
+sub run_backup; |
9 |
|
|
|
10 |
|
|
my $job = shift || 'DailyBackup'; |
11 |
|
|
my $report; |
12 |
|
|
@@ -257,32 +259,7 @@ |
13 |
|
|
|
14 |
|
|
# launching dar backup |
15 |
|
|
|
16 |
|
|
-$err = system("/usr/bin/timeout", |
17 |
|
|
- "-s", |
18 |
|
|
- "TERM", |
19 |
|
|
- "$timeout", |
20 |
|
|
- "/usr/bin/dar", |
21 |
|
|
- "-c", |
22 |
|
|
- "$tmpdir/$id/$bkname", |
23 |
|
|
- split(/\s+/,$ref), |
24 |
|
|
- "-B", |
25 |
|
|
- "/etc/dar/$job.dcf"); |
26 |
|
|
- |
27 |
|
|
-if ($err == 0) |
28 |
|
|
-{ |
29 |
|
|
- $report .= "Backup completed successfully on temporary dir \n"; |
30 |
|
|
-} |
31 |
|
|
-elsif ($err == 15) |
32 |
|
|
-{ |
33 |
|
|
- $report .= "Partial backup stored on temp dir.\n" |
34 |
|
|
- . " Session closed by timeout after $timeout seconds.\n" |
35 |
|
|
- . "Not an error, backup process will continue next night.\n"; |
36 |
|
|
-} |
37 |
|
|
-else |
38 |
|
|
-{ |
39 |
|
|
- $err = $err >> 8; |
40 |
|
|
- ldie("Dar error during backup : $err \n"); |
41 |
|
|
-} |
42 |
|
|
+run_backup(); |
43 |
|
|
|
44 |
|
|
if ($incnum == 0) |
45 |
|
|
{ |
46 |
|
|
@@ -338,3 +315,63 @@ |
47 |
|
|
system("/bin/umount", "$mntdir") if $mntdone; |
48 |
|
|
die($errmsg); |
49 |
|
|
} |
50 |
|
|
+ |
51 |
|
|
+sub start_dar_killer |
52 |
|
|
+{ |
53 |
|
|
+ my ($darpid, $gracetime) = @_; |
54 |
|
|
+ my $tick = $gracetime/10; |
55 |
|
|
+ |
56 |
|
|
+ my $killer = fork; |
57 |
|
|
+ return $killer if $killer; |
58 |
|
|
+ |
59 |
|
|
+ POSIX::setsid; |
60 |
|
|
+ chdir '/'; |
61 |
|
|
+ #fork && exit; |
62 |
|
|
+ |
63 |
|
|
+ warn "Dar killer $$ started for PID $darpid with gracetime $gracetime\n"; |
64 |
|
|
+ # wait for timeout or backup termination |
65 |
|
|
+ while ($tick > 0) { |
66 |
|
|
+ sleep 10; |
67 |
|
|
+ $tick--; |
68 |
|
|
+ exit unless (kill(0, $darpid)); |
69 |
|
|
+ } |
70 |
|
|
+ |
71 |
|
|
+ if (kill(0, $darpid)) { |
72 |
|
|
+ do { |
73 |
|
|
+ warn "Cleanly stops $darpid dar process\n"; |
74 |
|
|
+ } while (kill('QUIT', $darpid) != 1); |
75 |
|
|
+ } |
76 |
|
|
+ warn "Partial backup stored on backup workstation.\n", |
77 |
|
|
+ "Session cleanly closed by timeout after $timeout seconds.\n", |
78 |
|
|
+ "Not an error, backup process will continue next night.\n"; |
79 |
|
|
+ |
80 |
|
|
+ exit; |
81 |
|
|
+} |
82 |
|
|
+ |
83 |
|
|
+sub run_backup |
84 |
|
|
+{ |
85 |
|
|
+ my $data = undef; |
86 |
|
|
+ my $pid = undef; |
87 |
|
|
+ my $killerpid = undef; |
88 |
|
|
+ |
89 |
|
|
+ eval { |
90 |
|
|
+ ($pid = open INPUT, "-|", "/usr/bin/dar", "--create", "$tmpdir/$id/$bkname", split(/\s+/,$ref), "-B", "/etc/dar/$job.dcf") or ldie("cannot start : $!" ); |
91 |
|
|
+ warn "Running dar backup with PID $pid\n"; |
92 |
|
|
+ |
93 |
|
|
+ if ($pid) { |
94 |
|
|
+ $killerpid = start_dar_killer($pid, $timeout); } |
95 |
|
|
+ $data = do { local($/); <INPUT> }; |
96 |
|
|
+ close(INPUT); |
97 |
|
|
+ }; |
98 |
|
|
+ $report .= $data; |
99 |
|
|
+ |
100 |
|
|
+ if ($killerpid && kill(0, $killerpid)) { |
101 |
|
|
+ do { |
102 |
|
|
+ warn "Killing killer $killerpid\n"; |
103 |
|
|
+ } while (kill(9, $killerpid) != 1); |
104 |
|
|
+ |
105 |
|
|
+ waitpid($killerpid, 0); |
106 |
|
|
+ } |
107 |
|
|
+ |
108 |
|
|
+ return; |
109 |
|
|
+} |