/[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

Annotation of /trunk/bin/BackupPC_recover_from_increments

Parent Directory Parent Directory | Revision Log Revision Log


Revision 348 - (hide annotations)
Tue Mar 7 16:14:49 2006 UTC (18 years, 2 months ago) by dpavlin
File size: 3536 byte(s)
 r10315@llin:  dpavlin | 2006-03-07 17:14:42 +0100
 make first backup full if there is none

1 dpavlin 333 #!/usr/bin/perl -w
2    
3 dpavlin 342 use strict;
4    
5 dpavlin 340 =head1 NAME
6 dpavlin 333
7 dpavlin 340 BackupPC_recover_from_increments
8 dpavlin 333
9 dpavlin 340 =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 dpavlin 333 use File::Find;
24     use Data::Dumper;
25    
26     use lib "/data/backuppc/lib";
27     use BackupPC::Lib;
28    
29 dpavlin 342 my $host = 'restore';
30    
31 dpavlin 333 # connect to BackupPC_server
32    
33     die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
34 dpavlin 340 my %Conf = $bpc->Conf();
35 dpavlin 333
36     $bpc->ChildInit();
37    
38     my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
39     if ( $err ) {
40     print("Can't connect to server ($err)\n");
41     exit(1);
42     }
43    
44 dpavlin 340 my $TopDir = $bpc->TopDir();
45 dpavlin 333
46 dpavlin 343 #print Dumper(\%Conf);
47 dpavlin 340
48 dpavlin 342 # check if host exists
49    
50 dpavlin 343 my $host_info = $bpc->HostInfoRead( $host );
51 dpavlin 344 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 dpavlin 342
54 dpavlin 340 # create restore host configuration
55    
56 dpavlin 342 my $restore_path = "$Conf{InstallDir}/$Conf{GzipTempDir}/${host}-restore.tar.gz";
57 dpavlin 340
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 dpavlin 345 $Conf{ClientNameAlias} = 'localhost';
68 dpavlin 340
69     $Conf{TarClientCmd} = 'zcat __restore_path__';
70    
71     1;
72    
73     _END_OF_CONF_
74    
75     $conf_restore =~ s/__restore_path__/$restore_path/gs;
76    
77 dpavlin 342 my $config_file = "$bpc->{TopDir}/conf/${host}.pl";
78 dpavlin 340
79     open(my $host_fh, '>', $config_file) || die "can't open $config_file: $!";
80     print $host_fh $conf_restore || die "can't write configuration in $config_file: $!";
81     close($host_fh) || die "can't close $config_file: $!";
82    
83     warn "written config:\n$conf_restore\n";
84    
85     sub restore_increment {
86     my $path = shift || die "need path!";
87    
88 dpavlin 347 if ($path !~ m/\.tar\.gz$/i) {
89     print "skipping $path, not .tar.gz increment\n";
90     return;
91     }
92    
93 dpavlin 333 print "working on $path\n";
94    
95     if (-e $restore_path) {
96     unlink $restore_path || die "can't remove $restore_path: $!\n";
97     }
98 dpavlin 346 symlink $path, $restore_path || die "can't create link $path -> $restore_path: $!\n";
99 dpavlin 333
100 dpavlin 344 my $user = $host_info->{$host}->{user} || die "can't get user for host $host";
101 dpavlin 333
102 dpavlin 344 $bpc->ServerMesg("log User $user started recovery from increment $path");
103    
104 dpavlin 348 my @backups = $bpc->BackupInfoRead( $host );
105    
106     my $full = 1;
107     foreach my $b (@backups) {
108     $full = 0 if ($b->{type} eq 'full');
109     }
110    
111 dpavlin 344 my $r = $bpc->ServerMesg("backup $host $host $user $full");
112 dpavlin 348 print "backup ", $full ? 'full' : 'incremental', " --> $r";
113 dpavlin 342 die $r if ($r =~ m/^error/);
114 dpavlin 333
115     # Status_backup_in_progress
116     # Status_idle
117    
118 dpavlin 340 my ($state,$last_state) = ('','x');
119 dpavlin 333
120     while ($state ne 'Status_idle') {
121     my $s = $bpc->ServerMesg("status hosts");
122     my %Status;
123     {
124     eval "$s";
125     }
126     $state = $Status{restore}->{state};
127 dpavlin 342
128     die $state if ($state =~ m/^error/);
129    
130 dpavlin 340 if ($state ne $last_state) {
131     print "\n$state"; #, Dumper($Status{restore});
132     } else {
133     print ".";
134     }
135     $last_state = $state;
136 dpavlin 333 sleep 1;
137     }
138 dpavlin 340 print "\n";
139 dpavlin 333 }
140    
141 dpavlin 340 # now, start restore
142 dpavlin 333
143 dpavlin 340 foreach my $restore_inc (@ARGV) {
144    
145     if (-d $restore_inc) {
146    
147     find({ wanted => sub {
148     restore_increment( $File::Find::name );
149     }, follow => 0 }, $restore_inc);
150    
151 dpavlin 347 } elsif (-f $restore_inc) {
152 dpavlin 340 restore_increment( $restore_inc );
153     } else {
154 dpavlin 347 warn "skipped: $restore_inc, not file or directory\n";
155 dpavlin 340 }
156    
157     }
158    
159     #unlink $config_file || die "can't remove $config_file: $!";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26