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 2014-02-02 16:18:57.000000000 -0800 |
3 |
+++ e-smith-backup-2.4.0/root/etc/e-smith/events/actions/workstation-backup-dar 2014-02-02 20:28:48.000000000 -0800 |
4 |
@@ -248,98 +248,7 @@ |
5 |
} |
6 |
|
7 |
# update dar_manager catalog |
8 |
-my %backupfiles = (); |
9 |
-my $mntbkdir; |
10 |
-my $mounted; |
11 |
-my $key; |
12 |
- |
13 |
-my $setbackuplist = sub { |
14 |
- if ( $_ =~ /\.dar/ ) |
15 |
- { |
16 |
- my $dir = $File::Find::dir; |
17 |
- my $backupref; |
18 |
- $dir =~ s/$mntbkdir\///; |
19 |
- $_ =~ s/\..*\.dar//; |
20 |
- $backupref = $_; |
21 |
- $_ =~ s/.*-//; |
22 |
- @{$backupfiles{$_}}[0] = $dir; |
23 |
- @{$backupfiles{$_}}[1] = $backupref; |
24 |
- } |
25 |
-}; |
26 |
- |
27 |
-$mntbkdir = $mntdir . '/' . $id; |
28 |
- |
29 |
-my $catalog = "$mntbkdir/dar-catalog"; |
30 |
-unless ( -e $catalog) # Create an empty catalog if none found |
31 |
-{ |
32 |
- system("/usr/bin/dar_manager", "-Q", "-C", "$catalog") == 0 |
33 |
- or ldie("Unable to create dar_manager catalog.\n"); |
34 |
-} |
35 |
- |
36 |
-# sleep added to ensure the creation of a valid catalog |
37 |
-sleep 1; |
38 |
- |
39 |
-# find available backups for the server |
40 |
- |
41 |
-find { wanted => \&$setbackuplist, untaint => 1 }, $mntbkdir ; |
42 |
- |
43 |
-# find backups in current catalog |
44 |
- |
45 |
-my $i = 0; |
46 |
-my @bknum; |
47 |
-my @setd; |
48 |
-my @bkname; |
49 |
-open(DAR_LIST, "/usr/bin/dar_manager -Q -B \"$catalog\" -l |"); |
50 |
- |
51 |
-while (<DAR_LIST>) |
52 |
-{ |
53 |
- next unless ($_ =~ /set/); |
54 |
- chomp; |
55 |
- ($bknum[$i], $setd[$i], $bkname[$i]) = split(' ', $_, 3); |
56 |
- $i++; |
57 |
-} |
58 |
-close (DAR_LIST); |
59 |
- |
60 |
-# delete from catalog old removed backups |
61 |
- |
62 |
-my $j = $i; |
63 |
-while ($j) |
64 |
-{ |
65 |
- unless (-e "$setd[$j-1]/$bkname[$j-1]\.1\.dar") |
66 |
- { |
67 |
- my $del = $bknum[$j-1]; |
68 |
- if ($del =~ /^(.*)$/) |
69 |
- { |
70 |
- $del = $1; |
71 |
- } |
72 |
- system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-D", "$del") == 0 |
73 |
- or ldie("Failed to delete set $del from catalog.\n"); |
74 |
- } |
75 |
- $j--; |
76 |
-} |
77 |
- |
78 |
-# add to catalog new backups |
79 |
- |
80 |
-foreach $key (sort keys %backupfiles) |
81 |
-{ |
82 |
- my $exists = 0; |
83 |
- my $rf; |
84 |
- foreach $rf (@bkname) |
85 |
- { |
86 |
- $exists = 1 if ($rf eq $backupfiles{$key}[1]); |
87 |
- last if $exists; |
88 |
- } |
89 |
- do |
90 |
- { |
91 |
- my $add = "$mntbkdir/$backupfiles{$key}[0]/$backupfiles{$key}[1]"; |
92 |
- if ($add =~ /^(.*)$/) |
93 |
- { |
94 |
- $add = $1; |
95 |
- } |
96 |
- system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-A", "$add") == 0 |
97 |
- or ldie("Failed to add set $add to catalog.\n"); |
98 |
- } unless $exists; |
99 |
-} |
100 |
+&updateDarCatalog ("$mntdir/$id"); |
101 |
|
102 |
# Check free disk space |
103 |
my $df = qx(/bin/df -Ph \"$mntdir\"); |
104 |
@@ -539,3 +448,59 @@ |
105 |
ldie("Error while creating $tree : $@. Maybe insufficient rights directory.\n") if $@; |
106 |
} |
107 |
} |
108 |
+ |
109 |
+sub updateDarCatalog () |
110 |
+{ |
111 |
+ # update dar_manager catalog |
112 |
+ my $mntbkdir = shift; |
113 |
+ my $catalog = "$mntbkdir/dar-catalog"; |
114 |
+ my %backupfiles = (); # hash of backup files found on the disk. |
115 |
+ |
116 |
+ unless ( -e $catalog) # Create an empty catalog if none found |
117 |
+ { |
118 |
+ system("/usr/bin/dar_manager", "-Q", "-C", "$catalog") == 0 |
119 |
+ or ldie("Unable to create dar_manager catalog.\n"); |
120 |
+ } |
121 |
+ |
122 |
+ # sleep added to ensure the creation of a valid catalog |
123 |
+ sleep 1; |
124 |
+ |
125 |
+ # find available backups for the server |
126 |
+ my $setbackuplist = sub {if($_ =~ /([\w|-]+)-(\d+)\..*\.dar/){$backupfiles{$2} = $File::Find::dir."/$1-$2";}}; |
127 |
+ find { wanted => \&$setbackuplist, untaint => 1 }, $mntbkdir ; |
128 |
+ |
129 |
+ my $pid = open (DAR_LIST, "-|", "/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-l") or ldie ("Cannot start : $!"); |
130 |
+ my $catalogIndex; # Dar refers to each backup by an index |
131 |
+ my $oldkey=0; # The key for %backupfiles is the timestamp |
132 |
+ |
133 |
+ while (<DAR_LIST>) |
134 |
+ { |
135 |
+ next unless ($_ =~ /set/); |
136 |
+ chomp; |
137 |
+ $_ =~ /(\d+).*\s[\w|-]+-(\d+)/; |
138 |
+ ($catalogIndex, $oldkey) = ($1,$2); |
139 |
+ |
140 |
+ if (defined($backupfiles{$oldkey})) # found on disk and in catalog |
141 |
+ { |
142 |
+ delete $backupfiles{$oldkey}; # so that it will not be added in the next step. |
143 |
+ } |
144 |
+ else |
145 |
+ { |
146 |
+ system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-D", "$catalogIndex") == 0 |
147 |
+ or ldie("Failed to delete set $catalogIndex from catalog.\n"); |
148 |
+ } |
149 |
+ } |
150 |
+ waitpid ($pid, 0); |
151 |
+ $err = WEXITSTATUS($?); |
152 |
+ close (DAR_LIST); |
153 |
+ ldie ("Catalog error : $err") if $err; |
154 |
+ |
155 |
+ # Now add backups that were missing from the catalog in chronological order |
156 |
+ foreach my $key (sort keys %backupfiles) |
157 |
+ { |
158 |
+ next unless ($key > $oldkey); # prevent adding old backups to the catalog |
159 |
+ system("/usr/bin/dar_manager", "-Q", "-B", "$catalog", "-A", "$backupfiles{$key}") == 0 |
160 |
+ or ldie("Failed to add set $backupfiles{$key} to catalog.\n"); |
161 |
+ } |
162 |
+} |
163 |
+ |