1 #============================================================= -*-perl-*-
3 # BackupPC::CGI::Archive package
7 # This module implements the Archive action for the CGI interface.
10 # Craig Barratt <cbarratt@users.sourceforge.net>
13 # Copyright (C) 2003-2009 Craig Barratt
15 # This program is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #========================================================================
31 # Version 3.2.0, released 31 Jul 2010.
33 # See http://backuppc.sourceforge.net.
35 #========================================================================
37 package BackupPC::CGI::Archive;
40 use BackupPC::CGI::Lib qw(:all);
46 my $archHost = $In{host};
47 my $Privileged = CheckPermission();
50 ErrorExit($Lang->{Only_privileged_users_can_archive} );
52 if ( $In{type} == 0 ) {
53 my($fullTot, $fullSizeTot, $incrTot, $incrSizeTot, $str,
54 $strNone, $strGood, $hostCntGood, $hostCntNone, $checkBoxCnt,
57 $hostCntGood = $hostCntNone = $checkBoxCnt = $fullSizeTot = 0;
58 GetStatusInfo("hosts");
60 foreach my $host ( sort(keys(%Status)) ) {
61 my($fullDur, $incrCnt, $fullSize, $fullRate);
62 my @Backups = $bpc->BackupInfoRead($host);
63 my $fullCnt = $incrCnt = 0;
64 my $all_backup_numbers;
66 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
67 if ( $Backups[$i]{type} eq "full" ) {
68 $fullSize = $Backups[$i]{size} / (1024 * 1024);
71 $incrSizeTot = $Backups[$i]{size} / (1024 * 1024);
73 $backupnumber = $Backups[$i]{num};
74 $all_backup_numbers->{$backupnumber}++;
76 $fullSizeTot += $fullSize + $incrSizeTot;
77 $fullSize = sprintf("%.2f", ($fullSize + $incrSizeTot) / 1000);
79 $bpc->ConfigRead($archHost);
82 use Data::Dump qw(dump);
84 my $dbh = DBI->connect($Conf{SearchDSN}, $Conf{SearchUser}, "", { RaiseError => 1, AutoCommit => 0 });
85 my $sth = $dbh->prepare(qq{
92 join hosts on hosts.id = hostid
96 # and inc_size < 0 and size > 0 and not inc_deleted
97 while( my $row = $sth->fetchrow_hashref ) {
98 warn "# row ",dump $row;
99 $all_backup_numbers->{ $row->{num} } =
100 $row->{inc_deleted} ? 0 :
101 $row->{size} == 0 ? 0 :
102 $row->{inc_size} < 0 ? 1 :
103 $row->{size} > 0 ? 1 :
107 warn dump($all_backup_numbers);
110 grep { $all_backup_numbers->{$_} }
111 keys %$all_backup_numbers;
114 foreach my $backupnumber ( @backup_nums ) {
116 <input type="hidden" name="fcb$checkBoxCnt" value="$host">
117 <input type="checkbox" name="backup$checkBoxCnt" value="$backupnumber">$backupnumber
122 =for ASA extension removed this
125 <td class="border"><input type="hidden" name="backup$checkBoxCnt" value="$backupnumber"><input type="checkbox" name="fcb$checkBoxCnt" value="$host"> ${HostLink($host)} </td>
126 <td align="center" class="border"> ${UserLink($Hosts->{$host}{user})} </td>
127 <td align="center" class="border"> $fullSize </td>
138 <td align="center" class="border">
139 ${UserLink($Hosts->{$host}{user})}
141 <td align="center" class="border"> $fullSize </td>
144 if ( @Backups == 0 ) {
152 $fullSizeTot = sprintf("%.2f", $fullSizeTot / 1000);
153 my $now = timeStamp2(time);
154 my $checkAllHosts = $Lang->{checkAllHosts};
156 <input type="hidden" name="archivehost" value="$In{'archivehost'}">
158 my $content = eval("qq{$Lang->{BackupPC_Archive}}");
159 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);
162 my(@HostList, @BackupList, $HostListStr, $hiddenStr, $pathHdr,
163 $badFileCnt, $reply, $str);
166 # Pick up the archive host's config file
168 $bpc->ConfigRead($archHost);
169 %Conf = $bpc->Conf();
172 SplitPath => $Conf{SplitPath},
173 ParPath => $Conf{ParPath},
174 CatPath => $Conf{CatPath},
175 GzipPath => $Conf{GzipPath},
176 Bzip2Path => $Conf{Bzip2Path},
177 ArchiveDest => $Conf{ArchiveDest},
178 ArchiveComp => $Conf{ArchiveComp},
179 ArchivePar => $Conf{ArchivePar},
180 ArchiveSplit => $Conf{ArchiveSplit},
181 topDir => $bpc->{TopDir},
186 for ( my $i = 0 ; $i < $In{fcbMax} ; $i++ ) {
187 next if ( !defined($In{"fcb$i"}) );
188 my $name = $In{"fcb$i"};
189 my $backupno = $In{"backup$i"};
190 next unless defined $backupno; # ASA - skip hosts without backups checked
191 push(@HostList, $name);
192 push(@BackupList, $backupno);
194 <input type="hidden" name="fcb$i" value="$In{'fcb' . $i}">
195 <input type="hidden" name="backup$i" value="$In{'backup' . $i}">
197 $HostListStr .= <<EOF;
198 <li> ${EscHTML($name)} $i
202 <input type="hidden" name="archivehost" value="$In{'archivehost'}">
204 $hiddenStr .= "<input type=\"hidden\" name=\"fcbMax\" value=\"$In{fcbMax}\">\n";
205 if ( @HostList == 0 ) {
206 ErrorExit($Lang->{You_haven_t_selected_any_hosts});
208 my ($ArchiveDest, $ArchiveCompNone, $ArchiveCompGzip,
209 $ArchiveCompBzip2, $ArchivePar, $ArchiveSplit);
210 $ArchiveDest = $Conf{ArchiveDest};
211 if ( $Conf{ArchiveComp} eq "none" ) {
212 $ArchiveCompNone = "checked";
214 $ArchiveCompNone = "";
216 if ( $Conf{ArchiveComp} eq "gzip" ) {
217 $ArchiveCompGzip = "checked";
219 $ArchiveCompGzip = "";
221 if ( $Conf{ArchiveComp} eq "bzip2" ) {
222 $ArchiveCompBzip2 = "checked";
224 $ArchiveCompBzip2 = "";
226 $ArchivePar = $Conf{ArchivePar};
227 $ArchiveSplit = $Conf{ArchiveSplit};
229 if ( $In{type} == 1 ) {
231 # Tell the user what options they have
234 if ( $Conf{ArchiveClientCmd} =~ /\$archiveloc\b/ ) {
235 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_location}}");
237 if ( $Conf{ArchiveClientCmd} =~ /\$compression\b/ ) {
238 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_compression}}");
240 if ( $Conf{ArchiveClientCmd} =~ /\$parfile\b/
241 && -x $Conf{ParPath} ) {
242 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_parity}}");
244 if ( $Conf{ArchiveClientCmd} =~ /\$splitsize\b/
245 && -x $Conf{SplitPath} ) {
246 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_split}}");
248 my $content = eval("qq{$Lang->{BackupPC_Archive2}}");
249 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);
251 } elsif ( $In{type} == 2 ) {
253 my $archivehost = $1 if ( $In{archivehost} =~ /(.+)/ );
254 for ( my $i = 0 ; ; $i++ ) {
255 $reqFileName = "archiveReq.$$.$i";
256 last if ( !-f "$TopDir/pc/$archivehost/$reqFileName" );
258 my($compname, $compext);
259 if ( $In{compression} == 2 ) { # bzip2 compression
260 $compname = $Conf{Bzip2Path};
262 } elsif ( $In{compression} == 1 ) { # gzip compression
263 $compname = $Conf{GzipPath};
265 } else { # No Compression
266 $compname = $Conf{CatPath};
269 my $fullsplitsize = $In{splitsize} . '000000';
271 # parameters for the archive
272 archiveloc => $In{archive_device},
273 archtype => $In{archive_type},
274 compression => $compname,
277 splitsize => $fullsplitsize,
278 host => $archivehost,
280 # list of hosts to restore
281 HostList => \@HostList,
282 BackupList => \@BackupList,
288 my($archive) = Data::Dumper->new(
292 my $openPath = "$TopDir/pc/$archivehost/$reqFileName";
293 if ( open(REQ, ">", $openPath) ) {
295 print(REQ $archive->Dump);
298 ErrorExit(eval("qq{$Lang->{Can_t_open_create__openPath}}"));
300 $reply = $bpc->ServerMesg("archive $User $archivehost $reqFileName");
301 $str = eval("qq{$Lang->{Archive_requested}}");
303 my $content = eval("qq{$Lang->{BackupPC_Archive_Reply_from_server}}");
304 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);