1 #============================================================= -*-perl-*-
3 # BackupPC::Xfer::BackupPCd package
7 # This library defines a BackupPC::Xfer::BackupPCd class for managing
8 # the backuppcd-based transport of backup data from the client.
11 # Craig Barratt <cbarratt@users.sourceforge.net>
14 # Copyright (C) 2006-2007 Craig Barratt
16 # This program is free software; you can redistribute it and/or modify
17 # it under the terms of the GNU General Public License as published by
18 # the Free Software Foundation; either version 2 of the License, or
19 # (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #========================================================================
32 # Version 3.1.0, released 25 Nov 2007.
34 # See http://backuppc.sourceforge.net.
36 #========================================================================
38 package BackupPC::Xfer::BackupPCd;
44 my($class, $bpc, $args) = @_;
49 conf => { $bpc->Conf },
78 foreach my $arg ( keys(%$args) ) {
79 $t->{$arg} = $args->{$arg};
92 my $conf = $t->{conf};
93 my(@fileList, $bpcdCmd, $bpcdArgs, $logMsg, $incrDate,
94 $incrFlag, $restoreDir);
97 # We add a slash to the share name we pass to bpcd
99 ($t->{shareNameSlash} = "$t->{shareName}/") =~ s{//+$}{/};
101 if ( $t->{type} eq "restore" ) {
102 $bpcdCmd = $conf->{BackupPCdRestoreCmd};
103 $restoreDir = "$t->{shareName}/$t->{pathHdrDest}";
104 $restoreDir =~ s{//+}{/}g;
105 $logMsg = "restore started below directory $t->{shareName}"
106 . " to host $t->{host}";
108 if ( $t->{type} eq "full" ) {
109 if ( $t->{partialNum} ) {
110 $logMsg = "full backup started for directory $t->{shareName};"
111 . " updating partial $t->{partialNum}";
113 $logMsg = "full backup started for directory $t->{shareName}";
118 # TODO: fix this message - just refer to the backup, not time?
120 $incrDate = $bpc->timeStamp($t->{incrBaseTime} - 3600, 1);
121 $logMsg = "incr backup started back to $incrDate"
122 . " (backup #$t->{incrBaseBkupNum}) for directory"
123 . " $t->{shareName}";
126 $bpcdCmd = $conf->{BackupPCdCmd};
130 # Merge variables into $bpcdCmd
134 hostIP => $t->{hostIP},
135 client => $t->{client},
136 shareName => $t->{shareName},
137 shareNameSlash => $t->{shareNameSlash},
138 restoreDir => $restoreDir,
139 bpcdPath => $conf->{BackupPCdPath},
140 sshPath => $conf->{SshPath},
141 topDir => $bpc->TopDir(),
142 poolDir => $t->{compress} ? $bpc->{CPoolDir} : $bpc->{PoolDir},
143 poolCompress => $t->{compress} + 0,
144 incrFlag => $incrFlag,
146 $bpcdCmd = $bpc->cmdVarSubstitute($bpcdCmd, $args);
148 $t->{bpcdCmd} = $bpcdCmd;
150 delete($t->{_errStr});
159 my $conf = $t->{conf};
160 my($remoteSend, $remoteDir, $remoteDirDaemon);
164 # NO: alarm($conf->{ClientTimeout});
167 # Run backupcd command
169 my $str = "Running: "
170 . $t->{bpc}->execCmd2ShellCmd(@{$t->{bpcdCmd}})
172 $t->{XferLOG}->write(\$str);
178 $bpc->cmdSystemOrEvalLong($t->{bpcdCmd},
180 # write stdout to the XferLOG
182 $t->{XferLOG}->write(\$str);
184 0, # also catch stderr
189 # TODO: generate sensible stats by parsing the output of
190 # backuppcd. Get error and fail status.
192 if ( !defined($error) && defined($stats) ) {
197 $t->{xferErrCnt} = $stats->{errorCnt};
198 $t->{byteCnt} = $stats->{TotalFileSize};
199 $t->{fileCnt} = $stats->{TotalFileCnt};
200 my $str = "Done: $t->{fileCnt} files, $t->{byteCnt} bytes\n";
201 $t->{XferLOG}->write(\$str);
203 $t->{hostError} = $error if ( defined($error) );
205 if ( $t->{type} eq "restore" ) {
215 $stats->{ExistFileCnt},
216 $stats->{ExistFileSize},
217 $stats->{ExistFileCompSize},
218 $stats->{TotalFileCnt},
219 $stats->{TotalFileSize}
226 my($t, $reason) = @_;
236 return $t->{_errStr};
247 # Returns a hash ref giving various status information about
254 return { map { $_ => $t->{$_} }
255 qw(byteCnt fileCnt xferErrCnt xferBadShareCnt xferBadFileCnt
256 xferOK hostAbort hostError lastOutputLine)
264 return @{$t->{badFiles}};