#!/usr/bin/perl -w =head1 NAME 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; use lib "/data/backuppc/lib"; use BackupPC::Lib; # connect to BackupPC_server die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) ); my %Conf = $bpc->Conf(); $bpc->ChildInit(); my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}); if ( $err ) { print("Can't connect to server ($err)\n"); exit(1); } 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"; 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"; $bpc->ServerMesg("log User backuppc started restore of $path"); my $full = 0; my $r = $bpc->ServerMesg("backup restore restore backuppc $full"); print "backup --> $r"; # Status_backup_in_progress # Status_idle my ($state,$last_state) = ('','x'); while ($state ne 'Status_idle') { my $s = $bpc->ServerMesg("status hosts"); my %Status; { eval "$s"; } $state = $Status{restore}->{state}; if ($state ne $last_state) { print "\n$state"; #, Dumper($Status{restore}); } else { print "."; } $last_state = $state; sleep 1; } print "\n"; } # 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: $!";