#!/usr/bin/perl
#============================================================= -*-perl-*-
#
# BackupPC_archive: Archive files for an archive client.
#
# DESCRIPTION
#
#   Usage: BackupPC_archive <user> <archiveclient> <reqFileName>
#
# AUTHOR
#   Josh Marshall
#
# COPYRIGHT
#   Copyright (C) 2001-2009  Craig Barratt
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#========================================================================
#
# Version 3.2.1, released 24 Apr 2011.
#
# See http://backuppc.sourceforge.net.
#
#========================================================================

use strict;
no  utf8;
use lib "/usr/share/backuppc/lib";
use BackupPC::Lib;
use BackupPC::FileZIO;
use BackupPC::Xfer::Archive;

use vars qw( %ArchiveReq );

###########################################################################
# Initialize
###########################################################################

die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
my $TopDir = $bpc->TopDir();
my $BinDir = $bpc->BinDir();
my %Conf   = $bpc->Conf();
my $NeedPostCmd;

my($user, $host, $client, $reqFileName, %stat);

$bpc->ChildInit();

if ( @ARGV != 3 ) {
    print("usage: $0 <user> <archiveclient> <reqFileName>\n");
    exit(1);
}
$user = $1 if ( $ARGV[0] =~ /(.+)/ );
$client = $1 if ( $ARGV[1] =~ /(.+)/ );
if ( $ARGV[2] !~ /^([\w\.\s-]+)$/ ) {
    print("$0: bad reqFileName (arg #3): $ARGV[2]\n");
    exit(1);
}
$reqFileName = $1;

my $startTime = time();

my $Dir     = "$TopDir/pc/$client";
my @xferPid = ();

#
# Catch various signals
#
$SIG{INT}  = \&catch_signal;
$SIG{ALRM} = \&catch_signal;
$SIG{TERM} = \&catch_signal;
$SIG{PIPE} = \&catch_signal;
$SIG{STOP} = \&catch_signal;
$SIG{TSTP} = \&catch_signal;
$SIG{TTIN} = \&catch_signal;
my $Pid = $$;

m                                                                                  #!/usr/bin/perl
#============================================================= -*-perl-*-
#
# BackupPC_attribPrint: print the contents of attrib files.
#
# DESCRIPTION
#  
#   Usage: BackupPC_attribPrint attribPath
#
#   Compression status of attrib path is based on $Conf{CompressLevel}.
#
# AUTHOR
#   Craig Barratt  <cbarratt@users.sourceforge.net>
#
# COPYRIGHT
#   Copyright (C) 2005-2009  Craig Barratt
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#========================================================================
#
# Version 3.2.1, released 24 Apr 2011.
#
# See http://backuppc.sourceforge.net.
#
#========================================================================

use strict;
no  utf8;
use lib "/usr/share/backuppc/lib";

use BackupPC::Lib;
use BackupPC::Attrib qw(:all);
use BackupPC::FileZIO;
use Data::Dumper;

die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
my $TopDir = $bpc->TopDir();
my $BinDir = $bpc->BinDir();
my %Conf   = $bpc->Conf();

if ( @ARGV != 1 ) {
    print STDERR "Usage: $0 attribPath\n";
    exit(1);
}
if ( !-f $ARGV[0] ) {
    print STDERR "$ARGV[0] does not exist\n";
    exit(1);
}

my $attrib = BackupPC::Attrib->new({ compress => $Conf{CompressLevel} });

my($dir, $file);

if ( $ARGV[0] =~ m{(.+)/(.+)} ) {
    $dir  = $1;
    $file = $2;
} else {
    $dir = $ARGV[0];
}

if ( !$attrib->read($dir, $file) ) {
    print STDERR "Cannot read attrib file $ARGV[0]\n";
    exit(1);
}
my $info = $attrib->get();
$Data::Dumper::Indent = 1;
print Dumper($info);
                                                                                                                                                                                                                                                                                                                                                         ./usr/share/backuppc/bin/BackupPC_archiveStart                                                      0000755 0000000 0000000 00000007704 12065126753 020300  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   #!/usr/bin/perl
#============================================================= -*-perl-*-
#
# BackupPC_archiveStart: start an archive request from the
# command line.
#
# DESCRIPTION
#  
#   Usage: BackupPC_archiveStart archiveHost userName hosts...
#
#   Initiates an archive request on archive host archiveHost
#   for the listed hosts.  The latest backup for each host is
#   archived.  The userName is name of the requesting user,
#   which appears in the log files.
#
# AUTHOR
#   Craig Barratt  <cbarratt@users.sourceforge.net>
#
# COPYRIGHT
#   Copyright (C) 2007-2009  Craig Barratt
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#========================================================================
#
# Version 3.2.1, released 24 Apr 2011.
#
# See http://backuppc.sourceforge.net.
#
#========================================================================

