Skip to content

Commit

Permalink
Merge pull request #464 from pelzvieh/master
Browse files Browse the repository at this point in the history
Clean stdout and support writing to a pipe
  • Loading branch information
craigbarratt committed May 10, 2022
2 parents 2c9270b + fc25b65 commit 174e707
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions bin/BackupPC_archiveHost
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
# AUTHOR
# Craig Barratt <cbarratt@users.sourceforge.net>
# Josh Marshall
# Andreas Feldner
#
# COPYRIGHT
# Copyright (C) 2001-2013 Craig Barratt
# Copyright (C) 2001-2020 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
Expand All @@ -37,7 +38,7 @@
#
#========================================================================
#
# Version 4.0.0alpha3, released 1 Dec 2013.
# Version 4.4.x.
#
# See http://backuppc.sourceforge.net.
#
Expand All @@ -52,7 +53,7 @@ use BackupPC::Lib;
# Pick up the command-line arguments
#
if ( @ARGV != 11 ) {
print <<EOF;
print STDERR <<EOF;
Usage: $0 tarCreatePath splitPath parPath host bkupNum \\
compPath fileExt splitSize outLoc parFile share
EOF
Expand All @@ -78,11 +79,11 @@ die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
#
foreach my $prog ( ($tarCreate, $compPath, $splitPath, $parPath) ) {
if ( $prog =~ /[][;&()<>{}|^\n\r\t *\$\\'"`?]/ ) {
print("Error: executable path $prog contains suspicious characters\n");
print STDERR "Error: executable path $prog contains suspicious characters\n";
exit(1);
}
next if ( $prog eq "" || -x $prog );
print("Error: $prog is not an executable program\n");
print STDERR "Error: $prog is not an executable program\n";
exit(1);
}
my $mesg = "Writing tar archive for host $host, backup #$bkupNum";
Expand All @@ -97,7 +98,6 @@ $fileExt = $bpc->shellEscape($fileExt);
$splitSize = $bpc->shellEscape($splitSize);
$parfile = $bpc->shellEscape($parfile);
my $outLocE = $bpc->shellEscape($outLoc);

#
# We prefer to use /bin/csh because the exit status of a pipeline
# is non-zero if any command is non zero. In contrast, /bin/sh
Expand All @@ -110,12 +110,12 @@ if ( -x "/bin/csh" ) {
} elsif ( -x "/bin/sh" ) {
@shell = ("/bin/sh", "-c");
} else {
print("Error: Can't find executable /bin/csh or /bin/sh\n");
print STDERR "Error: Can't find executable /bin/csh or /bin/sh\n";
exit(1);
}
my $cmd = "$tarCreate -t -h $host -n $bkupNum -s $share . ";
$cmd .= "| $compPath " if ( $compPath ne "cat" && $compPath ne "/bin/cat" && $compPath ne "" );
if ( -b $outLoc || -c $outLoc || -f $outLoc ) {
if ( -b $outLoc || -p $outLoc || -c $outLoc || -f $outLoc ) {
#
# Output file is a device or a regular file, so don't use split
#
Expand All @@ -124,7 +124,7 @@ if ( -b $outLoc || -c $outLoc || -f $outLoc ) {
} else {
mkpath($outLoc) if ( !-d $outLoc );
if ( !-d $outLoc ) {
print("Error: unable to create output directory $outLoc\n");
print STDERR "Error: unable to create output directory $outLoc\n";
exit(1);
}
if ( $splitSize > 0 && -x $splitPath ) {
Expand All @@ -135,15 +135,15 @@ if ( -b $outLoc || -c $outLoc || -f $outLoc ) {
$mesg .= " to output file $outLocE/$host.$bkupNum.tar$fileExt";
}
}
print("$mesg\n");
print STDERR "$mesg\n";

#
# Run the command
#
my $ret = system(@shell, $cmd);
if ( $ret ) {
print("Executing: @shell $cmd\n");
print("Error: $tarCreate, compress or split failed\n");
print STDERR "Executing: @shell $cmd\n";
print STDERR "Error: $tarCreate, compress or split failed\n";
exit(1);
}

Expand All @@ -153,13 +153,13 @@ if ( $ret ) {
#
if ( -d $outLoc && -x $parPath ) {
if ( length($parfile) && $parfile != 0 ) {
print("Running $parPath to create parity files\n");
print STDERR "Running $parPath to create parity files\n";
my $parCmd =
"$parPath c -r$parfile $outLocE/$host.$bkupNum.tar$fileExt.par2 $outLocE/$host.$bkupNum.tar$fileExt*";
$ret = system($parCmd);
if ( $ret ) {
print("Executing: $parCmd\n");
print("Error: $parPath failed\n");
print STDERR "Executing: $parCmd\n";
print STDERR "Error: $parPath failed\n";
exit(1);
}
}
Expand Down

0 comments on commit 174e707

Please sign in to comment.