5 BackupPC_recover_from_increments
9 quick hack to create BackupPC pool out of increments
13 BackupPC_recover_from_increments /restore/from/directory/ [/path/to/increment/to/restore.tar.gz ... ]
17 2006-02-07 Dobrica Pavlinusic <dpavlin@rot13.org>
24 use lib "/data/backuppc/lib";
27 # connect to BackupPC_server
29 die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
30 my %Conf = $bpc->Conf();
34 my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
36 print("Can't connect to server ($err)\n");
40 my $TopDir = $bpc->TopDir();
44 # create restore host configuration
46 my $restore_path = "$TopDir/$temp/restore.tar.gz";
48 my $conf_restore = <<'_END_OF_CONF_';
50 $Conf{XferMethod} = 'tar';
52 $Conf{TarFullArgs} = 'echo "full backups are not supported in restore!" ; exit 1';
53 $Conf{TarIncrArgs} = '';
55 # fake ping when restoring
56 $Conf{PingCmd} = '$pingPath -c 1 localhost',
58 $Conf{TarClientCmd} = 'zcat __restore_path__';
64 $conf_restore =~ s/__restore_path__/$restore_path/gs;
66 my $config_file = "$bpc->{TopDir}/conf/restore.pl";
68 open(my $host_fh, '>', $config_file) || die "can't open $config_file: $!";
69 print $host_fh $conf_restore || die "can't write configuration in $config_file: $!";
70 close($host_fh) || die "can't close $config_file: $!";
72 warn "written config:\n$conf_restore\n";
74 sub restore_increment {
75 my $path = shift || die "need path!";
77 print "working on $path\n";
79 if (-e $restore_path) {
80 unlink $restore_path || die "can't remove $restore_path: $!\n";
82 link $path, $restore_path || die "can't create link $path -> $restore_path: $!\n";
84 $bpc->ServerMesg("log User backuppc started restore of $path");
87 my $r = $bpc->ServerMesg("backup restore restore backuppc $full");
88 print "backup --> $r";
90 # Status_backup_in_progress
93 my ($state,$last_state) = ('','x');
95 while ($state ne 'Status_idle') {
96 my $s = $bpc->ServerMesg("status hosts");
101 $state = $Status{restore}->{state};
102 if ($state ne $last_state) {
103 print "\n$state"; #, Dumper($Status{restore});
107 $last_state = $state;
115 foreach my $restore_inc (@ARGV) {
117 if (-d $restore_inc) {
119 find({ wanted => sub {
120 restore_increment( $File::Find::name );
121 }, follow => 0 }, $restore_inc);
123 } elsif (-f $restore_inc && $restore_inc =~ m/\.tar\.gz$/i) {
124 restore_increment( $restore_inc );
126 warn "skipped: $restore_inc, not directory or .tar.gz increment\n";
131 #unlink $config_file || die "can't remove $config_file: $!";