def _db_pg_dump(self, db_name, db_filename): _logger.info('auto_backup DUMP DB!') pg_passwd = os.environ.get( 'PGPASSWORD') or tools.config['db_password'] or False data = '' if not pg_passwd: _logger.error( 'DUMP DB: %s failed! Please verify the configuration of the database password on the server. ' 'You may need to create a .pgpass file for authentication, or specify `db_password` in the ' 'server configuration file.\n %s', db_name, data) raise Exception, "Couldn't dump database" os.environ['PGPASSWORD'] = tools.config['db_password'] cmd = ['pg_dump', '--format=c', '--no-owner'] if tools.config['db_user']: cmd.append('--username='******'db_user']) if tools.config['db_host']: cmd.append('--host=' + tools.config['db_host']) if tools.config['db_port']: cmd.append('--port=' + str(tools.config['db_port'])) cmd.append('--file=' + db_filename) cmd.append(db_name) stdin, stdout = tools.exec_pg_command_pipe(*tuple(cmd)) stdin.close() data = stdout.read() res = stdout.close() return base64.encodestring(data)
def _db_pg_dump(self, db_name, db_filename): _logger.info('auto_backup DUMP DB!') pg_passwd = os.environ.get('PGPASSWORD') or tools.config['db_password'] or False data = '' if not pg_passwd: _logger.error( 'DUMP DB: %s failed! Please verify the configuration of the database password on the server. ' 'You may need to create a .pgpass file for authentication, or specify `db_password` in the ' 'server configuration file.\n %s', db_name, data) raise Exception, "Couldn't dump database" os.environ['PGPASSWORD'] = tools.config['db_password'] cmd = ['pg_dump', '--format=c', '--no-owner'] if tools.config['db_user']: cmd.append('--username='******'db_user']) if tools.config['db_host']: cmd.append('--host=' + tools.config['db_host']) if tools.config['db_port']: cmd.append('--port=' + str(tools.config['db_port'])) cmd.append('--file=' + db_filename) cmd.append(db_name) stdin, stdout = tools.exec_pg_command_pipe(*tuple(cmd)) stdin.close() data = stdout.read() res = stdout.close() return base64.encodestring(data) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: