r10862@llin: dpavlin | 2006-04-28 11:07:29 +0200
[BackupPC.git] / bin / BackupPC_recover_from_increments
index cabc49c..5216efa 100755 (executable)
@@ -21,6 +21,7 @@ quick hack to create BackupPC pool out of increments
 =cut
 
 use File::Find;
+use File::Path;
 use Data::Dumper;
 
 use lib "/data/backuppc/lib";
@@ -29,6 +30,11 @@ 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
 
 die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
@@ -49,21 +55,28 @@ my $TopDir = $bpc->TopDir();
 # 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 $restore_path = "$Conf{InstallDir}/$Conf{GzipTempDir}/restore.tar.gz";
+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);
+}
+
+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} = '';
-
 # disable ping
 $Conf{PingCmd} = '';
 # work-around for Backup aborted because of CorrectHostCheck
@@ -71,14 +84,19 @@ $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";
 
@@ -92,16 +110,18 @@ sub restore_increment {
        my $path = shift || die "need path!";
 
        if ($path !~ m/\.tar\.gz$/i) {
-               print "skipping $path, not .tar.gz increment\n";
+               print "skipping $path, not .tar.gz increment\n";
                return;
        }
 
-       print "working on $path\n";
+       print "restoring $path\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";
+       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";
 
@@ -163,3 +183,5 @@ foreach my $restore_inc (@ARGV) {
 }
 
 #unlink $config_file || die "can't remove $config_file: $!";
+
+rmtree($inc_tmp_dir) if (-e $inc_tmp_dir);