* fixed typo in ChangeLog
[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-2009  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 3.2.0beta0, released 5 April 2009.
33 #
34 # See http://backuppc.sourceforge.net.
35 #
36 #========================================================================
37
38 package BackupPC::Xfer::Archive;
39
40 use strict;
41 use base qw(BackupPC::Xfer::Protocol);
42
43 sub start
44 {
45     return "Archive Started";
46 }
47
48 sub run
49 {
50     my($t) = @_;
51     my $bpc = $t->{bpc};
52     my $conf = $t->{conf};
53     
54     my(@HostList, @BackupList, $archiveClientCmd, $archiveClientCmd2, $logMsg);
55
56     $archiveClientCmd = $conf->{ArchiveClientCmd};
57     $t->{xferOK} = 1;
58     @HostList = $t->{HostList};
59     @BackupList = $t->{BackupList};
60     my $i = 0;
61     my $tarCreatePath = "$conf->{InstallDir}/bin/BackupPC_tarCreate";
62     while (${@HostList[0]}[$i]) {
63         #
64         #   Merge variables into @archiveClientCmd
65         #
66         my $errStr;
67         my $cmdargs = {
68             archiveloc    => $t->{archiveloc},
69             parfile       => $t->{parfile},
70             compression   => $t->{compression},
71             compext       => $t->{compext},
72             splitsize     => $t->{splitsize},
73             host          => ${@HostList[0]}[$i],
74             backupnumber  => ${@BackupList[0]}[$i],
75             Installdir    => $conf->{InstallDir},
76             tarCreatePath => $tarCreatePath,
77             splitpath     => $conf->{SplitPath},
78             parpath       => $conf->{ParPath},
79         };
80
81         $archiveClientCmd2 = $bpc->cmdVarSubstitute($archiveClientCmd,
82                                                     $cmdargs);
83         $t->{XferLOG}->write(\"Executing: @$archiveClientCmd2\n");
84
85         $bpc->cmdSystemOrEvalLong($archiveClientCmd2,
86             sub {
87                 $errStr = $_[0];
88                 $t->{XferLOG}->write(\$_[0]);
89             }, 0, $t->{pidHandler});
90         if ( $? ) {
91             ($t->{_errStr} = $errStr) =~ s/[\n\r]+//;
92             return;
93         }
94         $i++;
95     }
96     $t->{XferLOG}->write(\"Completed Archive\n");
97     return "Completed Archive";
98 }
99
100 1;