1 #============================================================= -*-perl-*-
3 # BackupPC::Xfer package
7 # This library defines a Factory for invoking transfer protocols in
8 # a polymorphic manner. This libary allows for easier expansion of
12 # Paul Mantz <pcmantz@zmanda.com>
15 # Copyright (C) 2001-2009 Craig Barratt
17 # This program is free software; you can redistribute it and/or modify
18 # it under the terms of the GNU General Public License as published by
19 # the Free Software Foundation; either version 2 of the License, or
20 # (at your option) any later version.
22 # This program is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU General Public License for more details.
27 # You should have received a copy of the GNU General Public License
28 # along with this program; if not, write to the Free Software
29 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #========================================================================
33 # Version 3.2.0, released 31 Jul 2010.
35 # See http://backuppc.sourceforge.net.
37 #========================================================================
40 package BackupPC::Xfer;
43 use Encode qw/from_to encode/;
45 use BackupPC::Xfer::Archive;
46 use BackupPC::Xfer::Ftp;
47 use BackupPC::Xfer::Protocol;
48 use BackupPC::Xfer::Rsync;
49 use BackupPC::Xfer::Smb;
50 use BackupPC::Xfer::Tar;
52 use vars qw( $errStr );
56 my($protocol, $bpc, $args) = @_;
61 if ( $protocol eq 'archive' ) {
63 $xfer = BackupPC::Xfer::Archive->new( $bpc, $args );
64 $errStr = BackupPC::Xfer::Archive::errStr() if ( !defined($xfer) );
67 } elsif ( $protocol eq 'ftp' ) {
69 $xfer = BackupPC::Xfer::Ftp->new( $bpc, $args );
70 $errStr = BackupPC::Xfer::Ftp::errStr() if ( !defined($xfer) );
73 } elsif ( $protocol eq 'rsync' || $protocol eq 'rsyncd' ) {
75 $xfer = BackupPC::Xfer::Rsync->new( $bpc, $args );
76 $errStr = BackupPC::Xfer::Rsync::errStr() if ( !defined($xfer) );
79 } elsif ( $protocol eq 'smb' ) {
81 $xfer = BackupPC::Xfer::Smb->new( $bpc, $args );
82 $errStr = BackupPC::Xfer::Smb::errStr() if ( !defined($xfer) );
85 } elsif ( $protocol eq 'tar' ) {
87 $xfer = BackupPC::Xfer::Tar->new( $bpc, $args );
88 $errStr = BackupPC::Xfer::Tar::errStr() if ( !defined($xfer) );
91 } elsif ( $protocol eq 'protocol') {
93 $xfer = BackupPC::Xfer::Protocol->new( $bpc, $args );
94 $errStr = BackupPC::Xfer::Protocol::errStr() if ( !defined($xfer) );
100 $errStr = "$protocol is not a supported protocol.";
106 # getShareNames() loads the correct shares dependent on the
114 if ( $conf->{XferMethod} eq "tar" ) {
115 $ShareNames = $conf->{TarShareName};
117 } elsif ( $conf->{XferMethod} eq "ftp" ) {
118 $ShareNames = $conf->{FtpShareName};
120 } elsif ( $conf->{XferMethod} eq "rsync" || $conf->{XferMethod} eq "rsyncd" ) {
121 $ShareNames = $conf->{RsyncShareName};
123 } elsif ( $conf->{XferMethod} eq "smb" ) {
124 $ShareNames = $conf->{SmbShareName};
128 # default to smb shares
130 $ShareNames = $conf->{SmbShareName};
133 $ShareNames = [$ShareNames] unless ref($ShareNames) eq "ARRAY";
143 if ( $conf->{XferMethod} eq "archive" ) {
146 } elsif ( $conf->{XferMethod} eq "ftp" ) {
149 } elsif ( $conf->{XferMethod} eq "rsync"
150 || $conf->{XferMethod} eq "rsyncd" ) {
151 $restoreCmd = $conf->{RsyncRestoreArgs};
153 } elsif ( $conf->{XferMethod} eq "tar" ) {
154 $restoreCmd = $conf->{TarClientRestoreCmd};
156 } elsif ( $conf->{XferMethod} eq "smb" ) {
157 $restoreCmd = $conf->{SmbClientRestoreCmd};
162 # protocol unrecognized
175 if ( $conf->{XferMethod} eq "archive" ) {
178 } elsif ( $conf->{XferMethod} eq "ftp" ) {
181 } elsif ( $conf->{XferMethod} eq "rsync"
182 || $conf->{XferMethod} eq "rsyncd"
183 || $conf->{XferMethod} eq "tar"
184 || $conf->{XferMethod} eq "smb" ) {
185 $restoreCmd = getRestoreCmd( $conf );
187 ref $restoreCmd eq "ARRAY"