mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Ensure backup/restore/maintenance work via SSH tunnels. Fixes #3355
This commit is contained in:
parent
b00931407e
commit
2b4605a9d3
web/pgadmin/tools
@ -116,13 +116,20 @@ class BackupMessage(IProcessDesc):
|
||||
id=self.sid, user_id=current_user.id
|
||||
).first()
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||
manager = driver.connection_manager(self.sid)
|
||||
|
||||
host = manager.local_bind_host if manager.use_ssh_tunnel else s.host
|
||||
port = manager.local_bind_port if manager.use_ssh_tunnel else s.port
|
||||
|
||||
if self.backup_type == BACKUP.OBJECT:
|
||||
return _(
|
||||
"Backing up an object on the server '{0}' "
|
||||
"from database '{1}'..."
|
||||
).format(
|
||||
"{0} ({1}:{2})".format(
|
||||
s.name, s.host, s.port
|
||||
s.name, host, port
|
||||
),
|
||||
self.database
|
||||
)
|
||||
@ -130,13 +137,13 @@ class BackupMessage(IProcessDesc):
|
||||
return _("Backing up the global objects on "
|
||||
"the server '{0}'...").format(
|
||||
"{0} ({1}:{2})".format(
|
||||
s.name, s.host, s.port
|
||||
s.name, host, port
|
||||
)
|
||||
)
|
||||
elif self.backup_type == BACKUP.SERVER:
|
||||
return _("Backing up the server '{0}'...").format(
|
||||
"{0} ({1}:{2})".format(
|
||||
s.name, s.host, s.port
|
||||
s.name, host, port
|
||||
)
|
||||
)
|
||||
else:
|
||||
@ -149,6 +156,13 @@ class BackupMessage(IProcessDesc):
|
||||
id=self.sid, user_id=current_user.id
|
||||
).first()
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||
manager = driver.connection_manager(self.sid)
|
||||
|
||||
host = manager.local_bind_host if manager.use_ssh_tunnel else s.host
|
||||
port = manager.local_bind_port if manager.use_ssh_tunnel else s.port
|
||||
|
||||
res = '<div class="h5">'
|
||||
|
||||
if self.backup_type == BACKUP.OBJECT:
|
||||
@ -158,8 +172,8 @@ class BackupMessage(IProcessDesc):
|
||||
).format(
|
||||
"{0} ({1}:{2})".format(
|
||||
html.safe_str(s.name),
|
||||
html.safe_str(s.host),
|
||||
html.safe_str(s.port),
|
||||
html.safe_str(host),
|
||||
html.safe_str(port),
|
||||
),
|
||||
html.safe_str(self.database)
|
||||
)
|
||||
@ -168,16 +182,16 @@ class BackupMessage(IProcessDesc):
|
||||
"the server '{0}'...").format(
|
||||
"{0} ({1}:{2})".format(
|
||||
html.safe_str(s.name),
|
||||
html.safe_str(s.host),
|
||||
html.safe_str(s.port)
|
||||
html.safe_str(host),
|
||||
html.safe_str(port)
|
||||
)
|
||||
)
|
||||
elif self.backup_type == BACKUP.SERVER:
|
||||
res += _("Backing up the server '{0}'...").format(
|
||||
"{0} ({1}:{2})".format(
|
||||
html.safe_str(s.name),
|
||||
html.safe_str(s.host),
|
||||
html.safe_str(s.port)
|
||||
html.safe_str(host),
|
||||
html.safe_str(port)
|
||||
)
|
||||
)
|
||||
else:
|
||||
@ -291,9 +305,10 @@ def create_backup_job(sid):
|
||||
'--file',
|
||||
backup_file,
|
||||
'--host',
|
||||
server.host,
|
||||
manager.local_bind_host if manager.use_ssh_tunnel else server.host,
|
||||
'--port',
|
||||
str(server.port),
|
||||
str(manager.local_bind_port) if manager.use_ssh_tunnel
|
||||
else str(server.port),
|
||||
'--username',
|
||||
server.username,
|
||||
'--no-password',
|
||||
@ -400,9 +415,10 @@ def create_backup_objects_job(sid):
|
||||
'--file',
|
||||
backup_file,
|
||||
'--host',
|
||||
server.host,
|
||||
manager.local_bind_host if manager.use_ssh_tunnel else server.host,
|
||||
'--port',
|
||||
str(server.port),
|
||||
str(manager.local_bind_port) if manager.use_ssh_tunnel
|
||||
else str(server.port),
|
||||
'--username',
|
||||
server.username,
|
||||
'--no-password'
|
||||
|
@ -224,7 +224,11 @@ def create_maintenance_job(sid, did):
|
||||
)
|
||||
|
||||
args = [
|
||||
'--host', server.host, '--port', str(server.port),
|
||||
'--host',
|
||||
manager.local_bind_host if manager.use_ssh_tunnel else server.host,
|
||||
'--port',
|
||||
str(manager.local_bind_port) if manager.use_ssh_tunnel
|
||||
else str(server.port),
|
||||
'--username', server.username, '--dbname',
|
||||
data['database'],
|
||||
'--command', query
|
||||
|
@ -93,8 +93,15 @@ class RestoreMessage(IProcessDesc):
|
||||
id=self.sid, user_id=current_user.id
|
||||
).first()
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||
manager = driver.connection_manager(self.sid)
|
||||
|
||||
host = manager.local_bind_host if manager.use_ssh_tunnel else s.host
|
||||
port = manager.local_bind_port if manager.use_ssh_tunnel else s.port
|
||||
|
||||
return _("Restoring backup on the server '{0}'...").format(
|
||||
"{0} ({1}:{2})".format(s.name, s.host, s.port),
|
||||
"{0} ({1}:{2})".format(s.name, host, port),
|
||||
)
|
||||
|
||||
def details(self, cmd, args):
|
||||
@ -103,13 +110,20 @@ class RestoreMessage(IProcessDesc):
|
||||
id=self.sid, user_id=current_user.id
|
||||
).first()
|
||||
|
||||
from pgadmin.utils.driver import get_driver
|
||||
driver = get_driver(PG_DEFAULT_DRIVER)
|
||||
manager = driver.connection_manager(self.sid)
|
||||
|
||||
host = manager.local_bind_host if manager.use_ssh_tunnel else s.host
|
||||
port = manager.local_bind_port if manager.use_ssh_tunnel else s.port
|
||||
|
||||
res = '<div class="h5">'
|
||||
|
||||
res += html.safe_str(
|
||||
_(
|
||||
"Restoring backup on the server '{0}'..."
|
||||
).format(
|
||||
"{0} ({1}:{2})".format(s.name, s.host, s.port)
|
||||
"{0} ({1}:{2})".format(s.name, host, port)
|
||||
)
|
||||
)
|
||||
|
||||
@ -276,7 +290,11 @@ def create_restore_job(sid):
|
||||
return False
|
||||
|
||||
args.extend([
|
||||
'--host', server.host, '--port', str(server.port),
|
||||
'--host',
|
||||
manager.local_bind_host if manager.use_ssh_tunnel else server.host,
|
||||
'--port',
|
||||
str(manager.local_bind_port) if manager.use_ssh_tunnel
|
||||
else str(server.port),
|
||||
'--username', server.username, '--no-password'
|
||||
])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user