use strict;
no  utf8;
use lib "/usr/share/backuppc/lib";
use Getopt::Std;
use BackupPC::Lib;

die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );

my %opts;

# no options currently
if ( !getopts("", \%opts) || @ARGV < 3 ) {
    print STDERR <<EOF;
usage: $0 archiveHost userName hosts...
EOF
    exit(1);
}

my $Hosts       = $bpc->HostInfoRead();
my $ArchiveHost = $ARGV[0];
my $UserName    = $ARGV[1];
my $TopDir      = $bpc->{Conf}{TopDir};

if ( !defined($Hosts->{$ArchiveHost}) ) {
    print(STDERR "$0: archive host $ArchiveHost doesn't exist... quitting\n");
    exit(1);
}
$bpc->ConfigRead($ArchiveHost);

my(@HostList, @BackupList);
for ( my $i = 2 ; $i < @ARGV ; $i++ ) {
    my $host = $ARGV[$i];
    if ( !defined($Hosts->{$host}) ) {
        print(STDERR "$0: host $host doesn't exist... quitting\n");
        exit(1);
    }
    my @backups = $bpc->BackupInfoRead($host);
    if ( !@backups ) {
        print(STDERR "$0: host $host doesn't have any backups... quitting\n");
        exit(1);
    }
    push(@HostList, $host);
    push(@BackupList, $backups[$#backups]{num});
}

my $ReqFileName;
for ( my $i = 0 ; ; $i++ ) {
    $ReqFileName="archiveReq.$$.$i";
    last if ( !-f "$TopDir/pc/$ArchiveHost/$ReqFileName" );
}
my %ArchiveReq = (
    archiveloc  => $bpc->{Conf}{ArchiveDest},
    archtype    => 0,
    compression => $bpc->{Conf}{ArchiveComp} eq 'none' ? $bpc->{Conf}{CatPath}
                    : ($bpc->{Conf}{ArchiveComp} eq 'gzip'
                      ? $bpc->{Conf}{GzipPath} : $bpc->{Conf}{Bzip2Path}),
    compext     => $bpc->{Conf}{ArchiveComp} eq 'none' ? ''
                    : ($bpc->{Conf}{ArchiveComp} eq 'gzip' ? '.gz' : '.bz2'),
    parfile     => $bpc->{Conf}{ArchivePar},
    splitsize   => '0000000',
    host        => $ArchiveHost,
    HostList    => \@HostList,
    BackupList  => \@BackupList,
    user        => $UserName,
    reqTime     => time,
);
my $archive = Data::Dumper->new([\%ArchiveReq], [qw(*ArchiveReq)]);
$archive->Indent(1);
if ( !open(REQ, ">", "$TopDir/pc/$ArchiveHost/$ReqFileName") ) {
    print(STDERR "$0: can't open/write request file $TopDir/pc/$ArchiveHost/$ReqFileName... quitting\n");
    exit(1);
}
binmode(REQ);
print REQ $archive->Dump;
close(REQ);
$bpc->ServerConnect($bpc->{Conf}{ServerHost}, $bpc->{Conf}{ServerPort});
my $reply = $bpc->ServerMesg("archive $UserName $ArchiveHost $ReqFileName");
$bpc->ServerDisconnect();
print("Sent archive request, reply: $reply\n");
exit(0);
                                                            ./usr/share/backuppc/bin/BackupPC_archiveHost                                                       0000755 0000000 0000000 00000012322 12065126753 020110  0                                                                                                    ustar   root                            root                                                                                                                                                                                                                   #!/usr/bin/perl
#=============================================================
#
# BackupPC_archiveHost: Archive files for a single host
#
# DESCRIPTION
#
#   Usage: BackupPC_archiveHost tarCreatePath splitPath parPath host bkupNum \
#               compPath fileExt splitSize outLoc parFile share
#
#   This script is run for each host to create an archive.
#
#   This script is executed by BackupPC_archive, based on the setting
#   of $Conf{ArchiveClientCmd}.  This script can be copied and modified
#   for site-specific behavior.  Update $Conf{ArchiveClientCmd} to point
#   at your customized archive script.
#
# AUTHOR
#   Craig Barratt  <cbarratt@users.sourceforge.net>
#   Josh Marshall
#
# COPYRIGHT
#   Copyright (C) 2001-2009  Craig Barratt
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS 