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 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 2.1.0, released 20 Jun 2004.
33 # See http://backuppc.sourceforge.net.
35 #========================================================================
37 package BackupPC::CGI::Archive;
40 use BackupPC::CGI::Lib qw(:all);
45 my $archHost = $In{host};
46 my $Privileged = CheckPermission();
49 ErrorExit($Lang->{Only_privileged_users_can_archive} );
51 if ( $In{type} == 0 ) {
52 my($fullTot, $fullSizeTot, $incrTot, $incrSizeTot, $str,
53 $strNone, $strGood, $hostCntGood, $hostCntNone, $checkBoxCnt,
56 $hostCntGood = $hostCntNone = $checkBoxCnt = $fullSizeTot = 0;
57 GetStatusInfo("hosts");
59 foreach my $host ( sort(keys(%Status)) ) {
60 my($fullDur, $incrCnt, $fullSize, $fullRate);
61 my @Backups = $bpc->BackupInfoRead($host);
62 my $fullCnt = $incrCnt = 0;
63 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
64 if ( $Backups[$i]{type} eq "full" ) {
65 $fullSize = $Backups[$i]{size} / (1024 * 1024);
68 $incrSizeTot = $Backups[$i]{size} / (1024 * 1024);
70 $backupnumber = $Backups[$i]{num};
72 $fullSizeTot += $fullSize + $incrSizeTot;
73 $fullSize = sprintf("%.2f", ($fullSize + $incrSizeTot) / 1000);
76 <td class="border"><input type="hidden" name="backup$checkBoxCnt" value="$backupnumber"><input type="checkbox" name="fcb$checkBoxCnt" value="$host"> ${HostLink($host)} </td>
77 <td align="center" class="border"> ${UserLink($Hosts->{$host}{user})} </td>
78 <td align="center" class="border"> $fullSize </td>
81 if ( @Backups == 0 ) {
89 $fullSizeTot = sprintf("%.2f", $fullSizeTot / 1000);
90 my $now = timeStamp2(time);
91 my $checkAllHosts = $Lang->{checkAllHosts};
93 <input type="hidden" name="archivehost" value="$In{'archivehost'}">
95 my $content = eval("qq{$Lang->{BackupPC_Archive}}");
96 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);
99 my(@HostList, @BackupList, $HostListStr, $hiddenStr, $pathHdr,
100 $badFileCnt, $reply, $str);
103 # Pick up the archive host's config file
105 $bpc->ConfigRead($archHost);
106 %Conf = $bpc->Conf();
109 SplitPath => $Conf{SplitPath},
110 ParPath => $Conf{ParPath},
111 CatPath => $Conf{CatPath},
112 GzipPath => $Conf{GzipPath},
113 Bzip2Path => $Conf{Bzip2Path},
114 ArchiveDest => $Conf{ArchiveDest},
115 ArchiveComp => $Conf{ArchiveComp},
116 ArchivePar => $Conf{ArchivePar},
117 ArchiveSplit => $Conf{ArchiveSplit},
118 topDir => $bpc->{TopDir},
123 for ( my $i = 0 ; $i < $In{fcbMax} ; $i++ ) {
124 next if ( !defined($In{"fcb$i"}) );
125 my $name = $In{"fcb$i"};
126 my $backupno = $In{"backup$i"};
127 push(@HostList, $name);
128 push(@BackupList, $backupno);
130 <input type="hidden" name="fcb$i" value="$In{'fcb' . $i}">
131 <input type="hidden" name="backup$i" value="$In{'backup' . $i}">
133 $HostListStr .= <<EOF;
134 <li> ${EscHTML($name)}
138 <input type="hidden" name="archivehost" value="$In{'archivehost'}">
140 $hiddenStr .= "<input type=\"hidden\" name=\"fcbMax\" value=\"$In{fcbMax}\">\n";
141 if ( @HostList == 0 ) {
142 ErrorExit($Lang->{You_haven_t_selected_any_hosts});
144 my ($ArchiveDest, $ArchiveCompNone, $ArchiveCompGzip,
145 $ArchiveCompBzip2, $ArchivePar, $ArchiveSplit);
146 $ArchiveDest = $Conf{ArchiveDest};
147 if ( $Conf{ArchiveComp} eq "none" ) {
148 $ArchiveCompNone = "checked";
150 $ArchiveCompNone = "";
152 if ( $Conf{ArchiveComp} eq "gzip" ) {
153 $ArchiveCompGzip = "checked";
155 $ArchiveCompGzip = "";
157 if ( $Conf{ArchiveComp} eq "bzip2" ) {
158 $ArchiveCompBzip2 = "checked";
160 $ArchiveCompBzip2 = "";
162 $ArchivePar = $Conf{ArchivePar};
163 $ArchiveSplit = $Conf{ArchiveSplit};
165 if ( $In{type} == 1 ) {
167 # Tell the user what options they have
170 if ( $Conf{ArchiveClientCmd} =~ /\$archiveloc\b/ ) {
171 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_location}}");
173 if ( $Conf{ArchiveClientCmd} =~ /\$compression\b/ ) {
174 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_compression}}");
176 if ( $Conf{ArchiveClientCmd} =~ /\$parfile\b/
177 && -x $Conf{ParPath} ) {
178 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_parity}}");
180 if ( $Conf{ArchiveClientCmd} =~ /\$splitsize\b/
181 && -x $Conf{SplitPath} ) {
182 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_split}}");
184 my $content = eval("qq{$Lang->{BackupPC_Archive2}}");
185 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);
187 } elsif ( $In{type} == 2 ) {
189 my $archivehost = $1 if ( $In{archivehost} =~ /(.+)/ );
190 for ( my $i = 0 ; ; $i++ ) {
191 $reqFileName = "archiveReq.$$.$i";
192 last if ( !-f "$TopDir/pc/$archivehost/$reqFileName" );
194 my($compname, $compext);
195 if ( $In{compression} == 2 ) { # bzip2 compression
196 $compname = $Conf{Bzip2Path};
198 } elsif ( $In{compression} == 1 ) { # gzip compression
199 $compname = $Conf{GzipPath};
201 } else { # No Compression
202 $compname = $Conf{CatPath};
205 my $fullsplitsize = $In{splitsize} . '000000';
207 # parameters for the archive
208 archiveloc => $In{archive_device},
209 archtype => $In{archive_type},
210 compression => $compname,
213 splitsize => $fullsplitsize,
214 host => $archivehost,
216 # list of hosts to restore
217 HostList => \@HostList,
218 BackupList => \@BackupList,
224 my($archive) = Data::Dumper->new(
228 if ( open(REQ, ">$TopDir/pc/$archivehost/$reqFileName") ) {
230 print(REQ $archive->Dump);
233 ErrorExit($Lang->{Can_t_open_create} );
235 $reply = $bpc->ServerMesg("archive $User $archivehost $reqFileName");
236 $str = eval("qq{$Lang->{Archive_requested}}");
238 my $content = eval("qq{$Lang->{BackupPC_Archive_Reply_from_server}}");
239 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);