=cut
use File::Find;
+use File::Path;
use Data::Dumper;
use lib "/data/backuppc/lib";
use BackupPC::Lib;
my $host = 'restore';
+my $share = '/etc';
+
+# this option will cleanup tar dump before import of each increment
+# WARNING: this will create increments which contain only new files, not
+# state of share in that particular moment! (it's fast, though)
+my $cleanup_before_increment = 0;
# connect to BackupPC_server
# check if host exists
my $host_info = $bpc->HostInfoRead( $host );
-print Dumper($host_info, $bpc->HostInfoRead( 'localhost' ));
+#print Dumper($host_info, $bpc->HostInfoRead( 'localhost' ));
die "host '$host' is not found, please add it to config/hosts configuration file\n" unless ($host_info->{$host});
-# create restore host configuration
+# take care of temporary directory for increments
+
+my $inc_tmp_dir = $Conf{IncrementTempDir} || die "need working directory in IncrementTempDir\n";
+
+sub cleanup_inc_temp_dir {
+ rmtree($inc_tmp_dir) if (-e $inc_tmp_dir);
+ mkpath($inc_tmp_dir);
+}
-my $restore_path = "$Conf{InstallDir}/$Conf{GzipTempDir}/${host}-restore.tar.gz";
+print "# using $inc_tmp_dir for increment scratch space";
+cleanup_inc_temp_dir() if (! $cleanup_before_increment);
+
+# create restore host configuration
my $conf_restore = <<'_END_OF_CONF_';
$Conf{XferMethod} = 'tar';
+$Conf{TarShareName} = '__share__';
-$Conf{TarFullArgs} = 'echo "full backups are not supported in restore!" ; exit 1';
-$Conf{TarIncrArgs} = '';
-
-# fake ping when restoring
-$Conf{PingCmd} = '$pingPath -c 1 localhost',
+# disable ping
+$Conf{PingCmd} = '';
+# work-around for Backup aborted because of CorrectHostCheck
+$Conf{FixedIPNetBiosNameCheck} = 0;
+$Conf{NmbLookupCmd} = '';
$Conf{ClientNameAlias} = 'localhost';
-$Conf{TarClientCmd} = 'zcat __restore_path__';
+#$Conf{TarIncrArgs} = '';
+#$Conf{ClientTimeout} = 600;
+#$Conf{TarClientCmd} = '';
+#$Conf{TarFullArgs} = 'gzip -cdv __restore_path__';
+
+$Conf{TarClientCmd} = '$tarPath -c -v -f - -C __inc_tmp_dir__ --totals';
1;
_END_OF_CONF_
-$conf_restore =~ s/__restore_path__/$restore_path/gs;
+$conf_restore =~ s/__share__/$share/gs;
+$conf_restore =~ s/__inc_tmp_dir__/$inc_tmp_dir/gs;
my $config_file = "$bpc->{TopDir}/conf/${host}.pl";
sub restore_increment {
my $path = shift || die "need path!";
- print "working on $path\n";
-
- if (-e $restore_path) {
- unlink $restore_path || die "can't remove $restore_path: $!\n";
+ if ($path !~ m/\.tar\.gz$/i) {
+ print "# skipping $path, not .tar.gz increment\n";
+ return;
}
- symlink $path, $restore_path || die "can't create link $path -> $restore_path: $!\n";
+
+ print "restoring $path\n";
+
+ cleanup_inc_temp_dir() if ($cleanup_before_increment);
+
+ my $cmd = "cd $inc_tmp_dir && tar xfz $path";
+ system($cmd) == 0 or die "can't execute: $cmd -- $?\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 $full = 0;
+ my @backups = $bpc->BackupInfoRead( $host );
+
+ my $full = 1;
+ foreach my $b (@backups) {
+ $full = 0 if ($b->{type} eq 'full');
+ }
+
my $r = $bpc->ServerMesg("backup $host $host $user $full");
- print "backup --> $r";
+ print "backup ", $full ? 'full' : 'incremental', " --> $r";
die $r if ($r =~ m/^error/);
# Status_backup_in_progress
restore_increment( $File::Find::name );
}, follow => 0 }, $restore_inc);
- } elsif (-f $restore_inc && $restore_inc =~ m/\.tar\.gz$/i) {
+ } elsif (-f $restore_inc) {
restore_increment( $restore_inc );
} else {
- warn "skipped: $restore_inc, not directory or .tar.gz increment\n";
+ warn "skipped: $restore_inc, not file or directory\n";
}
}
#unlink $config_file || die "can't remove $config_file: $!";
+
+rmtree($inc_tmp_dir) if (-e $inc_tmp_dir);