From 59947f8fa8af3769b99faa2cbd5c4ea6e7acf666 Mon Sep 17 00:00:00 2001 From: dpavlin Date: Mon, 6 Mar 2006 20:47:00 +0000 Subject: [PATCH] create host config file, auto-configure path to restore file, better output when in progres, support restore from directory or for increments specified at command line git-svn-id: svn+ssh://llin/home/dpavlin/private/svn/BackupPC/trunk@340 8392b6e1-25fa-0310-8288-cc32f8e212ea --- bin/BackupPC_recover_from_increments | 94 ++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 13 deletions(-) diff --git a/bin/BackupPC_recover_from_increments b/bin/BackupPC_recover_from_increments index 867934c..631bff3 100755 --- a/bin/BackupPC_recover_from_increments +++ b/bin/BackupPC_recover_from_increments @@ -1,8 +1,22 @@ #!/usr/bin/perl -w -# quick hack to create BackupPC pool out of increments +=head1 NAME -# 2006-02-07 Dobrica Pavlinusic +BackupPC_recover_from_increments + +=head1 DESCRIPTION + +quick hack to create BackupPC pool out of increments + +=head1 SYNOPSYS + + BackupPC_recover_from_increments /restore/from/directory/ [/path/to/increment/to/restore.tar.gz ... ] + +=head1 HISTORY + +2006-02-07 Dobrica Pavlinusic + +=cut use File::Find; use Data::Dumper; @@ -10,13 +24,10 @@ use Data::Dumper; use lib "/data/backuppc/lib"; use BackupPC::Lib; - -my $restore_path = './temp/restore.tar.gz'; - # connect to BackupPC_server die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) ); -my %Conf = $bpc->Conf(); +my %Conf = $bpc->Conf(); $bpc->ChildInit(); @@ -26,8 +37,42 @@ if ( $err ) { exit(1); } -sub increment { - my $path = $File::Find::name; +my $TopDir = $bpc->TopDir(); + +print Dumper(\%Conf); + +# create restore host configuration + +my $restore_path = "$TopDir/$temp/restore.tar.gz"; + +my $conf_restore = <<'_END_OF_CONF_'; + +$Conf{XferMethod} = 'tar'; + +$Conf{TarFullArgs} = 'echo "full backups are not supported in restore!" ; exit 1'; +$Conf{TarIncrArgs} = ''; + +# fake ping when restoring +$Conf{PingCmd} = '$pingPath -c 1 localhost', + +$Conf{TarClientCmd} = 'zcat __restore_path__'; + +1; + +_END_OF_CONF_ + +$conf_restore =~ s/__restore_path__/$restore_path/gs; + +my $config_file = "$bpc->{TopDir}/conf/restore.pl"; + +open(my $host_fh, '>', $config_file) || die "can't open $config_file: $!"; +print $host_fh $conf_restore || die "can't write configuration in $config_file: $!"; +close($host_fh) || die "can't close $config_file: $!"; + +warn "written config:\n$conf_restore\n"; + +sub restore_increment { + my $path = shift || die "need path!"; print "working on $path\n"; @@ -36,16 +81,16 @@ sub increment { } link $path, $restore_path || die "can't create link $path -> $restore_path: $!\n"; - $bpc->ServerMesg("log User backuppc started restore of $restore_path"); + $bpc->ServerMesg("log User backuppc started restore of $path"); my $full = 0; my $r = $bpc->ServerMesg("backup restore restore backuppc $full"); - print "backup --> $r\n"; + print "backup --> $r"; # Status_backup_in_progress # Status_idle - my $state = 'unknown'; + my ($state,$last_state) = ('','x'); while ($state ne 'Status_idle') { my $s = $bpc->ServerMesg("status hosts"); @@ -54,10 +99,33 @@ sub increment { eval "$s"; } $state = $Status{restore}->{state}; - print "# $state\n"; #, Dumper($Status{restore}); + if ($state ne $last_state) { + print "\n$state"; #, Dumper($Status{restore}); + } else { + print "."; + } + $last_state = $state; sleep 1; } + print "\n"; } -find({ wanted => \&increment, follow => 0 }, './temp'); +# now, start restore + +foreach my $restore_inc (@ARGV) { + + if (-d $restore_inc) { + + find({ wanted => sub { + restore_increment( $File::Find::name ); + }, follow => 0 }, $restore_inc); + + } elsif (-f $restore_inc && $restore_inc =~ m/\.tar\.gz$/i) { + restore_increment( $restore_inc ); + } else { + warn "skipped: $restore_inc, not directory or .tar.gz increment\n"; + } + +} +#unlink $config_file || die "can't remove $config_file: $!"; -- 2.20.1