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_CVS, released 3 Jul 2003.
33 # See http://backuppc.sourceforge.net.
35 #========================================================================
37 package BackupPC::CGI::Archive;
40 use BackupPC::CGI::Lib qw(:all);
45 if ( $In{type} == 0 ) {
46 my($fullTot, $fullSizeTot, $incrTot, $incrSizeTot, $str,
47 $strNone, $strGood, $hostCntGood, $hostCntNone, $checkBoxCnt,
50 $hostCntGood = $hostCntNone = $checkBoxCnt = $fullSizeTot = 0;
51 GetStatusInfo("hosts");
52 my $Privileged = CheckPermission();
55 ErrorExit($Lang->{Only_privileged_users_can_archive} );
57 foreach my $host ( sort(keys(%Status)) ) {
58 my($fullDur, $incrCnt, $fullSize, $fullRate);
59 my @Backups = $bpc->BackupInfoRead($host);
60 my $fullCnt = $incrCnt = 0;
61 for ( my $i = 0 ; $i < @Backups ; $i++ ) {
62 if ( $Backups[$i]{type} eq "full" ) {
63 $fullSize = $Backups[$i]{size} / (1024 * 1024);
66 $incrSizeTot = $Backups[$i]{size} / (1024 * 1024);
68 $backupnumber = $Backups[$i]{num};
70 $fullSizeTot += $fullSize + $incrSizeTot;
71 $fullSize = sprintf("%.2f", ($fullSize + $incrSizeTot) / 1000);
73 <tr bgcolor="#ffffcc">
74 <td><input type="hidden" name="backup$checkBoxCnt" value="$backupnumber"><input type="checkbox" name="fcb$checkBoxCnt" value="$host"> ${HostLink($host)} </td>
75 <td align="center"> ${UserLink($Hosts->{$host}{user})} </td>
76 <td align="center"> $fullSize </td>
79 if ( @Backups == 0 ) {
87 $fullSizeTot = sprintf("%.2f", $fullSizeTot / 1000);
88 my $now = timeStamp2(time);
89 my $checkAllHosts = $Lang->{checkAllHosts};
91 <input type="hidden" name="archivehost" value="$In{'archivehost'}">
93 Header($Lang->{BackupPC__Archive});
94 print eval ("qq{$Lang->{BackupPC_Archive}}");
99 my(@HostList, @BackupList, $HostListStr, $hiddenStr, $pathHdr, $badFileCnt, $reply, $str);
101 my $Privileged = CheckPermission();
103 SplitPath => $bpc->{Conf}{SplitPath},
104 ParPath => $bpc->{Conf}{ParPath},
105 CatPath => $bpc->{Conf}{CatPath},
106 GzipPath => $bpc->{Conf}{GzipPath},
107 Bzip2Path => $bpc->{Conf}{Bzip2Path},
108 ArchiveDest => $bpc->{Conf}{ArchiveDest},
109 ArchiveComp => $bpc->{Conf}{ArchiveComp},
110 ArchivePar => $bpc->{Conf}{ArchivePar},
111 ArchiveSplit => $bpc->{Conf}{ArchiveSplit},
112 topDir => $bpc->{TopDir},
115 if ( !$Privileged ) {
116 ErrorExit($Lang->{Only_privileged_users_can_archive} );
120 for ( my $i = 0 ; $i < $In{fcbMax} ; $i++ ) {
121 next if ( !defined($In{"fcb$i"}) );
122 my $name = $In{"fcb$i"};
123 my $backupno = $In{"backup$i"};
124 push(@HostList, $name);
125 push(@BackupList, $backupno);
127 <input type="hidden" name="fcb$i" value="$In{'fcb' . $i}">
128 <input type="hidden" name="backup$i" value="$In{'backup' . $i}">
130 $HostListStr .= <<EOF;
131 <li> ${EscHTML($name)}
135 <input type="hidden" name="archivehost" value="$In{'archivehost'}">
137 $hiddenStr .= "<input type=\"hidden\" name=\"fcbMax\" value=\"$In{fcbMax}\">\n";
138 if ( @HostList == 0 ) {
139 ErrorExit($Lang->{You_haven_t_selected_any_hosts});
141 my ($ArchiveDest, $ArchiveCompNone, $ArchiveCompGzip, $ArchiveCompBzip2, $ArchivePar, $ArchiveSplit);
142 $ArchiveDest = $bpc->{Conf}{ArchiveDest};
143 if ( $bpc->{Conf}{ArchiveComp} eq "none" ) {
144 $ArchiveCompNone = "checked";
146 $ArchiveCompNone = "";
148 if ( $bpc->{Conf}{ArchiveComp} eq "gzip" ) {
149 $ArchiveCompGzip = "checked";
151 $ArchiveCompGzip = "";
153 if ( $bpc->{Conf}{ArchiveComp} eq "bzip2" ) {
154 $ArchiveCompBzip2 = "checked";
156 $ArchiveCompBzip2 = "";
158 $ArchivePar = $bpc->{Conf}{ArchivePar};
159 $ArchiveSplit = $bpc->{Conf}{ArchiveSplit};
161 if ( $In{type} == 1 ) {
163 # Tell the user what options they have
166 Header($Lang->{BackupPC__Archive});
167 print eval ("qq{$Lang->{BackupPC_Archive2}}");
169 } elsif ( $In{type} == 2 ) {
171 my $archivehost = $1 if ( $In{archivehost} =~ /(.+)/ );
172 for ( my $i = 0 ; ; $i++ ) {
173 $reqFileName = "archiveReq.$$.$i";
174 last if ( !-f "$TopDir/pc/$archivehost/$reqFileName" );
177 if ( $In{compression} == 2 ) { # bzip2 compression
178 $compname = $Conf{Bzip2Path};
179 } elsif ( $In{compression} == 1 ) { # gzip compression
180 $compname = $Conf{GzipPath};
181 } else { # No Compression
182 $compname = $Conf{CatPath};
185 if ( $In{compression} == 2 ) { # bzip2 compression
187 } elsif ( $In{compression} == 1 ) { # gzip compression
189 } else { # No Compression
192 my $fullsplitsize = $In{splitsize} . '000000';
194 # parameters for the archive
195 archiveloc => $In{archive_device},
196 archtype => $In{archive_type},
197 compression => $compname,
200 splitsize => $fullsplitsize,
201 host => $archivehost,
204 # list of hosts to restore
205 HostList => \@HostList,
206 BackupList => \@BackupList,
212 my($archive) = Data::Dumper->new(
216 if ( open(REQ, ">$TopDir/pc/$archivehost/$reqFileName") ) {
218 print(REQ $archive->Dump);
221 ErrorExit($Lang->{Can_t_open_create} );
223 $reply = $bpc->ServerMesg("archive $User $archivehost $reqFileName");
225 $str = eval("qq{$Lang->{Archive_requested}}");
226 Header($Lang->{BackupPC__Archive});
227 print eval ("qq{$Lang->{BackupPC_Archive_Reply_from_server}}");