/[BackupPC]/trunk/bin/BackupPC_recover_from_increments
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/BackupPC_recover_from_increments

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 342 by dpavlin, Tue Mar 7 10:17:56 2006 UTC revision 349 by dpavlin, Tue Mar 7 16:24:26 2006 UTC
# Line 27  use lib "/data/backuppc/lib"; Line 27  use lib "/data/backuppc/lib";
27  use BackupPC::Lib;  use BackupPC::Lib;
28    
29  my $host = 'restore';  my $host = 'restore';
30    my $share = '/etc';
31    
32  # connect to BackupPC_server  # connect to BackupPC_server
33    
# Line 43  if ( $err ) { Line 44  if ( $err ) {
44    
45  my $TopDir = $bpc->TopDir();  my $TopDir = $bpc->TopDir();
46    
47  print Dumper(\%Conf);  #print Dumper(\%Conf);
48    
49  # check if host exists  # check if host exists
50    
51  die "host $host is not found" unless ($bpc->HostInfoRead( $host ));  my $host_info = $bpc->HostInfoRead( $host );
52    print Dumper($host_info, $bpc->HostInfoRead( 'localhost' ));
53    die "host '$host' is not found, please add it to config/hosts configuration file\n" unless ($host_info->{$host});
54    
55  # create restore host configuration  # create restore host configuration
56    
# Line 56  my $restore_path = "$Conf{InstallDir}/$C Line 59  my $restore_path = "$Conf{InstallDir}/$C
59  my $conf_restore = <<'_END_OF_CONF_';  my $conf_restore = <<'_END_OF_CONF_';
60    
61  $Conf{XferMethod} = 'tar';  $Conf{XferMethod} = 'tar';
62    $Conf{TarShareName} = '__share__';
63    
64  $Conf{TarFullArgs} = 'echo "full backups are not supported in restore!" ; exit 1';  $Conf{TarFullArgs} = 'echo "full backups are not supported in restore!" ; exit 1';
65  $Conf{TarIncrArgs} = '';  $Conf{TarIncrArgs} = '';
66    
67  # fake ping when restoring  # fake ping when restoring
68  $Conf{PingCmd} = '$pingPath -c 1 localhost',  $Conf{PingCmd} = '$pingPath -c 1 localhost',
69    $Conf{ClientNameAlias} = 'localhost';
70    
71  $Conf{TarClientCmd} = 'zcat __restore_path__';  $Conf{TarClientCmd} = 'zcat __restore_path__';
72    
# Line 70  $Conf{TarClientCmd} = 'zcat __restore_pa Line 75  $Conf{TarClientCmd} = 'zcat __restore_pa
75  _END_OF_CONF_  _END_OF_CONF_
76    
77  $conf_restore =~ s/__restore_path__/$restore_path/gs;  $conf_restore =~ s/__restore_path__/$restore_path/gs;
78    $conf_restore =~ s/__share__/$share/gs;
79    
80  my $config_file = "$bpc->{TopDir}/conf/${host}.pl";  my $config_file = "$bpc->{TopDir}/conf/${host}.pl";
81    
# Line 82  warn "written config:\n$conf_restore\n"; Line 88  warn "written config:\n$conf_restore\n";
88  sub restore_increment {  sub restore_increment {
89          my $path = shift || die "need path!";          my $path = shift || die "need path!";
90    
91            if ($path !~ m/\.tar\.gz$/i) {
92                    print "skipping $path, not .tar.gz increment\n";
93                    return;
94            }
95    
96          print "working on $path\n";          print "working on $path\n";
97    
98          if (-e $restore_path) {          if (-e $restore_path) {
99                  unlink $restore_path || die "can't remove $restore_path: $!\n";                  unlink $restore_path || die "can't remove $restore_path: $!\n";
100          }          }
101          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";
102    
103            my $user = $host_info->{$host}->{user} || die "can't get user for host $host";
104    
105          $bpc->ServerMesg("log User backuppc started restore of $path");          $bpc->ServerMesg("log User $user started recovery from increment $path");
106    
107            my @backups = $bpc->BackupInfoRead( $host );
108    
109            my $full = 1;
110            foreach my $b (@backups) {
111                    $full = 0 if ($b->{type} eq 'full');
112            }
113    
114          my $full = 0;          my $r = $bpc->ServerMesg("backup $host $host $user $full");
115          my $r = $bpc->ServerMesg("backup $host $host backuppc $full");          print "backup ", $full ? 'full' : 'incremental', " --> $r";
         print "backup --> $r";  
116          die $r if ($r =~ m/^error/);          die $r if ($r =~ m/^error/);
117    
118          # Status_backup_in_progress          # Status_backup_in_progress
# Line 132  foreach my $restore_inc (@ARGV) { Line 151  foreach my $restore_inc (@ARGV) {
151                          restore_increment( $File::Find::name );                          restore_increment( $File::Find::name );
152                  }, follow => 0 }, $restore_inc);                  }, follow => 0 }, $restore_inc);
153    
154          } elsif (-f $restore_inc && $restore_inc =~ m/\.tar\.gz$/i) {          } elsif (-f $restore_inc) {
155                  restore_increment( $restore_inc );                  restore_increment( $restore_inc );
156          } else {          } else {
157                  warn "skipped: $restore_inc, not directory or .tar.gz increment\n";                  warn "skipped: $restore_inc, not file or directory\n";
158          }          }
159    
160  }  }

Legend:
Removed from v.342  
changed lines
  Added in v.349

  ViewVC Help
Powered by ViewVC 1.1.26