/[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 361 by dpavlin, Sat Apr 29 10:59:09 2006 UTC revision 362 by dpavlin, Sat Apr 29 12:29:15 2006 UTC
# Line 127  close($host_fh) || die "can't close $con Line 127  close($host_fh) || die "can't close $con
127    
128  warn "written config:\n$conf_restore\n";  warn "written config:\n$conf_restore\n";
129    
130  sub restore_increment {  sub restore_increments {
         my $path = shift || die "need path!";  
131    
132          if ($path !~ m/\.tar\.gz$/i) {          foreach my $path (@_) {
133                  print "# skipping $path, not .tar.gz increment\n";                  next unless ($path);    # skip 0 element which is undef
                 return;  
         }  
   
         if ($restore_via_temp_dir) {  
   
                 print "restoring $path (extracting to create increment)\n";  
134    
135                  cleanup_inc_temp_dir() if ($cleanup_before_increment);                  print "extracting $path\n";
136    
137                  my $cmd = "cd $inc_tmp_dir && tar xfz $path";                  my $cmd = "cd $inc_tmp_dir && tar xfz $path";
138                  system($cmd) == 0 or die "can't execute: $cmd -- $?\n";                  system($cmd) == 0 or die "can't execute: $cmd -- $?\n";
139                    
         } else {  
   
                 print "using $path to create increment\n";  
   
                 if (-e $restore_path) {  
                         unlink $restore_path || die "can't remove $restore_path: $!\n";  
                 }  
                 symlink $path, $restore_path || die "can't create link $path -> $restore_path: $!\n";  
   
   
140          }          }
141    
142    #       print "using $path to create increment\n";
143    #
144    #       if (-e $restore_path) {
145    #               unlink $restore_path || die "can't remove $restore_path: $!\n";
146    #       }
147    #       symlink $path, $restore_path || die "can't create link $path -> $restore_path: $!\n";
148    
149          print "starting import into BackupPC pool\n";          print "starting import into BackupPC pool\n";
150    
151          my $user = $host_info->{$host}->{user} || die "can't get user for host $host";          my $user = $host_info->{$host}->{user} || die "can't get user for host $host";
152    
         $bpc->ServerMesg("log User $user started recovery from increment $path");  
   
153          my @backups = $bpc->BackupInfoRead( $host );          my @backups = $bpc->BackupInfoRead( $host );
154    
155          my $full = 1;          my $full = 1;
# Line 201  sub restore_increment { Line 189  sub restore_increment {
189    
190  # now, start restore  # now, start restore
191    
192    my $increments;
193    
194  foreach my $restore_inc (@ARGV) {  foreach my $restore_inc (@ARGV) {
195    
196            sub extract_filename {
197                    my $path = shift || die "no path?";
198                    if ($path =~ m#^(.*)/(\w+)_(\w+)_(\d+)\.tar\.gz$#) {
199                            my ($path,$host,$share,$num) = ($1,$2,$3,$4);
200                            $increments->{$host}->{$share}->{$num}->[1] = "${path}/${host}_${share}_${num}.tar.gz";
201                    } elsif ($path =~ m#^(.*)/(\w+)_(\w+)_(\d+)/(\d+)\.tar.gz$#) {
202                            my ($path,$host,$share,$num,$part) = ($1,$2,$3,$4,$5);
203                            $increments->{$host}->{$share}->{$num}->[$part] = "${path}/${host}_${share}_${num}/${part}.tar.gz";
204                    } else {
205                            print "# skipped: $path\n";
206                    }
207            }
208    
209          if (-d $restore_inc) {          if (-d $restore_inc) {
210    
211                  find({ wanted => sub {                  find({ wanted => sub {
212                          restore_increment( $File::Find::name );                          extract_filename( $File::Find::name );
213                  }, follow => 0 }, $restore_inc);                  }, follow => 0 }, $restore_inc);
214    
215          } elsif (-f $restore_inc) {          } elsif (-f $restore_inc) {
216                  restore_increment( $restore_inc );                  extract_filename( $restore_inc );
217          } else {          } else {
218                  warn "skipped: $restore_inc, not file or directory\n";                  warn "skipped: $restore_inc, not file or directory\n";
219          }          }
220    
221  }  }
222    
223    print Dumper($increments);
224    
225    cleanup_inc_temp_dir();
226    
227    foreach my $host (sort keys %{ $increments }) {
228            foreach my $share (sort keys %{ $increments->{$host} }) {
229                    foreach my $num (sort keys %{ $increments->{$host}->{$share} }) {
230                            print "# about to restore $host $share $num\n";
231                            my @parts = @{ $increments->{$host}->{$share}->{$num} };
232                            my $msg = "started recovery of ${host}:${share}#${num} with " . $#parts . " parts";
233    
234                            print "LOG: $msg\n";
235                            $bpc->ServerMesg("log $msg");
236    
237                            restore_increments( @parts );
238                    }
239            }
240    }
241                    
242    
243  #unlink $config_file || die "can't remove $config_file: $!";  #unlink $config_file || die "can't remove $config_file: $!";
244    
245  rmtree($inc_tmp_dir) if (-e $inc_tmp_dir);  rmtree($inc_tmp_dir) if (-e $inc_tmp_dir);

Legend:
Removed from v.361  
changed lines
  Added in v.362

  ViewVC Help
Powered by ViewVC 1.1.26