From 5a1e984a0b42c76cf2c7962c40a2fd6f73f377ef Mon Sep 17 00:00:00 2001 From: Jeremie Courreges-Anglas Date: Fri, 27 Jul 2018 11:53:30 +0200 Subject: [PATCH] Use pg_dump -Z to compress the output on the fly Less temp files overhead, less space used in tmp_dir, and less code. -Z is supported since PostgreSQL 7.1. --- libtisbackup/backup_pgsql.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/libtisbackup/backup_pgsql.py b/libtisbackup/backup_pgsql.py index 9c6172a..49ab969 100644 --- a/libtisbackup/backup_pgsql.py +++ b/libtisbackup/backup_pgsql.py @@ -93,17 +93,9 @@ class backup_pgsql(backup_generic): 'dest_dir':self.dest_dir, 'backup_start_date':backup_start_date} # dump db - cmd = "su - postgres -c 'pg_dump -E %(encoding)s %(db_name)s > %(tmp_dir)s/%(db_name)s-%(backup_start_date)s.sql'" % params - self.logger.debug('[%s] %s ',self.backup_name,cmd) - if not self.dry_run: - (error_code,output) = ssh_exec(cmd,ssh=self.ssh) - self.logger.debug("[%s] Output of %s :\n%s",self.backup_name,cmd,output) - if error_code: - raise Exception('Aborting, Not null exit code (%i) for "%s"' % (error_code,cmd)) - - # zip the file - cmd = 'gzip %(tmp_dir)s/%(db_name)s-%(backup_start_date)s.sql' % params - + filepath = '%(tmp_dir)s/%(db_name)s-%(backup_start_date)s.sql.gz' % params + cmd = "su - postgres -c 'pg_dump -E %(encoding)s -Z9 %(db_name)s'" % params + cmd += ' > ' + filepath self.logger.debug('[%s] %s ',self.backup_name,cmd) if not self.dry_run: (error_code,output) = ssh_exec(cmd,ssh=self.ssh) @@ -112,7 +104,6 @@ class backup_pgsql(backup_generic): raise Exception('Aborting, Not null exit code (%i) for "%s"' % (error_code,cmd)) # get the file - filepath = '%(tmp_dir)s/%(db_name)s-%(backup_start_date)s.sql.gz' % params localpath = '%(dest_dir)s/%(db_name)s-%(backup_start_date)s.sql.gz' % params self.logger.debug('[%s] get the file using sftp from "%s" to "%s" ',self.backup_name,filepath,localpath) if not self.dry_run: