r10865@llin: dpavlin | 2006-04-29 12:59:03 +0200
authordpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sat, 29 Apr 2006 10:59:09 +0000 (10:59 +0000)
committerdpavlin <dpavlin@8392b6e1-25fa-0310-8288-cc32f8e212ea>
Sat, 29 Apr 2006 10:59:09 +0000 (10:59 +0000)
 Again re-added $restore_via_temp_dir option because pipeing tar doesn't work well

git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@361 8392b6e1-25fa-0310-8288-cc32f8e212ea

Makefile
bin/BackupPC_recover_from_increments

index 819163c..795c00b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -83,4 +83,4 @@ cleanup-restore:
 
 restore: cleanup-restore test
        sleep 1
-       sudo -u backuppc ./bin/BackupPC_recover_from_increments /data/backuppc/temp/llin_etc*
+       sudo ./bin/BackupPC_recover_from_increments /data/backuppc/temp/llin_etc*
index 5216efa..80b3f12 100755 (executable)
@@ -35,9 +35,13 @@ my $share = '/etc';
 # state of share in that particular moment! (it's fast, though)
 my $cleanup_before_increment = 0;
 
+# this option will probably create wrong increments, but it's here for
+# testing and comparison. In short, don't use it!
+my $restore_via_temp_dir = 1;
+
 # connect to BackupPC_server
 
-die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
+my $bpc = BackupPC::Lib->new(undef, undef, 1) || die;
 my %Conf = $bpc->Conf();
 
 $bpc->ChildInit();
@@ -70,6 +74,8 @@ sub cleanup_inc_temp_dir {
 print "# using $inc_tmp_dir for increment scratch space";
 cleanup_inc_temp_dir() if (! $cleanup_before_increment);
 
+my $restore_path = "$Conf{InstallDir}/$Conf{GzipTempDir}/${host}-restore.tar.gz";
+
 # create restore host configuration
 
 my $conf_restore = <<'_END_OF_CONF_';
@@ -86,17 +92,32 @@ $Conf{ClientNameAlias} = 'localhost';
 
 #$Conf{TarIncrArgs} = '';
 #$Conf{ClientTimeout} = 600;
+
+_END_OF_CONF_
+
+$conf_restore .= <<'_END_OF_CONF_' if (! $restore_via_temp_dir);
+
 #$Conf{TarClientCmd} = '';
 #$Conf{TarFullArgs} = 'gzip -cdv __restore_path__';
 
-$Conf{TarClientCmd} = '$tarPath -c -v -f - -C __inc_tmp_dir__ --totals';
+# force BackupPC_tarExtract to produce output of tar -c -v -f - --totals
+# so that we can just pipe tar into it!
+$Conf{tarExtractEmulateTotals} = 1;
+$Conf{TarClientCmd} = 'zcat __restore_path__';
+
+_END_OF_CONF_
+
+$conf_restore .= <<'_END_OF_CONF_' if ($restore_via_temp_dir);
 
-1;
+$Conf{TarClientCmd} = '$tarPath -c -v -f - -C __inc_tmp_dir__ --totals';
 
 _END_OF_CONF_
 
 $conf_restore =~ s/__share__/$share/gs;
 $conf_restore =~ s/__inc_tmp_dir__/$inc_tmp_dir/gs;
+$conf_restore =~ s/__restore_path__/$restore_path/gs;
+
+$conf_restore .= "\n1;\n";
 
 my $config_file = "$bpc->{TopDir}/conf/${host}.pl";
 
@@ -114,12 +135,26 @@ sub restore_increment {
                return;
        }
 
-       print "restoring $path\n";
+       if ($restore_via_temp_dir) {
+
+               print "restoring $path (extracting to create increment)\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";
+       
+       } else {
+
+               print "using $path to create increment\n";
 
-       cleanup_inc_temp_dir() if ($cleanup_before_increment);
+               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";
 
-       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";