warn "written config:\n$conf_restore\n";
-sub restore_increment {
- my $path = shift || die "need path!";
+sub restore_increments {
- if ($path !~ m/\.tar\.gz$/i) {
- print "# skipping $path, not .tar.gz increment\n";
- return;
- }
-
- if ($restore_via_temp_dir) {
-
- print "restoring $path (extracting to create increment)\n";
+ foreach my $path (@_) {
+ next unless ($path); # skip 0 element which is undef
- cleanup_inc_temp_dir() if ($cleanup_before_increment);
+ print "extracting $path\n";
my $cmd = "cd $inc_tmp_dir && tar xfz $path";
system($cmd) == 0 or die "can't execute: $cmd -- $?\n";
- } 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";
-
-
}
+# 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";
+
print "starting import into BackupPC pool\n";
my $user = $host_info->{$host}->{user} || die "can't get user for host $host";
- $bpc->ServerMesg("log User $user started recovery from increment $path");
-
my @backups = $bpc->BackupInfoRead( $host );
my $full = 1;
# now, start restore
+my $increments;
+
foreach my $restore_inc (@ARGV) {
+ sub extract_filename {
+ my $path = shift || die "no path?";
+ if ($path =~ m#^(.*)/(\w+)_(\w+)_(\d+)\.tar\.gz$#) {
+ my ($path,$host,$share,$num) = ($1,$2,$3,$4);
+ $increments->{$host}->{$share}->{$num}->[1] = "${path}/${host}_${share}_${num}.tar.gz";
+ } elsif ($path =~ m#^(.*)/(\w+)_(\w+)_(\d+)/(\d+)\.tar.gz$#) {
+ my ($path,$host,$share,$num,$part) = ($1,$2,$3,$4,$5);
+ $increments->{$host}->{$share}->{$num}->[$part] = "${path}/${host}_${share}_${num}/${part}.tar.gz";
+ } else {
+ print "# skipped: $path\n";
+ }
+ }
+
if (-d $restore_inc) {
find({ wanted => sub {
- restore_increment( $File::Find::name );
+ extract_filename( $File::Find::name );
}, follow => 0 }, $restore_inc);
} elsif (-f $restore_inc) {
- restore_increment( $restore_inc );
+ extract_filename( $restore_inc );
} else {
warn "skipped: $restore_inc, not file or directory\n";
}
}
+print Dumper($increments);
+
+cleanup_inc_temp_dir();
+
+foreach my $host (sort keys %{ $increments }) {
+ foreach my $share (sort keys %{ $increments->{$host} }) {
+ foreach my $num (sort keys %{ $increments->{$host}->{$share} }) {
+ print "# about to restore $host $share $num\n";
+ my @parts = @{ $increments->{$host}->{$share}->{$num} };
+ my $msg = "started recovery of ${host}:${share}#${num} with " . $#parts . " parts";
+
+ print "LOG: $msg\n";
+ $bpc->ServerMesg("log $msg");
+
+ restore_increments( @parts );
+ }
+ }
+}
+
+
#unlink $config_file || die "can't remove $config_file: $!";
rmtree($inc_tmp_dir) if (-e $inc_tmp_dir);