* Added lib/BackupPC/Xfer/Archive.pm
[BackupPC.git] / lib / BackupPC / Xfer / Archive.pm
1 #============================================================= -*-perl-*-
2 #
3 # BackupPC::Xfer::Archive package
4 #
5 # DESCRIPTION
6 #
7 #   This library defines a BackupPC::Xfer::Archive class for managing
8 #   archives to media.
9 #
10 # AUTHOR
11 #   Craig Barratt  <cbarratt@users.sourceforge.net>
12 #
13 # COPYRIGHT
14 #   Copyright (C) 2001-2003  Craig Barratt
15 #
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.
20 #
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.
25 #
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
29 #
30 #========================================================================
31 #
32 # Version 2.1.0_CVS, released 3 Jul 2003.
33 #
34 # See http://backuppc.sourceforge.net.
35 #
36 #========================================================================
37
38 package BackupPC::Xfer::Archive;
39
40 use strict;
41
42 sub new
43 {
44     my($class, $bpc, $args) = @_;
45
46     $args ||= {};
47     my $t = bless {
48         bpc       => $bpc,
49         conf      => { $bpc->Conf },
50         host      => "",
51         hostIP    => "",
52         shareName => "",
53         pipeRH    => undef,
54         pipeWH    => undef,
55         badFiles  => [],
56         %$args,
57     }, $class;
58
59     return $t;
60 }
61
62 sub args
63 {
64     my($t, $args) = @_;
65
66     foreach my $arg ( keys(%$args) ) {
67         $t->{$arg} = $args->{$arg};
68     }
69 }
70
71 sub useArchive
72 {
73     return 1;
74 }
75
76 sub start
77 {
78     return "Archive Started";
79 }
80
81 sub run
82 {
83     my($t) = @_;
84     my $bpc = $t->{bpc};
85     my $conf = $t->{conf};
86     
87     my(@HostList, @BackupList, $archiveClientCmd, $archiveClientCmd2, $logMsg);
88
89     $archiveClientCmd = $conf->{ArchiveClientCmd};
90     $t->{xferOK} = 1;
91     @HostList = $t->{HostList};
92     @BackupList = $t->{BackupList};
93     my $i=0;
94     my $tarCreatePath = $conf->{InstallDir} . "/bin/BackupPC_tarCreate";
95     while (${@HostList[0]}[$i]) {
96       #
97       # Merge variables into @archiveClientCmd
98       #
99       my $cmdargs = {
100           archiveloc   => $t->{archiveloc},
101           parfile      => $t->{parfile},
102           compression  => $t->{compression},
103           compext      => $t->{compext},
104           splitsize    => $t->{splitsize},
105           host         => ${@HostList[0]}[$i],
106           backupnumber => ${@BackupList[0]}[$i],
107           Installdir    => $conf->{InstallDir},
108           tarCreatePath => $tarCreatePath,
109           splitpath     => $conf->{SplitPath},
110           parpath       => $conf->{ParPath},
111       };
112
113       $archiveClientCmd2 = $bpc->cmdVarSubstitute($archiveClientCmd, $cmdargs);
114       $t->{XferLOG}->write(\"Executing: @$archiveClientCmd2\n");
115
116        $bpc->cmdSystemOrEval($archiveClientCmd2,
117             sub {
118                 $t->{XferLOG}->write(\$_[0]);
119             });
120
121       $i++;
122     }
123     $t->{XferLOG}->write(\"Completed Archive\n");
124     return "Completed Archive";
125 }
126
127 sub errStr
128 {
129     my($t) = @_;
130
131     return $t->{_errStr};
132 }
133
134 sub xferPid
135 {
136     my($t) = @_;
137
138     return ($t->{xferPid});
139 }
140
141 sub logMsg
142 {
143     my($t, $msg) = @_;
144
145     push(@{$t->{_logMsg}}, $msg);
146 }
147
148 sub logMsgGet
149 {
150     my($t) = @_;
151
152     return shift(@{$t->{_logMsg}});
153 }
154
155 1;