1 |
dpavlin |
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, released 20 Jun 2004. |
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 $errStr; |
100 |
|
|
my $cmdargs = { |
101 |
|
|
archiveloc => $t->{archiveloc}, |
102 |
|
|
parfile => $t->{parfile}, |
103 |
|
|
compression => $t->{compression}, |
104 |
|
|
compext => $t->{compext}, |
105 |
|
|
splitsize => $t->{splitsize}, |
106 |
|
|
host => ${@HostList[0]}[$i], |
107 |
|
|
backupnumber => ${@BackupList[0]}[$i], |
108 |
|
|
Installdir => $conf->{InstallDir}, |
109 |
|
|
tarCreatePath => $tarCreatePath, |
110 |
|
|
splitpath => $conf->{SplitPath}, |
111 |
|
|
parpath => $conf->{ParPath}, |
112 |
|
|
}; |
113 |
|
|
|
114 |
|
|
$archiveClientCmd2 = $bpc->cmdVarSubstitute($archiveClientCmd, |
115 |
|
|
$cmdargs); |
116 |
|
|
$t->{XferLOG}->write(\"Executing: @$archiveClientCmd2\n"); |
117 |
|
|
|
118 |
|
|
$bpc->cmdSystemOrEvalLong($archiveClientCmd2, |
119 |
|
|
sub { |
120 |
|
|
$errStr = $_[0]; |
121 |
|
|
$t->{XferLOG}->write(\$_[0]); |
122 |
|
|
}, 0, $t->{pidHandler}); |
123 |
|
|
if ( $? ) { |
124 |
|
|
($t->{_errStr} = $errStr) =~ s/[\n\r]+//; |
125 |
|
|
return; |
126 |
|
|
} |
127 |
|
|
$i++; |
128 |
|
|
} |
129 |
|
|
$t->{XferLOG}->write(\"Completed Archive\n"); |
130 |
|
|
return "Completed Archive"; |
131 |
|
|
} |
132 |
|
|
|
133 |
|
|
sub errStr |
134 |
|
|
{ |
135 |
|
|
my($t) = @_; |
136 |
|
|
|
137 |
|
|
return $t->{_errStr}; |
138 |
|
|
} |
139 |
|
|
|
140 |
|
|
sub abort |
141 |
|
|
{ |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
sub xferPid |
145 |
|
|
{ |
146 |
|
|
my($t) = @_; |
147 |
|
|
|
148 |
|
|
return ($t->{xferPid}); |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
sub logMsg |
152 |
|
|
{ |
153 |
|
|
my($t, $msg) = @_; |
154 |
|
|
|
155 |
|
|
push(@{$t->{_logMsg}}, $msg); |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
sub logMsgGet |
159 |
|
|
{ |
160 |
|
|
my($t) = @_; |
161 |
|
|
|
162 |
|
|
return shift(@{$t->{_logMsg}}); |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
1; |