2 #============================================================= -*-perl-*-
4 # BackupPC_archiveStart: start an archive request from the
9 # Usage: BackupPC_archiveStart archiveHost userName hosts...
11 # Initiates an archive request on archive host archiveHost
12 # for the listed hosts. The latest backup for each host is
13 # archived. The userName is name of the requesting user,
14 # which appears in the log files.
17 # Craig Barratt <cbarratt@users.sourceforge.net>
20 # Copyright (C) 2007-2009 Craig Barratt
22 # This program is free software; you can redistribute it and/or modify
23 # it under the terms of the GNU General Public License as published by
24 # the Free Software Foundation; either version 2 of the License, or
25 # (at your option) any later version.
27 # This program is distributed in the hope that it will be useful,
28 # but WITHOUT ANY WARRANTY; without even the implied warranty of
29 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 # GNU General Public License for more details.
32 # You should have received a copy of the GNU General Public License
33 # along with this program; if not, write to the Free Software
34 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36 #========================================================================
38 # Version 3.2.0, released 31 Jul 2010.
40 # See http://backuppc.sourceforge.net.
42 #========================================================================
46 use lib "/usr/local/BackupPC/lib";
50 die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
54 # no options currently
55 if ( !getopts("", \%opts) || @ARGV < 3 ) {
57 usage: $0 archiveHost userName hosts[:num]...
62 my $Hosts = $bpc->HostInfoRead();
63 my $ArchiveHost = $ARGV[0];
64 my $UserName = $ARGV[1];
65 my $TopDir = $bpc->{Conf}{TopDir};
67 if ( !defined($Hosts->{$ArchiveHost}) ) {
68 print(STDERR "$0: archive host $ArchiveHost doesn't exist... quitting\n");
71 $bpc->ConfigRead($ArchiveHost);
73 my(@HostList, @BackupList);
74 for ( my $i = 2 ; $i < @ARGV ; $i++ ) {
75 my ($host,$num) = split(/:/,$ARGV[$i],2);
76 if ( !defined($Hosts->{$host}) ) {
77 print(STDERR "$0: host $host doesn't exist... quitting\n");
80 my @backups = $bpc->BackupInfoRead($host);
82 print(STDERR "$0: host $host doesn't have any backups... quitting\n");
85 push(@HostList, $host);
86 $num ||= $backups[$#backups]{num};
87 push(@BackupList, $num);
91 for ( my $i = 0 ; ; $i++ ) {
92 $ReqFileName="archiveReq.$$.$i";
93 last if ( !-f "$TopDir/pc/$ArchiveHost/$ReqFileName" );
96 archiveloc => $bpc->{Conf}{ArchiveDest},
98 compression => $bpc->{Conf}{ArchiveComp} eq 'none' ? $bpc->{Conf}{CatPath}
99 : ($bpc->{Conf}{ArchiveComp} eq 'gzip'
100 ? $bpc->{Conf}{GzipPath} : $bpc->{Conf}{Bzip2Path}),
101 compext => $bpc->{Conf}{ArchiveComp} eq 'none' ? ''
102 : ($bpc->{Conf}{ArchiveComp} eq 'gzip' ? '.gz' : '.bz2'),
103 parfile => $bpc->{Conf}{ArchivePar},
104 splitsize => '0000000',
105 host => $ArchiveHost,
106 HostList => \@HostList,
107 BackupList => \@BackupList,
111 my $archive = Data::Dumper->new([\%ArchiveReq], [qw(*ArchiveReq)]);
113 if ( !open(REQ, ">", "$TopDir/pc/$ArchiveHost/$ReqFileName") ) {
114 print(STDERR "$0: can't open/write request file $TopDir/pc/$ArchiveHost/$ReqFileName... quitting\n");
118 print REQ $archive->Dump;
120 $bpc->ServerConnect($bpc->{Conf}{ServerHost}, $bpc->{Conf}{ServerPort});
121 my $reply = $bpc->ServerMesg("archive $UserName $ArchiveHost $ReqFileName");
122 $bpc->ServerDisconnect();
123 print("Sent archive request, reply: $reply\n");