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 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
65 if ( $Backups[$i]{type} eq "full" ) {
66 $fullSize = $Backups[$i]{size} / (1024 * 1024);
69 $incrSizeTot = $Backups[$i]{size} / (1024 * 1024);
71 $backupnumber = $Backups[$i]{num};
73 $fullSizeTot += $fullSize + $incrSizeTot;
74 $fullSize = sprintf("%.2f", ($fullSize + $incrSizeTot) / 1000);
76 $bpc->ConfigRead($archHost);
79 my $dbh = DBI->connect($Conf{SearchDSN}, $Conf{SearchUser}, "", { RaiseError => 1, AutoCommit => 0 });
80 my $backup_nums = $dbh->selectcol_arrayref(qq{
84 join hosts on hosts.id = hostid
85 where hosts.name = ? and inc_size < 0 and size > 0 and not inc_deleted
89 foreach my $backupnumber ( sort @$backup_nums ) {
91 <input type="hidden" name="fcb$checkBoxCnt" value="$host">
92 <input type="checkbox" name="backup$checkBoxCnt" value="$backupnumber">$backupnumber
97 =for ASA extension removed this
100 <td class="border"><input type="hidden" name="backup$checkBoxCnt" value="$backupnumber"><input type="checkbox" name="fcb$checkBoxCnt" value="$host"> ${HostLink($host)} </td>
101 <td align="center" class="border"> ${UserLink($Hosts->{$host}{user})} </td>
102 <td align="center" class="border"> $fullSize </td>
113 <td align="center" class="border">
114 ${UserLink($Hosts->{$host}{user})}
116 <td align="center" class="border"> $fullSize </td>
119 if ( @Backups == 0 ) {
127 $fullSizeTot = sprintf("%.2f", $fullSizeTot / 1000);
128 my $now = timeStamp2(time);
129 my $checkAllHosts = $Lang->{checkAllHosts};
131 <input type="hidden" name="archivehost" value="$In{'archivehost'}">
133 my $content = eval("qq{$Lang->{BackupPC_Archive}}");
134 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);
137 my(@HostList, @BackupList, $HostListStr, $hiddenStr, $pathHdr,
138 $badFileCnt, $reply, $str);
141 # Pick up the archive host's config file
143 $bpc->ConfigRead($archHost);
144 %Conf = $bpc->Conf();
147 SplitPath => $Conf{SplitPath},
148 ParPath => $Conf{ParPath},
149 CatPath => $Conf{CatPath},
150 GzipPath => $Conf{GzipPath},
151 Bzip2Path => $Conf{Bzip2Path},
152 ArchiveDest => $Conf{ArchiveDest},
153 ArchiveComp => $Conf{ArchiveComp},
154 ArchivePar => $Conf{ArchivePar},
155 ArchiveSplit => $Conf{ArchiveSplit},
156 topDir => $bpc->{TopDir},
161 for ( my $i = 0 ; $i < $In{fcbMax} ; $i++ ) {
162 next if ( !defined($In{"fcb$i"}) );
163 my $name = $In{"fcb$i"};
164 my $backupno = $In{"backup$i"};
165 push(@HostList, $name);
166 push(@BackupList, $backupno);
168 <input type="hidden" name="fcb$i" value="$In{'fcb' . $i}">
169 <input type="hidden" name="backup$i" value="$In{'backup' . $i}">
171 $HostListStr .= <<EOF;
172 <li> ${EscHTML($name)} $i
176 <input type="hidden" name="archivehost" value="$In{'archivehost'}">
178 $hiddenStr .= "<input type=\"hidden\" name=\"fcbMax\" value=\"$In{fcbMax}\">\n";
179 if ( @HostList == 0 ) {
180 ErrorExit($Lang->{You_haven_t_selected_any_hosts});
182 my ($ArchiveDest, $ArchiveCompNone, $ArchiveCompGzip,
183 $ArchiveCompBzip2, $ArchivePar, $ArchiveSplit);
184 $ArchiveDest = $Conf{ArchiveDest};
185 if ( $Conf{ArchiveComp} eq "none" ) {
186 $ArchiveCompNone = "checked";
188 $ArchiveCompNone = "";
190 if ( $Conf{ArchiveComp} eq "gzip" ) {
191 $ArchiveCompGzip = "checked";
193 $ArchiveCompGzip = "";
195 if ( $Conf{ArchiveComp} eq "bzip2" ) {
196 $ArchiveCompBzip2 = "checked";
198 $ArchiveCompBzip2 = "";
200 $ArchivePar = $Conf{ArchivePar};
201 $ArchiveSplit = $Conf{ArchiveSplit};
203 if ( $In{type} == 1 ) {
205 # Tell the user what options they have
208 if ( $Conf{ArchiveClientCmd} =~ /\$archiveloc\b/ ) {
209 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_location}}");
211 if ( $Conf{ArchiveClientCmd} =~ /\$compression\b/ ) {
212 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_compression}}");
214 if ( $Conf{ArchiveClientCmd} =~ /\$parfile\b/
215 && -x $Conf{ParPath} ) {
216 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_parity}}");
218 if ( $Conf{ArchiveClientCmd} =~ /\$splitsize\b/
219 && -x $Conf{SplitPath} ) {
220 $paramStr .= eval("qq{$Lang->{BackupPC_Archive2_split}}");
222 my $content = eval("qq{$Lang->{BackupPC_Archive2}}");
223 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);
225 } elsif ( $In{type} == 2 ) {
227 my $archivehost = $1 if ( $In{archivehost} =~ /(.+)/ );
228 for ( my $i = 0 ; ; $i++ ) {
229 $reqFileName = "archiveReq.$$.$i";
230 last if ( !-f "$TopDir/pc/$archivehost/$reqFileName" );
232 my($compname, $compext);
233 if ( $In{compression} == 2 ) { # bzip2 compression
234 $compname = $Conf{Bzip2Path};
236 } elsif ( $In{compression} == 1 ) { # gzip compression
237 $compname = $Conf{GzipPath};
239 } else { # No Compression
240 $compname = $Conf{CatPath};
243 my $fullsplitsize = $In{splitsize} . '000000';
245 # parameters for the archive
246 archiveloc => $In{archive_device},
247 archtype => $In{archive_type},
248 compression => $compname,
251 splitsize => $fullsplitsize,
252 host => $archivehost,
254 # list of hosts to restore
255 HostList => \@HostList,
256 BackupList => \@BackupList,
262 my($archive) = Data::Dumper->new(
266 my $openPath = "$TopDir/pc/$archivehost/$reqFileName";
267 if ( open(REQ, ">", $openPath) ) {
269 print(REQ $archive->Dump);
272 ErrorExit(eval("qq{$Lang->{Can_t_open_create__openPath}}"));
274 $reply = $bpc->ServerMesg("archive $User $archivehost $reqFileName");
275 $str = eval("qq{$Lang->{Archive_requested}}");
277 my $content = eval("qq{$Lang->{BackupPC_Archive_Reply_from_server}}");
278 Header(eval("qq{$Lang->{BackupPC__Archive}}"), $content, 1);