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>
18 # Dobrica Pavlinusic <dpavlin@rot13.org>
21 # Copyright (C) 2007-2009 Craig Barratt
23 # This program is free software; you can redistribute it and/or modify
24 # it under the terms of the GNU General Public License as published by
25 # the Free Software Foundation; either version 2 of the License, or
26 # (at your option) any later version.
28 # This program is distributed in the hope that it will be useful,
29 # but WITHOUT ANY WARRANTY; without even the implied warranty of
30 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 # GNU General Public License for more details.
33 # You should have received a copy of the GNU General Public License
34 # along with this program; if not, write to the Free Software
35 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 #========================================================================
39 # Version 3.2.0, released 31 Jul 2010.
41 # See http://backuppc.sourceforge.net.
43 #========================================================================
47 use lib "/usr/local/BackupPC/lib";
53 die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
57 # no options currently
58 if ( !getopts("", \%opts) || @ARGV < 3 ) {
60 usage: $0 archiveHost userName hosts[:num]...
65 my $Hosts = $bpc->HostInfoRead();
66 my $ArchiveHost = $ARGV[0];
67 my $UserName = $ARGV[1];
68 my $TopDir = $bpc->{Conf}{TopDir};
70 if ( !defined($Hosts->{$ArchiveHost}) ) {
71 print(STDERR "$0: archive host $ArchiveHost doesn't exist... quitting\n");
74 $bpc->ConfigRead($ArchiveHost);
76 my(@HostList, @BackupList);
77 for ( my $i = 2 ; $i < @ARGV ; $i++ ) {
78 my ($host,$num) = split(/:/,$ARGV[$i],2);
79 if ( !defined($Hosts->{$host}) ) {
80 print(STDERR "$0: host $host doesn't exist... quitting\n");
83 my @backups = $bpc->BackupInfoRead($host);
85 print(STDERR "$0: host $host doesn't have any backups... quitting\n");
88 push(@HostList, $host);
89 $num ||= $backups[$#backups]{num};
90 push(@BackupList, $num);
94 for ( my $i = 0 ; ; $i++ ) {
95 $ReqFileName="archiveReq.$$.$i";
96 last if ( !-f "$TopDir/pc/$ArchiveHost/$ReqFileName" );
99 archiveloc => $bpc->{Conf}{ArchiveDest},
101 compression => $bpc->{Conf}{ArchiveComp} eq 'none' ? $bpc->{Conf}{CatPath}
102 : ($bpc->{Conf}{ArchiveComp} eq 'gzip'
103 ? $bpc->{Conf}{GzipPath} : $bpc->{Conf}{Bzip2Path}),
104 compext => $bpc->{Conf}{ArchiveComp} eq 'none' ? ''
105 : ($bpc->{Conf}{ArchiveComp} eq 'gzip' ? '.gz' : '.bz2'),
106 parfile => $bpc->{Conf}{ArchivePar},
107 splitsize => '0000000',
108 host => $ArchiveHost,
109 HostList => \@HostList,
110 BackupList => \@BackupList,
114 my $archive = Data::Dumper->new([\%ArchiveReq], [qw(*ArchiveReq)]);
116 if ( !open(REQ, ">", "$TopDir/pc/$ArchiveHost/$ReqFileName") ) {
117 print(STDERR "$0: can't open/write request file $TopDir/pc/$ArchiveHost/$ReqFileName... quitting\n");
121 print REQ $archive->Dump;
123 $bpc->ServerConnect($bpc->{Conf}{ServerHost}, $bpc->{Conf}{ServerPort});
124 my $reply = $bpc->ServerMesg("archive $UserName $ArchiveHost $ReqFileName");
125 $bpc->ServerDisconnect();
126 print("Sent archive request, reply: $reply\n");