/[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 333 by dpavlin, Tue Feb 7 21:22:29 2006 UTC revision 344 by dpavlin, Tue Mar 7 10:42:35 2006 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2    
3  # quick hack to create BackupPC pool out of increments  use strict;
4    
5  # 2006-02-07 Dobrica Pavlinusic <dpavlin@rot13.org>  =head1 NAME
6    
7    BackupPC_recover_from_increments
8    
9    =head1 DESCRIPTION
10    
11    quick hack to create BackupPC pool out of increments
12    
13    =head1 SYNOPSYS
14    
15     BackupPC_recover_from_increments /restore/from/directory/ [/path/to/increment/to/restore.tar.gz ... ]
16    
17    =head1 HISTORY
18    
19    2006-02-07 Dobrica Pavlinusic <dpavlin@rot13.org>
20    
21    =cut
22    
23  use File::Find;  use File::Find;
24  use Data::Dumper;  use Data::Dumper;
# Line 10  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';
 my $restore_path = './temp/restore.tar.gz';  
30    
31  # connect to BackupPC_server  # connect to BackupPC_server
32    
33  die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );  die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
34  my %Conf   = $bpc->Conf();  my %Conf = $bpc->Conf();
35    
36  $bpc->ChildInit();  $bpc->ChildInit();
37    
# Line 26  if ( $err ) { Line 41  if ( $err ) {
41      exit(1);      exit(1);
42  }  }
43    
44  sub increment {  my $TopDir = $bpc->TopDir();
45          my $path = $File::Find::name;  
46    #print Dumper(\%Conf);
47    
48    # check if host exists
49    
50    my $host_info = $bpc->HostInfoRead( $host );
51    print Dumper($host_info, $bpc->HostInfoRead( 'localhost' ));
52    die "host '$host' is not found, please add it to config/hosts configuration file\n" unless ($host_info->{$host});
53    
54    # create restore host configuration
55    
56    my $restore_path = "$Conf{InstallDir}/$Conf{GzipTempDir}/${host}-restore.tar.gz";
57    
58    my $conf_restore = <<'_END_OF_CONF_';
59    
60    $Conf{XferMethod} = 'tar';
61    
62    $Conf{TarFullArgs} = 'echo "full backups are not supported in restore!" ; exit 1';
63    $Conf{TarIncrArgs} = '';
64    
65    # fake ping when restoring
66    $Conf{PingCmd} = '$pingPath -c 1 localhost',
67    
68    $Conf{TarClientCmd} = 'zcat __restore_path__';
69    
70    1;
71    
72    _END_OF_CONF_
73    
74    $conf_restore =~ s/__restore_path__/$restore_path/gs;
75    
76    my $config_file = "$bpc->{TopDir}/conf/${host}.pl";
77    
78    open(my $host_fh, '>', $config_file) || die "can't open $config_file: $!";
79    print $host_fh $conf_restore || die "can't write configuration in $config_file: $!";
80    close($host_fh) || die "can't close $config_file: $!";
81    
82    warn "written config:\n$conf_restore\n";
83    
84    sub restore_increment {
85            my $path = shift || die "need path!";
86    
87          print "working on $path\n";          print "working on $path\n";
88    
# Line 36  sub increment { Line 91  sub increment {
91          }          }
92          link $path, $restore_path || die "can't create link $path -> $restore_path: $!\n";          link $path, $restore_path || die "can't create link $path -> $restore_path: $!\n";
93    
94          $bpc->ServerMesg("log User backuppc started restore of $restore_path");          my $user = $host_info->{$host}->{user} || die "can't get user for host $host";
95    
96            $bpc->ServerMesg("log User $user started recovery from increment $path");
97    
98          my $full = 0;          my $full = 0;
99          my $r = $bpc->ServerMesg("backup restore restore backuppc $full");          my $r = $bpc->ServerMesg("backup $host $host $user $full");
100          print "backup --> $r\n";          print "backup --> $r";
101            die $r if ($r =~ m/^error/);
102    
103          # Status_backup_in_progress          # Status_backup_in_progress
104          # Status_idle          # Status_idle
105    
106          my $state = 'unknown';          my ($state,$last_state) = ('','x');
107    
108          while ($state ne 'Status_idle') {          while ($state ne 'Status_idle') {
109                  my $s = $bpc->ServerMesg("status hosts");                  my $s = $bpc->ServerMesg("status hosts");
# Line 54  sub increment { Line 112  sub increment {
112                          eval "$s";                          eval "$s";
113                  }                  }
114                  $state = $Status{restore}->{state};                  $state = $Status{restore}->{state};
115                  print "# $state\n"; #, Dumper($Status{restore});  
116                    die $state if ($state =~ m/^error/);
117    
118                    if ($state ne $last_state) {
119                            print "\n$state"; #, Dumper($Status{restore});
120                    } else {
121                            print ".";
122                    }
123                    $last_state = $state;
124                  sleep 1;                  sleep 1;
125          }          }
126            print "\n";
127  }  }
128    
129  find({ wanted => \&increment, follow => 0 }, './temp');  # now, start restore
130    
131    foreach my $restore_inc (@ARGV) {
132    
133            if (-d $restore_inc) {
134    
135                    find({ wanted => sub {
136                            restore_increment( $File::Find::name );
137                    }, follow => 0 }, $restore_inc);
138    
139            } elsif (-f $restore_inc && $restore_inc =~ m/\.tar\.gz$/i) {
140                    restore_increment( $restore_inc );
141            } else {
142                    warn "skipped: $restore_inc, not directory or .tar.gz increment\n";
143            }
144    
145    }
146    
147    #unlink $config_file || die "can't remove $config_file: $!";

Legend:
Removed from v.333  
changed lines
  Added in v.344

  ViewVC Help
Powered by ViewVC 1.1.26