Ensure that Backup, Restore, and Maintenance should work properly when pgpass file is used. #6499

pull/6553/head
Akshay Joshi 2023-07-11 15:34:14 +05:30
parent 20ad30abc1
commit def1f31ba8
7 changed files with 42 additions and 71 deletions

View File

@ -40,10 +40,12 @@ Bug fixes
| `Issue #6317 <https://github.com/pgadmin-org/pgadmin4/issues/6317>`_ - Fix an issue where queries longer than 1 minute get stuck - Container 7.1
| `Issue #6356 <https://github.com/pgadmin-org/pgadmin4/issues/6356>`_ - Fix an issue where queries get stuck with auto-completion enabled.
| `Issue #6364 <https://github.com/pgadmin-org/pgadmin4/issues/6364>`_ - Fixed Query Tool/ PSQL tool tab title not getting updated on database rename.
| `Issue #6499 <https://github.com/pgadmin-org/pgadmin4/issues/6499>`_ - Ensure that Backup, Restore, and Maintenance should work properly when pgpass file is used.
| `Issue #6501 <https://github.com/pgadmin-org/pgadmin4/issues/6501>`_ - Fix the query tool auto-complete issue on the server reconnection.
| `Issue #6502 <https://github.com/pgadmin-org/pgadmin4/issues/6502>`_ - Fix the query tool restore connection issue.
| `Issue #6509 <https://github.com/pgadmin-org/pgadmin4/issues/6509>`_ - Fix the reconnecton issue if the PostgreSQL server is restarted from the backend.
| `Issue #6514 <https://github.com/pgadmin-org/pgadmin4/issues/6514>`_ - Fix the connection and stability issues since v7, possibly related to background schema changes.
| `Issue #6515 <https://github.com/pgadmin-org/pgadmin4/issues/6515>`_ - Fixed an issue where the query tool is unable to execute a query on Postgres 10 and below versions.
| `Issue #6524 <https://github.com/pgadmin-org/pgadmin4/issues/6524>`_ - Fix the lost connection error in v7.4.
| `Issue #6537 <https://github.com/pgadmin-org/pgadmin4/issues/6537>`_ - Fixed an issue where filters are not working and query history shows empty queries.
| `Issue #6544 <https://github.com/pgadmin-org/pgadmin4/issues/6544>`_ - Fix an issue where adding a sub-folder inside a folder is not working as expected in File Manager.

View File

@ -2256,19 +2256,9 @@ class MViewNode(ViewNode, VacuumSettings):
try:
p = BatchProcess(
desc=Message(sid, data, SQL),
cmd=utility, args=args
cmd=utility, args=args, manager_obj=manager
)
manager.export_password_env(p.id)
# Check for connection timeout and if it is greater than 0
# then set the environment variable PGCONNECT_TIMEOUT.
timeout = manager.get_connection_param_value('connect_timeout')
if timeout and int(timeout) > 0:
env = dict()
env['PGCONNECT_TIMEOUT'] = str(timeout)
p.set_env_variables(server, env=env)
else:
p.set_env_variables(server)
p.start()
jid = p.id
except Exception as e:

View File

@ -15,7 +15,7 @@ import csv
import os
import sys
import psutil
from abc import ABCMeta, abstractproperty, abstractmethod
from abc import ABCMeta, abstractmethod
from datetime import datetime, timedelta
from pickle import dumps, loads
from subprocess import Popen, PIPE
@ -70,16 +70,16 @@ class IProcessDesc(metaclass=ABCMeta):
if config.SERVER_MODE:
file = self.bfile
process_file = self.bfile
try:
# check if file name is encoded with UTF-8
file = self.bfile.decode('utf-8')
process_file = self.bfile.decode('utf-8')
except Exception:
# do nothing if bfile is not encoded.
pass
path = get_complete_file_path(file)
path = file if path is None else path
path = get_complete_file_path(process_file)
path = process_file if path is None else path
if IS_WIN:
path = os.path.realpath(path)
@ -91,7 +91,7 @@ class IProcessDesc(metaclass=ABCMeta):
end = start + (len(storage_directory))
last_dir = os.path.dirname(path[end:])
else:
last_dir = file
last_dir = process_file
last_dir = replace_path_for_win(last_dir)
@ -111,12 +111,12 @@ def replace_path_for_win(last_dir=None):
return last_dir
class BatchProcess():
class BatchProcess:
def __init__(self, **kwargs):
self.id = self.desc = self.cmd = self.args = self.log_dir = \
self.stdout = self.stderr = self.stime = self.etime = \
self.ecode = None
self.ecode = self.manager_obj = None
self.env = dict()
if 'id' in kwargs:
@ -131,6 +131,9 @@ class BatchProcess():
kwargs['desc'], _cmd, kwargs['args']
)
if 'manager_obj' in kwargs:
self.manager_obj = kwargs['manager_obj']
def _retrieve_process(self, _id):
p = Process.query.filter_by(pid=_id, user_id=current_user.id).first()
@ -833,6 +836,25 @@ class BatchProcess():
if server.service:
self.env['PGSERVICE'] = server.service
if self.manager_obj:
# Set the PGPASSFILE environment variable
if self.manager_obj.connection_params and \
isinstance(self.manager_obj.connection_params, dict) and \
'passfile' in self.manager_obj.connection_params and \
self.manager_obj.connection_params['passfile']:
self.env['PGPASSFILE'] = get_complete_file_path(
self.manager_obj.connection_params['passfile'])
# Check for connection timeout and if it is greater than 0 then
# set the environment variable PGCONNECT_TIMEOUT.
timeout = self.manager_obj.get_connection_param_value(
'connect_timeout')
if timeout and int(timeout) > 0:
self.env['PGCONNECT_TIMEOUT'] = str(timeout)
# export password environment
self.manager_obj.export_password_env(self.id)
if 'env' in kwargs:
self.env.update(kwargs['env'])

