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;
65 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
66 if ( $Backups[$i]{type} eq "full" ) {
67 $fullSize = $Backups[$i]{size} / (1024 * 1024);
70 $incrSizeTot = $Backups[$i]{size} / (1024 * 1024);
72 $backupnumber = $Backups[$i]{num};
74 $fullSizeTot += $fullSize + $incrSizeTot;
75 $fullSize = sprintf("%.2f", ($fullSize + $incrSizeTot) / 1000);
77 $bpc->ConfigRead($archHost);
81 foreach my $backupnumber ( BackupPC::Search::host_backup_nums($host) ) {
83 <input type="hidden" name="fcb$checkBoxCnt" value="$host">
84 <input type="checkbox" name="backup$checkBoxCnt" value="$backupnumber">$backupnumber
89 =for ASA extension removed this
92 <td class="border"><input type="hidden" name="backup$checkBoxCnt" value="$backupnumber"><input type="checkbox" name="fcb$checkBoxCnt" value="$host"> ${HostLink($host)} </td>
93 <td align="center" class="border"> ${UserLink($Hosts->{$host}{user})} </td>
94 <td align="center" class="border"> $fullSize </td>
105 <td align="center" class="border">
106 ${UserLink($Hosts->{$host}{user})}
108 <td align="center" class="border"> $fullSize </td>
111 if ( @Backups == 0 ) {
119 $fullSizeTot = sprintf("%.2f", $fullSizeTot / 1000);
120 my $now = timeStamp2(time);
121 my $checkAllHosts = $Lang->{checkAllHosts};
123 <input type="hidden" name="archivehost" value="$In{'archivehost'}">
125 my $content = eval("qq{$Lang->{BackupPC_Archive}}");
126 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);
129 my(@HostList, @BackupList, $HostListStr, $hiddenStr, $pathHdr,
130 $badFileCnt, $reply, $str);
133 # Pick up the archive host's config file
135 $bpc->ConfigRead($archHost);
136 %Conf = $bpc->Conf();
139 SplitPath => $Conf{SplitPath},
140 ParPath => $Conf{ParPath},
141 CatPath => $Conf{CatPath},
142 GzipPath => $Conf{GzipPath},
143 Bzip2Path => $Conf{Bzip2Path},
144 ArchiveDest => $Conf{ArchiveDest},
145 ArchiveComp => $Conf{ArchiveComp},
146 ArchivePar => $Conf{ArchivePar},
147 ArchiveSplit => $Conf{ArchiveSplit},
148 topDir => $bpc->{TopDir},
153 for ( my $i = 0 ; $i < $In{fcbMax} ; $i++ ) {
154 next if ( !defined($In{"fcb$i"}) );
155 my $name = $In{"fcb$i"};
156 my $backupno = $In{"backup$i"};
157 next unless defined $backupno; # ASA - skip hosts without backups checked
158 push(@HostList, $name);
159 push(@BackupList, $backupno);
161 <input type="hidden" name="fcb$i" value="$In{'fcb' . $i}">
162 <input type="hidden" name="backup$i" value="$In{'backup' . $i}">
164 $HostListStr .= <<EOF;
165 <li> ${EscHTML($name)} $i
169 <input type="hidden" name="archivehost" value="$In{'archivehost'}">
171 $hiddenStr .= "<input type=\"hidden\" name=\"fcbMax\" value=\"$In{fcbMax}\">\n";
172 if ( @HostList == 0 ) {
173 ErrorExit($Lang->{You_haven_t_selected_any_hosts});
175 my ($ArchiveDest, $ArchiveCompNone, $ArchiveCompGzip,
176 $ArchiveCompBzip2, $ArchivePar, $ArchiveSplit);
177 $ArchiveDest = $Conf{ArchiveDest};
178 if ( $Conf{ArchiveComp} eq "none" ) {
179 $ArchiveCompNone = "checked";
181 $ArchiveCompNone = "";
183 if ( $Conf{ArchiveComp} eq "gzip" ) {
184 $ArchiveCompGzip = "checked";
186 $ArchiveCompGzip = "";
188 if ( $Conf{ArchiveComp} eq "bzip2" ) {
189 $ArchiveCompBzip2 = "checked";
191 $ArchiveCompBzip2 = "";
193 $ArchivePar = $Conf{ArchivePar};
194 $ArchiveSplit = $Conf{ArchiveSplit};
196 if ( $In{type} == 1 ) {
198 # Tell the user what options they have
201 if ( $Conf{ArchiveClientCmd} =~ /\$archiveloc\b/ ) {
202 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_location}}");
204 if ( $Conf{ArchiveClientCmd} =~ /\$compression\b/ ) {
205 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_compression}}");
207 if ( $Conf{ArchiveClientCmd} =~ /\$parfile\b/
208 && -x $Conf{ParPath} ) {
209 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_parity}}");
211 if ( $Conf{ArchiveClientCmd} =~ /\$splitsize\b/
212 && -x $Conf{SplitPath} ) {
213 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_split}}");
215 my $content = eval("qq{$Lang->{BackupPC_Archive2}}");
216 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);
218 } elsif ( $In{type} == 2 ) {
220 my $archivehost = $1 if ( $In{archivehost} =~ /(.+)/ );
221 for ( my $i = 0 ; ; $i++ ) {
222 $reqFileName = "archiveReq.$$.$i";
223 last if ( !-f "$TopDir/pc/$archivehost/$reqFileName" );
225 my($compname, $compext);
226 if ( $In{compression} == 2 ) { # bzip2 compression
227 $compname = $Conf{Bzip2Path};
229 } elsif ( $In{compression} == 1 ) { # gzip compression
230 $compname = $Conf{GzipPath};
232 } else { # No Compression
233 $compname = $Conf{CatPath};
236 my $fullsplitsize = $In{splitsize} . '000000'; # mb -> bytes
238 # parameters for the archive
239 archiveloc => $In{archive_device},
240 archtype => $In{archive_type},
241 compression => $compname,
244 splitsize => $fullsplitsize,
245 host => $archivehost,
247 # list of hosts to restore
248 HostList => \@HostList,
249 BackupList => \@BackupList,
255 my($archive) = Data::Dumper->new(
259 my $openPath = "$TopDir/pc/$archivehost/$reqFileName";
260 if ( open(REQ, ">", $openPath) ) {
262 print(REQ $archive->Dump);
265 ErrorExit(eval("qq{$Lang->{Can_t_open_create__openPath}}"));
267 $reply = $bpc->ServerMesg("archive $User $archivehost $reqFileName");
268 $str = eval("qq{$Lang->{Archive_requested}}");
270 my $content = eval("qq{$Lang->{BackupPC_Archive_Reply_from_server}}");
271 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);