/[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 342 - (show annotations)
Tue Mar 7 10:17:56 2006 UTC (18 years, 2 months ago) by dpavlin
File size: 3049 byte(s)
 r10303@llin:  dpavlin | 2006-03-07 11:17:50 +0100
 configure hostname to use for restore, different path to current increment
 which is restored, check for hosts (which doesn't still work), die on errors

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
31 # connect to BackupPC_server
32
33 die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
34 my %Conf = $bpc->Conf();
35
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 my $TopDir = $bpc->TopDir();
45
46 print Dumper(\%Conf);
47
48 # check if host exists
49
50 die "host $host is not found" unless ($bpc->HostInfoRead( $host ));
51
52 # create restore host configuration
53
54 my $restore_path = "$Conf{InstallDir}/$Conf{GzipTempDir}/${host}-restore.tar.gz";
55
56 my $conf_restore = <<'_END_OF_CONF_';
57
58 $Conf{XferMethod} = 'tar';
59
60 $Conf{TarFullArgs} = 'echo "full backups are not supported in restore!" ; exit 1';
61 $Conf{TarIncrArgs} = '';
62
63 # fake ping when restoring
64 $Conf{PingCmd} = '$pingPath -c 1 localhost',
65
66 $Conf{TarClientCmd} = 'zcat __restore_path__';
67
68 1;
69
70 _END_OF_CONF_
71
72 $conf_restore =~ s/__restore_path__/$restore_path/gs;
73
74 my $config_file = "$bpc->{TopDir}/conf/${host}.pl";
75
76 open(my $host_fh, '>', $config_file) || die "can't open $config_file: $!";
77 print $host_fh $conf_restore || die "can't write configuration in $config_file: $!";
78 close($host_fh) || die "can't close $config_file: $!";
79
80 warn "written config:\n$conf_restore\n";
81
82 sub restore_increment {
83 my $path = shift || die "need path!";
84
85 print "working on $path\n";
86
87 if (-e $restore_path) {
88 unlink $restore_path || die "can't remove $restore_path: $!\n";
89 }
90 link $path, $restore_path || die "can't create link $path -> $restore_path: $!\n";
91
92 $bpc->ServerMesg("log User backuppc started restore of $path");
93
94 my $full = 0;
95 my $r = $bpc->ServerMesg("backup $host $host backuppc $full");
96 print "backup --> $r";
97 die $r if ($r =~ m/^error/);
98
99 # Status_backup_in_progress
100 # Status_idle
101
102 my ($state,$last_state) = ('','x');
103
104 while ($state ne 'Status_idle') {
105 my $s = $bpc->ServerMesg("status hosts");
106 my %Status;
107 {
108 eval "$s";
109 }
110 $state = $Status{restore}->{state};
111
112 die $state if ($state =~ m/^error/);
113
114 if ($state ne $last_state) {
115 print "\n$state"; #, Dumper($Status{restore});
116 } else {
117 print ".";
118 }
119 $last_state = $state;
120 sleep 1;
121 }
122 print "\n";
123 }
124
125 # now, start restore
126
127 foreach my $restore_inc (@ARGV) {
128
129 if (-d $restore_inc) {
130
131 find({ wanted => sub {
132 restore_increment( $File::Find::name );
133 }, follow => 0 }, $restore_inc);
134
135 } elsif (-f $restore_inc && $restore_inc =~ m/\.tar\.gz$/i) {
136 restore_increment( $restore_inc );
137 } else {
138 warn "skipped: $restore_inc, not directory or .tar.gz increment\n";
139 }
140
141 }
142
143 #unlink $config_file || die "can't remove $config_file: $!";

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26