1 |
diff -up e-smith-backup-2.2.0/root/etc/e-smith/events/actions/workstation-backup-dar.catalog e-smith-backup-2.2.0/root/etc/e-smith/events/actions/workstation-backup-dar |
2 |
--- e-smith-backup-2.2.0/root/etc/e-smith/events/actions/workstation-backup-dar.catalog 2012-04-09 15:59:12.000000000 +0200 |
3 |
+++ e-smith-backup-2.2.0/root/etc/e-smith/events/actions/workstation-backup-dar 2012-04-09 16:00:47.000000000 +0200 |
4 |
@@ -27,6 +27,7 @@ use esmith::templates; |
5 |
use Time::localtime; |
6 |
use File::Copy; |
7 |
use File::Path; |
8 |
+use File::Find; |
9 |
use POSIX ":sys_wait_h"; |
10 |
use esmith::ConfigDB; |
11 |
|
12 |
@@ -318,6 +319,99 @@ foreach (<$tmpdir/$id/$bkname*>) |
13 |
unless move($_, $setdirname); |
14 |
} |
15 |
|
16 |
+# update dar_manager catalog |
17 |
+ |
18 |
+$report .= "Updating catalog\n"; |
19 |
+ |
20 |
+my %backupfiles = (); |
21 |
+my $mntbkdir; |
22 |
+my $mounted; |
23 |
+my $key; |
24 |
+ |
25 |
+my $setbackuplist = sub { |
26 |
+ if ( $_ =~ /\.dar/ ) |
27 |
+ { |
28 |
+ my $dir = $File::Find::dir; |
29 |
+ my $backupref; |
30 |
+ $dir =~ s/$mntbkdir\///; |
31 |
+ $_ =~ s/\..*\.dar//; |
32 |
+ $backupref = $_; |
33 |
+ $_ =~ s/.*-//; |
34 |
+ @{$backupfiles{$_}}[0] = $dir; |
35 |
+ @{$backupfiles{$_}}[1] = $backupref; |
36 |
+ } |
37 |
+}; |
38 |
+ |
39 |
+$mntbkdir = $mntdir . '/' . $id; |
40 |
+ |
41 |
+my $catalog = "$mntbkdir/dar-catalog"; |
42 |
+unless ( -e $catalog) |
43 |
+{ |
44 |
+ system("/usr/bin/dar_manager", "-Q", "-C", "$catalog") == 0 |
45 |
+ or ldie("Unable to create dar_manager catalog.\n"); |
46 |
+} |
47 |
+ |
48 |
+# find available backups for the server |
49 |
+ |
50 |
+find { wanted => \&$setbackuplist, untaint => 1 }, $mntbkdir ; |
51 |
+ |
52 |
+# find backups in current catalog |
53 |
+ |
54 |
+my $i = 0; |
55 |
+my @bknum; |
56 |
+my @setd; |
57 |
+my @bkname; |
58 |
+open(DAR_LIST, "/usr/bin/dar_manager -Q -B $catalog -l |"); |
59 |
+while (<DAR_LIST>) |
60 |
+{ |
61 |
+ next unless ($_ =~ /set/); |
62 |
+ chomp; |
63 |
+ ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); |
64 |
+ $i++; |
65 |
+} |
66 |
+close (DAR_LIST); |
67 |
+ |
68 |
+# delete from catalog old removed backups |
69 |
+ |
70 |
+my $j = $i; |
71 |
+while ($j) |
72 |
+{ |
73 |
+ unless (-e "$setd[$j-1]/$bkname[$j-1]\.1\.dar") |
74 |
+ { |
75 |
+ my $del = $bknum[$j-1]; |
76 |
+ if ($del =~ /^(.*)$/) |
77 |
+ { |
78 |
+ $del = $1; |
79 |
+ } |
80 |
+ system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-D", "$del") == 0 |
81 |
+ or ldie("Failed to delete set $del from catalog.\n"); |
82 |
+ } |
83 |
+ $j--; |
84 |
+} |
85 |
+ |
86 |
+# add to catalog new backups |
87 |
+ |
88 |
+foreach $key (sort keys %backupfiles) |
89 |
+{ |
90 |
+ my $exists = 0; |
91 |
+ my $rf; |
92 |
+ foreach $rf (@bkname) |
93 |
+ { |
94 |
+ $exists = 1 if ($rf eq $backupfiles{$key}[1]); |
95 |
+ last if $exists; |
96 |
+ } |
97 |
+ do |
98 |
+ { |
99 |
+ my $add = "$mntbkdir/$backupfiles{$key}[0]/$backupfiles{$key}[1]"; |
100 |
+ if ($add =~ /^(.*)$/) |
101 |
+ { |
102 |
+ $add = $1; |
103 |
+ } |
104 |
+ system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-A", "$add") == 0 |
105 |
+ or ldie("Failed to add set $add to catalog.\n"); |
106 |
+ } unless $exists; |
107 |
+} |
108 |
+ |
109 |
# Check free disk space |
110 |
my $df = qx(/bin/df -Ph $mntdir); |
111 |
if ($df =~ /^\S+\s+(\S+)\s+(\S+)\s+(\S+)\s+(\d*%)/mi) |
112 |
diff -up e-smith-backup-2.2.0/root/etc/e-smith/web/functions/backup.catalog e-smith-backup-2.2.0/root/etc/e-smith/web/functions/backup |
113 |
--- e-smith-backup-2.2.0/root/etc/e-smith/web/functions/backup.catalog 2012-04-09 15:59:12.000000000 +0200 |
114 |
+++ e-smith-backup-2.2.0/root/etc/e-smith/web/functions/backup 2012-04-09 16:00:54.000000000 +0200 |
115 |
@@ -2604,72 +2604,12 @@ sub workstnSelRestore() |
116 |
} |
117 |
|
118 |
my $catalog = "$mntbkdir/dar-catalog"; |
119 |
- unless ( -e $catalog) |
120 |
- { |
121 |
- system("/usr/bin/dar_manager", "-C", "$catalog") == 0 |
122 |
- or die($fm->localise('ERR_DAR_CATALOG'),"\n"); |
123 |
- } |
124 |
- |
125 |
- # find available backups for the server |
126 |
- |
127 |
- find { wanted => \&$setbackuplist, untaint => 1 }, $mntbkdir ; |
128 |
- |
129 |
- # find backups in current catalog |
130 |
- |
131 |
my $i = 0; |
132 |
+ my $j = 0; |
133 |
my @bknum; |
134 |
my @setd; |
135 |
my @bkname; |
136 |
- open(DAR_LIST, "/usr/bin/dar_manager -B $catalog -l |"); |
137 |
- while (<DAR_LIST>) |
138 |
- { |
139 |
- next unless ($_ =~ /set/); |
140 |
- chomp; |
141 |
- ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); |
142 |
- $i++; |
143 |
- } |
144 |
- close (DAR_LIST); |
145 |
|
146 |
- # delete from catalog old removed backups |
147 |
- |
148 |
- my $j = $i; |
149 |
- while ($j) |
150 |
- { |
151 |
- unless (-e "$setd[$j-1]/$bkname[$j-1]\.1\.dar") |
152 |
- { |
153 |
- my $del = $bknum[$j-1]; |
154 |
- if ($del =~ /^(.*)$/) |
155 |
- { |
156 |
- $del = $1; |
157 |
- } |
158 |
- system("/usr/bin/dar_manager", "-B", "$catalog", "-D", "$del") == 0 |
159 |
- or die($fm->localise('ERR_DAR_CATALOG'),"\n"); |
160 |
- } |
161 |
- $j--; |
162 |
- } |
163 |
- |
164 |
- # add to catalog new backups |
165 |
- |
166 |
- foreach $key (sort keys %backupfiles) |
167 |
- { |
168 |
- my $exists = 0; |
169 |
- my $rf; |
170 |
- foreach $rf (@bkname) |
171 |
- { |
172 |
- $exists = 1 if ($rf eq $backupfiles{$key}[1]); |
173 |
- last if $exists; |
174 |
- } |
175 |
- do |
176 |
- { |
177 |
- my $add = "$mntbkdir/$backupfiles{$key}[0]/$backupfiles{$key}[1]"; |
178 |
- if ($add =~ /^(.*)$/) |
179 |
- { |
180 |
- $add = $1; |
181 |
- } |
182 |
- system("/usr/bin/dar_manager", "-B", "$catalog", "-A", "$add") == 0 |
183 |
- or die($fm->localise('ERR_DAR_CATALOG'),"\n"); |
184 |
- } unless $exists; |
185 |
- } |
186 |
|
187 |
# update backups list from current catalog |
188 |
|