fix register_existingbackups

fix tmp gzip for pgsqldump
This commit is contained in:
htouvet 2018-02-09 09:55:33 +01:00
parent c29ad67075
commit b082796a87
2 changed files with 9 additions and 6 deletions

View File

@ -86,12 +86,14 @@ class backup_pgsql(backup_generic):
def do_pgsqldump(self,stats):
t = datetime.datetime.now()
backup_start_date = t.strftime('%Y%m%d-%Hh%Mm%S')
# 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 = {
'encoding':self.encoding,
'db_name':self.db_name,
'tmp_dir':self.tmp_dir,
'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)
@ -100,7 +102,8 @@ class backup_pgsql(backup_generic):
raise Exception('Aborting, Not null exit code (%i) for "%s"' % (error_code,cmd))
# zip the file
cmd = 'gzip /tmp/' + self.db_name + '-' + backup_start_date + '.sql'
cmd = 'gzip %(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)
@ -109,8 +112,8 @@ class backup_pgsql(backup_generic):
raise Exception('Aborting, Not null exit code (%i) for "%s"' % (error_code,cmd))
# get the file
filepath = '/tmp/' + self.db_name + '-' + backup_start_date + '.sql.gz'
localpath = self.dest_dir + '/' + self.db_name + '-' + backup_start_date + '.sql.gz'
filepath = '%(tmp_dir)s/%(db_name)s-%(backup_start_date)s.sql' % 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:
transport = self.ssh.get_transport()

View File

@ -810,7 +810,7 @@ class backup_generic:
def register_existingbackups(self):
"""scan existing backups and insert stats in database"""
registered = [b['backup_location'] for b in self.dbstat.query('select distinct backup_location from stats where backup_name=?',self.backup_name)]
registered = [b['backup_location'] for b in self.dbstat.query('select distinct backup_location from stats where backup_name=?',[self.backup_name])]
raise Exception('Abstract method')
def export_latestbackup(self,destdir):