21 |
=cut |
=cut |
22 |
|
|
23 |
use File::Find; |
use File::Find; |
24 |
|
use File::Path; |
25 |
use Data::Dumper; |
use Data::Dumper; |
26 |
|
|
27 |
use lib "/data/backuppc/lib"; |
use lib "/data/backuppc/lib"; |
28 |
use BackupPC::Lib; |
use BackupPC::Lib; |
29 |
|
|
30 |
my $host = 'restore'; |
my $host = 'restore'; |
31 |
|
my $share = '/etc'; |
32 |
|
|
33 |
# connect to BackupPC_server |
# connect to BackupPC_server |
34 |
|
|
50 |
# check if host exists |
# check if host exists |
51 |
|
|
52 |
my $host_info = $bpc->HostInfoRead( $host ); |
my $host_info = $bpc->HostInfoRead( $host ); |
53 |
print Dumper($host_info, $bpc->HostInfoRead( 'localhost' )); |
#print Dumper($host_info, $bpc->HostInfoRead( 'localhost' )); |
54 |
die "host '$host' is not found, please add it to config/hosts configuration file\n" unless ($host_info->{$host}); |
die "host '$host' is not found, please add it to config/hosts configuration file\n" unless ($host_info->{$host}); |
55 |
|
|
56 |
# create restore host configuration |
# take care of temporary directory for increments |
57 |
|
|
58 |
|
my $inc_tmp_dir = $Conf{IncrementTempDir} || die "need working directory in IncrementTempDir\n"; |
59 |
|
rmtree($inc_tmp_dir) if (-e $inc_tmp_dir); |
60 |
|
|
61 |
|
mkpath($inc_tmp_dir); |
62 |
|
|
63 |
my $restore_path = "$Conf{InstallDir}/$Conf{GzipTempDir}/${host}-restore.tar.gz"; |
print "# using $inc_tmp_dir for increment scratch space"; |
64 |
|
|
65 |
|
# create restore host configuration |
66 |
|
|
67 |
my $conf_restore = <<'_END_OF_CONF_'; |
my $conf_restore = <<'_END_OF_CONF_'; |
68 |
|
|
69 |
$Conf{XferMethod} = 'tar'; |
$Conf{XferMethod} = 'tar'; |
70 |
|
$Conf{TarShareName} = '__share__'; |
71 |
|
|
72 |
$Conf{TarFullArgs} = 'echo "full backups are not supported in restore!" ; exit 1'; |
# disable ping |
73 |
$Conf{TarIncrArgs} = ''; |
$Conf{PingCmd} = ''; |
74 |
|
# work-around for Backup aborted because of CorrectHostCheck |
75 |
# fake ping when restoring |
$Conf{FixedIPNetBiosNameCheck} = 0; |
76 |
$Conf{PingCmd} = '$pingPath -c 1 localhost', |
$Conf{NmbLookupCmd} = ''; |
77 |
$Conf{ClientNameAlias} = 'localhost'; |
$Conf{ClientNameAlias} = 'localhost'; |
78 |
|
|
79 |
$Conf{TarClientCmd} = 'zcat __restore_path__'; |
#$Conf{TarIncrArgs} = ''; |
80 |
|
#$Conf{ClientTimeout} = 600; |
81 |
|
#$Conf{TarClientCmd} = ''; |
82 |
|
#$Conf{TarFullArgs} = 'gzip -cdv __restore_path__'; |
83 |
|
|
84 |
|
$Conf{TarClientCmd} = '$tarPath -c -v -f - -C __inc_tmp_dir__ --totals'; |
85 |
|
|
86 |
1; |
1; |
87 |
|
|
88 |
_END_OF_CONF_ |
_END_OF_CONF_ |
89 |
|
|
90 |
$conf_restore =~ s/__restore_path__/$restore_path/gs; |
$conf_restore =~ s/__share__/$share/gs; |
91 |
|
$conf_restore =~ s/__inc_tmp_dir__/$inc_tmp_dir/gs; |
92 |
|
|
93 |
my $config_file = "$bpc->{TopDir}/conf/${host}.pl"; |
my $config_file = "$bpc->{TopDir}/conf/${host}.pl"; |
94 |
|
|
102 |
my $path = shift || die "need path!"; |
my $path = shift || die "need path!"; |
103 |
|
|
104 |
if ($path !~ m/\.tar\.gz$/i) { |
if ($path !~ m/\.tar\.gz$/i) { |
105 |
print "skipping $path, not .tar.gz increment\n"; |
print "# skipping $path, not .tar.gz increment\n"; |
106 |
return; |
return; |
107 |
} |
} |
108 |
|
|
109 |
print "working on $path\n"; |
print "restoring $path\n"; |
110 |
|
|
111 |
if (-e $restore_path) { |
my $cmd = "cd $inc_tmp_dir && tar xvfz $path"; |
112 |
unlink $restore_path || die "can't remove $restore_path: $!\n"; |
system($cmd) == 0 or die "can't execute: $cmd -- $?\n"; |
113 |
} |
|
114 |
symlink $path, $restore_path || die "can't create link $path -> $restore_path: $!\n"; |
print "starting import into BackupPC pool\n"; |
115 |
|
|
116 |
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"; |
117 |
|
|
118 |
$bpc->ServerMesg("log User $user started recovery from increment $path"); |
$bpc->ServerMesg("log User $user started recovery from increment $path"); |
119 |
|
|
120 |
my $full = 0; |
my @backups = $bpc->BackupInfoRead( $host ); |
121 |
|
|
122 |
|
my $full = 1; |
123 |
|
foreach my $b (@backups) { |
124 |
|
$full = 0 if ($b->{type} eq 'full'); |
125 |
|
} |
126 |
|
|
127 |
my $r = $bpc->ServerMesg("backup $host $host $user $full"); |
my $r = $bpc->ServerMesg("backup $host $host $user $full"); |
128 |
print "backup --> $r"; |
print "backup ", $full ? 'full' : 'incremental', " --> $r"; |
129 |
die $r if ($r =~ m/^error/); |
die $r if ($r =~ m/^error/); |
130 |
|
|
131 |
# Status_backup_in_progress |
# Status_backup_in_progress |