--- trunk/bin/BackupPC_recover_from_increments 2006/03/07 10:17:56 342 +++ trunk/bin/BackupPC_recover_from_increments 2006/03/07 16:24:26 349 @@ -27,6 +27,7 @@ use BackupPC::Lib; my $host = 'restore'; +my $share = '/etc'; # connect to BackupPC_server @@ -43,11 +44,13 @@ my $TopDir = $bpc->TopDir(); -print Dumper(\%Conf); +#print Dumper(\%Conf); # check if host exists -die "host $host is not found" unless ($bpc->HostInfoRead( $host )); +my $host_info = $bpc->HostInfoRead( $host ); +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 @@ -56,12 +59,14 @@ 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', +$Conf{ClientNameAlias} = 'localhost'; $Conf{TarClientCmd} = 'zcat __restore_path__'; @@ -70,6 +75,7 @@ _END_OF_CONF_ $conf_restore =~ s/__restore_path__/$restore_path/gs; +$conf_restore =~ s/__share__/$share/gs; my $config_file = "$bpc->{TopDir}/conf/${host}.pl"; @@ -82,18 +88,31 @@ sub restore_increment { my $path = shift || die "need path!"; + if ($path !~ m/\.tar\.gz$/i) { + print "skipping $path, not .tar.gz increment\n"; + return; + } + print "working on $path\n"; if (-e $restore_path) { unlink $restore_path || die "can't remove $restore_path: $!\n"; } - link $path, $restore_path || die "can't create link $path -> $restore_path: $!\n"; + symlink $path, $restore_path || die "can't create link $path -> $restore_path: $!\n"; + + my $user = $host_info->{$host}->{user} || die "can't get user for host $host"; - $bpc->ServerMesg("log User backuppc started restore of $path"); + $bpc->ServerMesg("log User $user started recovery from increment $path"); + + my @backups = $bpc->BackupInfoRead( $host ); + + my $full = 1; + foreach my $b (@backups) { + $full = 0 if ($b->{type} eq 'full'); + } - my $full = 0; - my $r = $bpc->ServerMesg("backup $host $host backuppc $full"); - print "backup --> $r"; + my $r = $bpc->ServerMesg("backup $host $host $user $full"); + print "backup ", $full ? 'full' : 'incremental', " --> $r"; die $r if ($r =~ m/^error/); # Status_backup_in_progress @@ -132,10 +151,10 @@ 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"; } }