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) 2008 Zmanda
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 #========================================================================
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::BackupPCd;
47 use BackupPC::Xfer::Ftp;
48 use BackupPC::Xfer::Protocol;
49 use BackupPC::Xfer::Rsync;
50 use BackupPC::Xfer::Smb;
51 use BackupPC::Xfer::Tar;
53 use vars qw( $errStr );
57 my($protocol, $bpc, $args) = @_;
62 if ( $protocol eq 'archive' ) {
64 $xfer = BackupPC::Xfer::Archive->new( $bpc, $args );
65 $errStr = BackupPC::Xfer::Archive::errStr() if ( !defined($xfer) );
68 } elsif ( $protocol eq 'backuppcd' ) {
70 $xfer = BackupPC::Xfer::BackupPCd->new( $bpc, $args );
71 $errStr = BackupPC::Xfer::BackupPCd::errStr() if ( !defined($xfer) );
74 } elsif ( $protocol eq 'ftp' ) {
76 $xfer = BackupPC::Xfer::Ftp->new( $bpc, $args );
77 $errStr = BackupPC::Xfer::Ftp::errStr() if ( !defined($xfer) );
80 } elsif ( $protocol eq 'rsync' || $protocol eq 'rsyncd' ) {
82 $xfer = BackupPC::Xfer::Rsync->new( $bpc, $args );
83 $errStr = BackupPC::Xfer::Rsync::errStr() if ( !defined($xfer) );
86 } elsif ( $protocol eq 'smb' ) {
88 $xfer = BackupPC::Xfer::Smb->new( $bpc, $args );
89 $errStr = BackupPC::Xfer::Smb::errStr() if ( !defined($xfer) );
92 } elsif ( $protocol eq 'tar' ) {
94 $xfer = BackupPC::Xfer::Tar->new( $bpc, $args );
95 $errStr = BackupPC::Xfer::Tar::errStr() if ( !defined($xfer) );
98 } elsif ( $protocol eq 'protocol') {
100 $xfer = BackupPC::Xfer::Protocol->new( $bpc, $args );
101 $errStr = BackupPC::Xfer::Protocol::errStr() if ( !defined($xfer) );
107 $errStr = "$protocol is not a supported protocol.";
113 # getShareNames() loads the correct shares dependent on the
121 if ( $conf->{XferMethod} eq "tar" ) {
122 $ShareNames = $conf->{TarShareName};
124 } elsif ( $conf->{XferMethod} eq "ftp" ) {
125 $ShareNames = $conf->{FtpShareName};
127 } elsif ( $conf->{XferMethod} eq "rsync" || $conf->{XferMethod} eq "rsyncd" ) {
128 $ShareNames = $conf->{RsyncShareName};
130 } elsif ( $conf->{XferMethod} eq "backuppcd" ) {
131 $ShareNames = $conf->{BackupPCdShareName};
133 } elsif ( $conf->{XferMethod} eq "smb" ) {
134 $ShareNames = $conf->{SmbShareName};
138 # default to smb shares
140 $ShareNames = $conf->{SmbShareName};
143 $ShareNames = [$ShareNames] unless ref($ShareNames) eq "ARRAY";