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
@ -116,13 +116,20 @@ class BackupMessage(IProcessDesc):
|
|||||||
id=self.sid, user_id=current_user.id
|
id=self.sid, user_id=current_user.id
|
||||||
).first()
|
).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:
|
if self.backup_type == BACKUP.OBJECT:
|
||||||
return _(
|
return _(
|
||||||
"Backing up an object on the server '{0}' "
|
"Backing up an object on the server '{0}' "
|
||||||
"from database '{1}'..."
|
"from database '{1}'..."
|
||||||
).format(
|
).format(
|
||||||
"{0} ({1}:{2})".format(
|
"{0} ({1}:{2})".format(
|
||||||
s.name, s.host, s.port
|
s.name, host, port
|
||||||
),
|
),
|
||||||
self.database
|
self.database
|
||||||
)
|
)
|
||||||
@ -130,13 +137,13 @@ class BackupMessage(IProcessDesc):
|
|||||||
return _("Backing up the global objects on "
|
return _("Backing up the global objects on "
|
||||||
"the server '{0}'...").format(
|
"the server '{0}'...").format(
|
||||||
"{0} ({1}:{2})".format(
|
"{0} ({1}:{2})".format(
|
||||||
s.name, s.host, s.port
|
s.name, host, port
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self.backup_type == BACKUP.SERVER:
|
elif self.backup_type == BACKUP.SERVER:
|
||||||
return _("Backing up the server '{0}'...").format(
|
return _("Backing up the server '{0}'...").format(
|
||||||
"{0} ({1}:{2})".format(
|
"{0} ({1}:{2})".format(
|
||||||
s.name, s.host, s.port
|
s.name, host, port
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@ -149,6 +156,13 @@ class BackupMessage(IProcessDesc):
|
|||||||
id=self.sid, user_id=current_user.id
|
id=self.sid, user_id=current_user.id
|
||||||
).first()
|
).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 = '<div class="h5">'
|
||||||
|
|
||||||
if self.backup_type == BACKUP.OBJECT:
|
if self.backup_type == BACKUP.OBJECT:
|
||||||
@ -158,8 +172,8 @@ class BackupMessage(IProcessDesc):
|
|||||||
).format(
|
).format(
|
||||||
"{0} ({1}:{2})".format(
|
"{0} ({1}:{2})".format(
|
||||||
html.safe_str(s.name),
|
html.safe_str(s.name),
|
||||||
html.safe_str(s.host),
|
html.safe_str(host),
|
||||||
html.safe_str(s.port),
|
html.safe_str(port),
|
||||||
),
|
),
|
||||||
html.safe_str(self.database)
|
html.safe_str(self.database)
|
||||||
)
|
)
|
||||||
@ -168,16 +182,16 @@ class BackupMessage(IProcessDesc):
|
|||||||
"the server '{0}'...").format(
|
"the server '{0}'...").format(
|
||||||
"{0} ({1}:{2})".format(
|
"{0} ({1}:{2})".format(
|
||||||
html.safe_str(s.name),
|
html.safe_str(s.name),
|
||||||
html.safe_str(s.host),
|
html.safe_str(host),
|
||||||
html.safe_str(s.port)
|
html.safe_str(port)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self.backup_type == BACKUP.SERVER:
|
elif self.backup_type == BACKUP.SERVER:
|
||||||
res += _("Backing up the server '{0}'...").format(
|
res += _("Backing up the server '{0}'...").format(
|
||||||
"{0} ({1}:{2})".format(
|
"{0} ({1}:{2})".format(
|
||||||
html.safe_str(s.name),
|
html.safe_str(s.name),
|
||||||
html.safe_str(s.host),
|
html.safe_str(host),
|
||||||
html.safe_str(s.port)
|
html.safe_str(port)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@ -291,9 +305,10 @@ def create_backup_job(sid):
|
|||||||
'--file',
|
'--file',
|
||||||
backup_file,
|
backup_file,
|
||||||
'--host',
|
'--host',
|
||||||
server.host,
|
manager.local_bind_host if manager.use_ssh_tunnel else server.host,
|
||||||
'--port',
|
'--port',
|
||||||
str(server.port),
|
str(manager.local_bind_port) if manager.use_ssh_tunnel
|
||||||
|
else str(server.port),
|
||||||
'--username',
|
'--username',
|
||||||
server.username,
|
server.username,
|
||||||
'--no-password',
|
'--no-password',
|
||||||
@ -400,9 +415,10 @@ def create_backup_objects_job(sid):
|
|||||||
'--file',
|
'--file',
|
||||||
backup_file,
|
backup_file,
|
||||||
'--host',
|
'--host',
|
||||||
server.host,
|
manager.local_bind_host if manager.use_ssh_tunnel else server.host,
|
||||||
'--port',
|
'--port',
|
||||||
str(server.port),
|
str(manager.local_bind_port) if manager.use_ssh_tunnel
|
||||||
|
else str(server.port),
|
||||||
'--username',
|
'--username',
|
||||||
server.username,
|
server.username,
|
||||||
'--no-password'
|
'--no-password'
|
||||||
|
@ -224,7 +224,11 @@ def create_maintenance_job(sid, did):
|
|||||||
)
|
)
|
||||||
|
|
||||||
args = [
|
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',
|
'--username', server.username, '--dbname',
|
||||||
data['database'],
|
data['database'],
|
||||||
'--command', query
|
'--command', query
|
||||||
|
@ -93,8 +93,15 @@ class RestoreMessage(IProcessDesc):
|
|||||||
id=self.sid, user_id=current_user.id
|
id=self.sid, user_id=current_user.id
|
||||||
).first()
|
).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(
|
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):
|
def details(self, cmd, args):
|
||||||
@ -103,13 +110,20 @@ class RestoreMessage(IProcessDesc):
|
|||||||
id=self.sid, user_id=current_user.id
|
id=self.sid, user_id=current_user.id
|
||||||
).first()
|
).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 = '<div class="h5">'
|
||||||
|
|
||||||
res += html.safe_str(
|
res += html.safe_str(
|
||||||
_(
|
_(
|
||||||
"Restoring backup on the server '{0}'..."
|
"Restoring backup on the server '{0}'..."
|
||||||
).format(
|
).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
|
return False
|
||||||
|
|
||||||
args.extend([
|
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'
|
'--username', server.username, '--no-password'
|
||||||
])
|
])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user