View File

@ -437,7 +437,7 @@ def create_backup_objects_job(sid):
*args,
database=data['database']
),
cmd=utility, args=escaped_args
cmd=utility, args=escaped_args, manager_obj=manager
)
else:
p = BatchProcess(
@ -447,20 +447,10 @@ def create_backup_objects_job(sid):
server.id, bfile,
*args
),
cmd=utility, args=escaped_args
cmd=utility, args=escaped_args, manager_obj=manager
)
manager.export_password_env(p.id)
# Check for connection timeout and if it is greater than 0 then
# set the environment variable PGCONNECT_TIMEOUT.
timeout = manager.get_connection_param_value('connect_timeout')
if timeout and int(timeout) > 0:
env = dict()
env['PGCONNECT_TIMEOUT'] = str(timeout)
p.set_env_variables(server, env=env)
else:
p.set_env_variables(server)
p.start()
jid = p.id
except Exception as e:

View File

@ -328,15 +328,10 @@ def create_import_export_job(sid):
*args,
**io_params
),
cmd=utility, args=args
cmd=utility, args=args, manager_obj=manager
)
manager.export_password_env(p.id)
env = dict()
if manager.service:
env['PGSERVICE'] = manager.service
env['PGHOST'] = \
manager.local_bind_host if manager.use_ssh_tunnel else server.host
env['PGPORT'] = \
@ -350,14 +345,6 @@ def create_import_export_job(sid):
if value is None:
del env[key]
# Export PGPASSFILE to work with PGPASSFILE authenthification
if manager.connection_params \
and isinstance(manager.connection_params, dict):
if 'passfile' in manager.connection_params \
and manager.connection_params['passfile']:
env['PGPASSFILE'] = get_complete_file_path(
manager.connection_params['passfile'])
p.set_env_variables(server, env=env)
p.start()
jid = p.id

View File

@ -246,19 +246,9 @@ def create_maintenance_job(sid, did):
try:
p = BatchProcess(
desc=Message(server.id, data, query),
cmd=utility, args=args
cmd=utility, args=args, manager_obj=manager
)
manager.export_password_env(p.id)
# Check for connection timeout and if it is greater than 0 then
# set the environment variable PGCONNECT_TIMEOUT.
timeout = manager.get_connection_param_value('connect_timeout')
if timeout and int(timeout) > 0:
env = dict()
env['PGCONNECT_TIMEOUT'] = str(timeout)
p.set_env_variables(server, env=env)
else:
p.set_env_variables(server)
p.start()
jid = p.id
except Exception as e:

View File

@ -377,19 +377,9 @@ def create_restore_job(sid):
*args,
database=data['database']
),
cmd=utility, args=args
cmd=utility, args=args, manager_obj=manager
)
manager.export_password_env(p.id)
# Check for connection timeout and if it is greater than 0 then
# set the environment variable PGCONNECT_TIMEOUT.
timeout = manager.get_connection_param_value('connect_timeout')
if timeout and int(timeout) > 0:
env = dict()
env['PGCONNECT_TIMEOUT'] = str(timeout)
p.set_env_variables(server, env=env)
else:
p.set_env_variables(server)
p.start()
jid = p.id
except Exception as e: