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;
41 use base qw(BackupPC::Xfer::Protocol);
45 my($class, $bpc, $args) = @_;
50 conf => { $bpc->Conf },
79 my $conf = $t->{conf};
80 my(@fileList, $bpcdCmd, $bpcdArgs, $logMsg, $incrDate,
81 $incrFlag, $restoreDir);
84 # We add a slash to the share name we pass to bpcd
86 ($t->{shareNameSlash} = "$t->{shareName}/") =~ s{//+$}{/};
88 if ( $t->{type} eq "restore" ) {
89 $bpcdCmd = $conf->{BackupPCdRestoreCmd};
90 $restoreDir = "$t->{shareName}/$t->{pathHdrDest}";
91 $restoreDir =~ s{//+}{/}g;
92 $logMsg = "restore started below directory $t->{shareName}"
93 . " to host $t->{host}";
95 if ( $t->{type} eq "full" ) {
96 if ( $t->{partialNum} ) {
97 $logMsg = "full backup started for directory $t->{shareName};"
98 . " updating partial $t->{partialNum}";
100 $logMsg = "full backup started for directory $t->{shareName}";
105 # TODO: fix this message - just refer to the backup, not time?
107 $incrDate = $bpc->timeStamp($t->{incrBaseTime} - 3600, 1);
108 $logMsg = "incr backup started back to $incrDate"
109 . " (backup #$t->{incrBaseBkupNum}) for directory"
110 . " $t->{shareName}";
113 $bpcdCmd = $conf->{BackupPCdCmd};
117 # Merge variables into $bpcdCmd
121 hostIP => $t->{hostIP},
122 client => $t->{client},
123 shareName => $t->{shareName},
124 shareNameSlash => $t->{shareNameSlash},
125 restoreDir => $restoreDir,
126 bpcdPath => $conf->{BackupPCdPath},
127 sshPath => $conf->{SshPath},
128 topDir => $bpc->TopDir(),
129 poolDir => $t->{compress} ? $bpc->{CPoolDir} : $bpc->{PoolDir},
130 poolCompress => $t->{compress} + 0,
131 incrFlag => $incrFlag,
133 $bpcdCmd = $bpc->cmdVarSubstitute($bpcdCmd, $args);
135 $t->{bpcdCmd} = $bpcdCmd;
137 delete($t->{_errStr});
146 my $conf = $t->{conf};
147 my($remoteSend, $remoteDir, $remoteDirDaemon);
151 # NO: alarm($conf->{ClientTimeout});
154 # Run backupcd command
156 my $str = "Running: "
157 . $t->{bpc}->execCmd2ShellCmd(@{$t->{bpcdCmd}})
159 $t->{XferLOG}->write(\$str);
165 $bpc->cmdSystemOrEvalLong($t->{bpcdCmd},
167 # write stdout to the XferLOG
169 $t->{XferLOG}->write(\$str);
171 0, # also catch stderr
176 # TODO: generate sensible stats by parsing the output of
177 # backuppcd. Get error and fail status.
179 if ( !defined($error) && defined($stats) ) {
184 $t->{xferErrCnt} = $stats->{errorCnt};
185 $t->{byteCnt} = $stats->{TotalFileSize};
186 $t->{fileCnt} = $stats->{TotalFileCnt};
187 my $str = "Done: $t->{fileCnt} files, $t->{byteCnt} bytes\n";
188 $t->{XferLOG}->write(\$str);
190 $t->{hostError} = $error if ( defined($error) );
192 if ( $t->{type} eq "restore" ) {
202 $stats->{ExistFileCnt},
203 $stats->{ExistFileSize},
204 $stats->{ExistFileCompSize},
205 $stats->{TotalFileCnt},
206 $stats->{TotalFileSize}