127 |
|
|
128 |
warn "written config:\n$conf_restore\n"; |
warn "written config:\n$conf_restore\n"; |
129 |
|
|
130 |
sub restore_increment { |
sub restore_increments { |
|
my $path = shift || die "need path!"; |
|
131 |
|
|
132 |
if ($path !~ m/\.tar\.gz$/i) { |
foreach my $path (@_) { |
133 |
print "# skipping $path, not .tar.gz increment\n"; |
next unless ($path); # skip 0 element which is undef |
|
return; |
|
|
} |
|
|
|
|
|
if ($restore_via_temp_dir) { |
|
|
|
|
|
print "restoring $path (extracting to create increment)\n"; |
|
134 |
|
|
135 |
cleanup_inc_temp_dir() if ($cleanup_before_increment); |
print "extracting $path\n"; |
136 |
|
|
137 |
my $cmd = "cd $inc_tmp_dir && tar xfz $path"; |
my $cmd = "cd $inc_tmp_dir && tar xfz $path"; |
138 |
system($cmd) == 0 or die "can't execute: $cmd -- $?\n"; |
system($cmd) == 0 or die "can't execute: $cmd -- $?\n"; |
139 |
|
|
|
} else { |
|
|
|
|
|
print "using $path to create increment\n"; |
|
|
|
|
|
if (-e $restore_path) { |
|
|
unlink $restore_path || die "can't remove $restore_path: $!\n"; |
|
|
} |
|
|
symlink $path, $restore_path || die "can't create link $path -> $restore_path: $!\n"; |
|
|
|
|
|
|
|
140 |
} |
} |
141 |
|
|
142 |
|
# print "using $path to create increment\n"; |
143 |
|
# |
144 |
|
# if (-e $restore_path) { |
145 |
|
# unlink $restore_path || die "can't remove $restore_path: $!\n"; |
146 |
|
# } |
147 |
|
# symlink $path, $restore_path || die "can't create link $path -> $restore_path: $!\n"; |
148 |
|
|
149 |
print "starting import into BackupPC pool\n"; |
print "starting import into BackupPC pool\n"; |
150 |
|
|
151 |
my $user = $host_info->{$host}->{user} || die "can't get user for host $host"; |
my $user = $host_info->{$host}->{user} || die "can't get user for host $host"; |
152 |
|
|
|
$bpc->ServerMesg("log User $user started recovery from increment $path"); |
|
|
|
|
153 |
my @backups = $bpc->BackupInfoRead( $host ); |
my @backups = $bpc->BackupInfoRead( $host ); |
154 |
|
|
155 |
my $full = 1; |
my $full = 1; |
189 |
|
|
190 |
# now, start restore |
# now, start restore |
191 |
|
|
192 |
|
my $increments; |
193 |
|
|
194 |
foreach my $restore_inc (@ARGV) { |
foreach my $restore_inc (@ARGV) { |
195 |
|
|
196 |
|
sub extract_filename { |
197 |
|
my $path = shift || die "no path?"; |
198 |
|
if ($path =~ m#^(.*)/(\w+)_(\w+)_(\d+)\.tar\.gz$#) { |
199 |
|
my ($path,$host,$share,$num) = ($1,$2,$3,$4); |
200 |
|
$increments->{$host}->{$share}->{$num}->[1] = "${path}/${host}_${share}_${num}.tar.gz"; |
201 |
|
} elsif ($path =~ m#^(.*)/(\w+)_(\w+)_(\d+)/(\d+)\.tar.gz$#) { |
202 |
|
my ($path,$host,$share,$num,$part) = ($1,$2,$3,$4,$5); |
203 |
|
$increments->{$host}->{$share}->{$num}->[$part] = "${path}/${host}_${share}_${num}/${part}.tar.gz"; |
204 |
|
} else { |
205 |
|
print "# skipped: $path\n"; |
206 |
|
} |
207 |
|
} |
208 |
|
|
209 |
if (-d $restore_inc) { |
if (-d $restore_inc) { |
210 |
|
|
211 |
find({ wanted => sub { |
find({ wanted => sub { |
212 |
restore_increment( $File::Find::name ); |
extract_filename( $File::Find::name ); |
213 |
}, follow => 0 }, $restore_inc); |
}, follow => 0 }, $restore_inc); |
214 |
|
|
215 |
} elsif (-f $restore_inc) { |
} elsif (-f $restore_inc) { |
216 |
restore_increment( $restore_inc ); |
extract_filename( $restore_inc ); |
217 |
} else { |
} else { |
218 |
warn "skipped: $restore_inc, not file or directory\n"; |
warn "skipped: $restore_inc, not file or directory\n"; |
219 |
} |
} |
220 |
|
|
221 |
} |
} |
222 |
|
|
223 |
|
print Dumper($increments); |
224 |
|
|
225 |
|
cleanup_inc_temp_dir(); |
226 |
|
|
227 |
|
foreach my $host (sort keys %{ $increments }) { |
228 |
|
foreach my $share (sort keys %{ $increments->{$host} }) { |
229 |
|
foreach my $num (sort keys %{ $increments->{$host}->{$share} }) { |
230 |
|
print "# about to restore $host $share $num\n"; |
231 |
|
my @parts = @{ $increments->{$host}->{$share}->{$num} }; |
232 |
|
my $msg = "started recovery of ${host}:${share}#${num} with " . $#parts . " parts"; |
233 |
|
|
234 |
|
print "LOG: $msg\n"; |
235 |
|
$bpc->ServerMesg("log $msg"); |
236 |
|
|
237 |
|
restore_increments( @parts ); |
238 |
|
} |
239 |
|
} |
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
#unlink $config_file || die "can't remove $config_file: $!"; |
#unlink $config_file || die "can't remove $config_file: $!"; |
244 |
|
|
245 |
rmtree($inc_tmp_dir) if (-e $inc_tmp_dir); |
rmtree($inc_tmp_dir) if (-e $inc_tmp_dir); |