The following patch addresses 2 limitations I often run into with the
user-space BackupPC_zcat function

1. The v4 version requires that you run as user 'backuppc' (even root
   fails) which shouldn't be necessary (and wasn't necessary in the
   simpler v3 version)

2. It is a pain in the neck to 'cat' a mix of compressed and
   non-compressed files. For example, you cant do:
   BackupPC_zcat TopDir/log/LOG* because the latest log is
   uncompressed and the older ones are compressed.

The following simple patch addresses those issues:


--- /usr/share/backuppc/bin/BackupPC_zcat       2020-06-21 18:27:35.000000000 
-0400
+++ /tmp/BackupPC_zcat  2022-01-25 22:05:40.491222233 -0500
@@ -51,7 +51,7 @@
 use BackupPC::View;
 use Getopt::Std;
 
-die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
+die("BackupPC::Lib->new failed\n") if ( !(my $bpc = 
BackupPC::Lib->new("","","",1)) ); #No user check
 my $TopDir = $bpc->TopDir();
 my %Conf   = $bpc->Conf();
 
@@ -68,8 +68,21 @@
 }
 
 my $ret = 0;
+my $CompressLevel = $Conf{CompressLevel}; #Store original value
 if ( @ARGV ) {
     while ( my $file = shift(@ARGV) ) {
+       #Check if zlib and if not then set $Conf{CompressLevel} = 0
+       #This allows you to use BackupPC_zcat on uncompressed files
+       open(FD, $file) || die "File open failed for '$file': $!\n";
+       if(read(F, my $buffer, 4)){
+           my ($magic1, $magic2) = unpack("C2C2", $buffer);
+           $Conf{CompressLevel} = 
+               ($magic1 == 0x78 && 
+                ($magic2 == 0x01 || $magic2 == 0x5E || $magic2 == 0x9c || 
$magic2 == 0xDA)) ?
+               $CompressLevel :0; #Override original $Conf{CompressLevel} and 
set to 0 if not zlib compressed
+       }
+       close(FD);
+
         #
         # first case is an MD5 digest - try to find it in the pool (if it 
doesn't exist as a file)
         #


_______________________________________________
BackupPC-users mailing list
BackupPC-users@lists.sourceforge.net
List:    https://lists.sourceforge.net/lists/listinfo/backuppc-users
Wiki:    https://github.com/backuppc/backuppc/wiki
Project: https://backuppc.github.io/backuppc/

Reply via email to