/[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 340 by dpavlin, Mon Mar 6 20:47:00 2006 UTC revision 352 by dpavlin, Wed Apr 26 11:10:48 2006 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3    use strict;
4    
5  =head1 NAME  =head1 NAME
6    
7  BackupPC_recover_from_increments  BackupPC_recover_from_increments
# Line 24  use Data::Dumper; Line 26  use Data::Dumper;
26  use lib "/data/backuppc/lib";  use lib "/data/backuppc/lib";
27  use BackupPC::Lib;  use BackupPC::Lib;
28    
29    my $host = 'restore';
30    my $share = '/etc';
31    
32  # connect to BackupPC_server  # connect to BackupPC_server
33    
34  die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );  die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
# Line 39  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
50    
51    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    
57  my $restore_path = "$TopDir/$temp/restore.tar.gz";  my $restore_path = "$Conf{InstallDir}/$Conf{GzipTempDir}/restore.tar.gz";
58    
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  # disable ping
68  $Conf{PingCmd} = '$pingPath -c 1 localhost',  $Conf{PingCmd} = '';
69    # work-around for Backup aborted because of CorrectHostCheck
70    $Conf{FixedIPNetBiosNameCheck} = 0;
71    $Conf{NmbLookupCmd} = '';
72    $Conf{ClientNameAlias} = 'localhost';
73    
74  $Conf{TarClientCmd} = 'zcat __restore_path__';  $Conf{TarClientCmd} = 'zcat __restore_path__';
75    
# Line 62  $Conf{TarClientCmd} = 'zcat __restore_pa Line 78  $Conf{TarClientCmd} = 'zcat __restore_pa
78  _END_OF_CONF_  _END_OF_CONF_
79    
80  $conf_restore =~ s/__restore_path__/$restore_path/gs;  $conf_restore =~ s/__restore_path__/$restore_path/gs;
81    $conf_restore =~ s/__share__/$share/gs;
82    
83  my $config_file = "$bpc->{TopDir}/conf/restore.pl";  my $config_file = "$bpc->{TopDir}/conf/${host}.pl";
84    
85  open(my $host_fh, '>', $config_file) || die "can't open $config_file: $!";  open(my $host_fh, '>', $config_file) || die "can't open $config_file: $!";
86  print $host_fh $conf_restore || die "can't write configuration in $config_file: $!";  print $host_fh $conf_restore || die "can't write configuration in $config_file: $!";
# Line 74  warn "written config:\n$conf_restore\n"; Line 91  warn "written config:\n$conf_restore\n";
91  sub restore_increment {  sub restore_increment {
92          my $path = shift || die "need path!";          my $path = shift || die "need path!";
93    
94            if ($path !~ m/\.tar\.gz$/i) {
95                    print "skipping $path, not .tar.gz increment\n";
96                    return;
97            }
98    
99          print "working on $path\n";          print "working on $path\n";
100    
101          if (-e $restore_path) {          if (-e $restore_path) {
102                  unlink $restore_path || die "can't remove $restore_path: $!\n";                  unlink $restore_path || die "can't remove $restore_path: $!\n";
103          }          }
104          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";
105    
106          $bpc->ServerMesg("log User backuppc started restore of $path");          my $user = $host_info->{$host}->{user} || die "can't get user for host $host";
107    
108          my $full = 0;          $bpc->ServerMesg("log User $user started recovery from increment $path");
109          my $r = $bpc->ServerMesg("backup restore restore backuppc $full");  
110          print "backup --> $r";          my @backups = $bpc->BackupInfoRead( $host );
111    
112            my $full = 1;
113            foreach my $b (@backups) {
114                    $full = 0 if ($b->{type} eq 'full');
115            }
116    
117            my $r = $bpc->ServerMesg("backup $host $host $user $full");
118            print "backup ", $full ? 'full' : 'incremental', " --> $r";
119            die $r if ($r =~ m/^error/);
120    
121          # Status_backup_in_progress          # Status_backup_in_progress
122          # Status_idle          # Status_idle
# Line 99  sub restore_increment { Line 130  sub restore_increment {
130                          eval "$s";                          eval "$s";
131                  }                  }
132                  $state = $Status{restore}->{state};                  $state = $Status{restore}->{state};
133    
134                    die $state if ($state =~ m/^error/);
135    
136                  if ($state ne $last_state) {                  if ($state ne $last_state) {
137                          print "\n$state"; #, Dumper($Status{restore});                          print "\n$state"; #, Dumper($Status{restore});
138                  } else {                  } else {
# Line 120  foreach my $restore_inc (@ARGV) { Line 154  foreach my $restore_inc (@ARGV) {
154                          restore_increment( $File::Find::name );                          restore_increment( $File::Find::name );
155                  }, follow => 0 }, $restore_inc);                  }, follow => 0 }, $restore_inc);
156    
157          } elsif (-f $restore_inc && $restore_inc =~ m/\.tar\.gz$/i) {          } elsif (-f $restore_inc) {
158                  restore_increment( $restore_inc );                  restore_increment( $restore_inc );
159          } else {          } else {
160                  warn "skipped: $restore_inc, not directory or .tar.gz increment\n";                  warn "skipped: $restore_inc, not file or directory\n";
161          }          }
162    
163  }  }

Legend:
Removed from v.340  
changed lines
  Added in v.352

  ViewVC Help
Powered by ViewVC 1.1.26