7 BackupPC_recover_from_increments
11 quick hack to create BackupPC pool out of increments
15 BackupPC_recover_from_increments /restore/from/directory/ [/path/to/increment/to/restore.tar.gz ... ]
19 2006-02-07 Dobrica Pavlinusic <dpavlin@rot13.org>
26 use lib "/data/backuppc/lib";
31 # connect to BackupPC_server
33 die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
34 my %Conf = $bpc->Conf();
38 my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
40 print("Can't connect to server ($err)\n");
44 my $TopDir = $bpc->TopDir();
48 # check if host exists
50 die "host $host is not found" unless ($bpc->HostInfoRead( $host ));
52 # create restore host configuration
54 my $restore_path = "$Conf{InstallDir}/$Conf{GzipTempDir}/${host}-restore.tar.gz";
56 my $conf_restore = <<'_END_OF_CONF_';
58 $Conf{XferMethod} = 'tar';
60 $Conf{TarFullArgs} = 'echo "full backups are not supported in restore!" ; exit 1';
61 $Conf{TarIncrArgs} = '';
63 # fake ping when restoring
64 $Conf{PingCmd} = '$pingPath -c 1 localhost',
66 $Conf{TarClientCmd} = 'zcat __restore_path__';
72 $conf_restore =~ s/__restore_path__/$restore_path/gs;
74 my $config_file = "$bpc->{TopDir}/conf/${host}.pl";
76 open(my $host_fh, '>', $config_file) || die "can't open $config_file: $!";
77 print $host_fh $conf_restore || die "can't write configuration in $config_file: $!";
78 close($host_fh) || die "can't close $config_file: $!";
80 warn "written config:\n$conf_restore\n";
82 sub restore_increment {
83 my $path = shift || die "need path!";
85 print "working on $path\n";
87 if (-e $restore_path) {
88 unlink $restore_path || die "can't remove $restore_path: $!\n";
90 link $path, $restore_path || die "can't create link $path -> $restore_path: $!\n";
92 $bpc->ServerMesg("log User backuppc started restore of $path");
95 my $r = $bpc->ServerMesg("backup $host $host backuppc $full");
96 print "backup --> $r";
97 die $r if ($r =~ m/^error/);
99 # Status_backup_in_progress
102 my ($state,$last_state) = ('','x');
104 while ($state ne 'Status_idle') {
105 my $s = $bpc->ServerMesg("status hosts");
110 $state = $Status{restore}->{state};
112 die $state if ($state =~ m/^error/);
114 if ($state ne $last_state) {
115 print "\n$state"; #, Dumper($Status{restore});
119 $last_state = $state;
127 foreach my $restore_inc (@ARGV) {
129 if (-d $restore_inc) {
131 find({ wanted => sub {
132 restore_increment( $File::Find::name );
133 }, follow => 0 }, $restore_inc);
135 } elsif (-f $restore_inc && $restore_inc =~ m/\.tar\.gz$/i) {
136 restore_increment( $restore_inc );
138 warn "skipped: $restore_inc, not directory or .tar.gz increment\n";
143 #unlink $config_file || die "can't remove $config_file: $!";