Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cedriczirtacic/8023012 to your computer and use it in GitHub Desktop.
Save cedriczirtacic/8023012 to your computer and use it in GitHub Desktop.
Patch for webmin's postgresql backup script to enable gzip/bzip2 compression.
--- postgresql/backup.pl.old 2013-12-17 14:50:06.000000000 -0300
+++ postgresql/backup.pl 2013-12-17 16:25:52.000000000 -0300
@@ -2,6 +2,7 @@
# backup.pl
# Called by cron to backup a database
+my $compress;
$no_acl_check++;
require './postgresql-lib.pl';
@@ -16,6 +17,8 @@
$cmode = 0;
}
+$compress=$1 if($ARGV[1] =~ m/^--(bzip2|gzip)$/);
+
if ($cmode) {
# Run and check before-backup command (for all DBs)
$bok = &execute_before(undef, STDOUT, 0, $config{'backup_'}, undef);
@@ -69,7 +72,20 @@
if (!$cmode) {
&execute_after($db, STDOUT, 0, $file, $all ? undef : $db);
}
+ if(defined($compress)){
+ my $compression_lvl=5; # level of compression used. change it at will.
+ my $bin_compress=qx{ which $compress };
+ my @args_compress;
+
+ if($compress=~/bzip2/){
+ push @args_compress, "-z"
+ }
+ push @args_compress, "-$compression_lvl";
+ chomp $bin_compress;
+ system(qq{ "$bin_compress" @args_compress "$file" });
+ print STDERR "Error compressing the file $file" if($? > 0);
}
+}
if ($cmode) {
&execute_after(undef, STDOUT, 0, $config{'backup_'}, undef);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment