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

Contents of /trunk/bin/BackupPC_recover_from_increments

Parent Directory Parent Directory | Revision Log Revision Log


Revision 349 - (show annotations)
Tue Mar 7 16:24:26 2006 UTC (18 years, 2 months ago) by dpavlin
File size: 3631 byte(s)
 r10317@llin:  dpavlin | 2006-03-07 17:24:19 +0100
 added TarShareName to re-create share name

1 #!/usr/bin/perl -w
2
3 use strict;
4
5 =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;
24 use Data::Dumper;
25
26 use lib "/data/backuppc/lib";
27 use BackupPC::Lib;
28
29 my $host = 'restore';
30 my $share = '/etc';
31
32 # connect to BackupPC_server
33
34 die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
35 my %Conf = $bpc->Conf();
36
37 $bpc->ChildInit();
38
39 my $err = $bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort});
40 if ( $err ) {
41 print("Can't connect to server ($err)\n");
42 exit(1);
43 }
44
45 my $TopDir = $bpc->TopDir();
46
47 #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
56
57 my $restore_path = "$Conf{InstallDir}/$Conf{GzipTempDir}/${host}-restore.tar.gz";
58
59 my $conf_restore = <<'_END_OF_CONF_';
60
61 $Conf{XferMethod} = 'tar';
62 $Conf{TarShareName} = '__share__';
63
64 $Conf{TarFullArgs} = 'echo "full backups are not supported in restore!" ; exit 1';
65 $Conf{TarIncrArgs} = '';
66
67 # fake ping when restoring
68 $Conf{PingCmd} = '$pingPath -c 1 localhost',
69 $Conf{ClientNameAlias} = 'localhost';
70
71 $Conf{TarClientCmd} = 'zcat __restore_path__';
72
73 1;
74
75 _END_OF_CONF_
76
77 $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";
81
82 open(my $host_fh, '>', $config_file) || die "can't open $config_file: $!";
83 print $host_fh $conf_restore || die "can't write configuration in $config_file: $!";
84 close($host_fh) || die "can't close $config_file: $!";
85
86 warn "written config:\n$conf_restore\n";
87
88 sub restore_increment {
89 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";
97
98 if (-e $restore_path) {
99 unlink $restore_path || die "can't remove $restore_path: $!\n";
100 }
101 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 $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 $r = $bpc->ServerMesg("backup $host $host $user $full");
115 print "backup ", $full ? 'full' : 'incremental', " --> $r";
116 die $r if ($r =~ m/^error/);
117
118 # Status_backup_in_progress
119 # Status_idle
120
121 my ($state,$last_state) = ('','x');
122
123 while ($state ne 'Status_idle') {
124 my $s = $bpc->ServerMesg("status hosts");
125 my %Status;
126 {
127 eval "$s";
128 }
129 $state = $Status{restore}->{state};
130
131 die $state if ($state =~ m/^error/);
132
133 if ($state ne $last_state) {
134 print "\n$state"; #, Dumper($Status{restore});
135 } else {
136 print ".";
137 }
138 $last_state = $state;
139 sleep 1;
140 }
141 print "\n";
142 }
143
144 # now, start restore
145
146 foreach my $restore_inc (@ARGV) {
147
148 if (-d $restore_inc) {
149
150 find({ wanted => sub {
151 restore_increment( $File::Find::name );
152 }, follow => 0 }, $restore_inc);
153
154 } elsif (-f $restore_inc) {
155 restore_increment( $restore_inc );
156 } else {
157 warn "skipped: $restore_inc, not file or directory\n";
158 }
159
160 }
161
162 #unlink $config_file || die "can't remove $config_file: $!";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26