2016-05-15 09:29:57 -05:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2018-01-05 04:42:49 -06:00
|
|
|
# Copyright (C) 2013 - 2018, The pgAdmin Development Team
|
2016-05-15 09:29:57 -05:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
"""Implements Restore Utility"""
|
|
|
|
|
2016-07-26 09:05:14 -05:00
|
|
|
import simplejson as json
|
2016-05-15 09:29:57 -05:00
|
|
|
import os
|
|
|
|
|
|
|
|
from flask import render_template, request, current_app, \
|
|
|
|
url_for, Response
|
2018-04-04 04:47:01 -05:00
|
|
|
from flask_babelex import gettext as _
|
2016-07-22 10:25:23 -05:00
|
|
|
from flask_security import login_required, current_user
|
2016-06-21 08:12:14 -05:00
|
|
|
from pgadmin.misc.bgprocess.processes import BatchProcess, IProcessDesc
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
from pgadmin.utils import PgAdminModule, get_storage_directory, html, \
|
|
|
|
fs_short_path, document_dir
|
2016-06-21 08:12:14 -05:00
|
|
|
from pgadmin.utils.ajax import make_json_response, bad_request
|
2016-05-15 09:29:57 -05:00
|
|
|
|
|
|
|
from config import PG_DEFAULT_DRIVER
|
|
|
|
from pgadmin.model import Server
|
|
|
|
|
|
|
|
# set template path for sql scripts
|
|
|
|
MODULE_NAME = 'restore'
|
|
|
|
server_info = {}
|
|
|
|
|
|
|
|
|
|
|
|
class RestoreModule(PgAdminModule):
|
|
|
|
"""
|
|
|
|
class RestoreModule(Object):
|
|
|
|
|
|
|
|
It is a utility which inherits PgAdminModule
|
|
|
|
class and define methods to load its own
|
|
|
|
javascript file.
|
|
|
|
"""
|
|
|
|
|
|
|
|
LABEL = _('Restore')
|
|
|
|
|
|
|
|
def get_own_javascripts(self):
|
|
|
|
""""
|
|
|
|
Returns:
|
|
|
|
list: js files used by this module
|
|
|
|
"""
|
|
|
|
return [{
|
|
|
|
'name': 'pgadmin.tools.restore',
|
|
|
|
'path': url_for('restore.index') + 'restore',
|
|
|
|
'when': None
|
|
|
|
}]
|
|
|
|
|
2017-06-12 22:36:42 -05:00
|
|
|
def get_exposed_url_endpoints(self):
|
|
|
|
"""
|
|
|
|
Returns:
|
|
|
|
list: URL endpoints for backup module
|
|
|
|
"""
|
|
|
|
return ['restore.create_job']
|
2016-06-21 08:21:06 -05:00
|
|
|
|
2018-01-26 10:54:21 -06:00
|
|
|
|
2016-05-15 09:29:57 -05:00
|
|
|
# Create blueprint for RestoreModule class
|
|
|
|
blueprint = RestoreModule(
|
|
|
|
MODULE_NAME, __name__, static_url_path=''
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class RestoreMessage(IProcessDesc):
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
def __init__(self, _sid, _bfile, *_args):
|
2016-05-15 09:29:57 -05:00
|
|
|
self.sid = _sid
|
|
|
|
self.bfile = _bfile
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
self.cmd = ''
|
|
|
|
|
|
|
|
def cmdArg(x):
|
|
|
|
if x:
|
|
|
|
x = html.safe_str(x)
|
|
|
|
x = x.replace('\\', '\\\\')
|
|
|
|
x = x.replace('"', '\\"')
|
|
|
|
x = x.replace('""', '\\"')
|
2018-01-26 10:54:21 -06:00
|
|
|
return ' "' + x + '"'
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
return ''
|
|
|
|
|
|
|
|
for arg in _args:
|
|
|
|
if arg and len(arg) >= 2 and arg[:2] == '--':
|
|
|
|
self.cmd += ' ' + arg
|
|
|
|
else:
|
|
|
|
self.cmd += cmdArg(arg)
|
|
|
|
|
2018-06-15 05:36:07 -05:00
|
|
|
def get_server_details(self):
|
2016-05-15 09:29:57 -05:00
|
|
|
# Fetch the server details like hostname, port, roles etc
|
|
|
|
s = Server.query.filter_by(
|
|
|
|
id=self.sid, user_id=current_user.id
|
|
|
|
).first()
|
|
|
|
|
2018-05-30 20:25:42 -05:00
|
|
|
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
|
|
|
|
|
2018-06-15 05:36:07 -05:00
|
|
|
return s.name, host, port
|
|
|
|
|
|
|
|
@property
|
|
|
|
def message(self):
|
|
|
|
name, host, port = self.get_server_details()
|
|
|
|
|
2016-06-17 08:21:14 -05:00
|
|
|
return _("Restoring backup on the server '{0}'...").format(
|
2018-06-15 05:36:07 -05:00
|
|
|
"{0} ({1}:{2})".format(name, host, port),
|
2016-05-15 09:29:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
def details(self, cmd, args):
|
2018-06-15 05:36:07 -05:00
|
|
|
name, host, port = self.get_server_details()
|
2016-05-15 09:29:57 -05:00
|
|
|
res = '<div class="h5">'
|
|
|
|
|
2016-05-16 01:28:36 -05:00
|
|
|
res += html.safe_str(
|
2016-05-15 09:29:57 -05:00
|
|
|
_(
|
2017-04-05 07:50:49 -05:00
|
|
|
"Restoring backup on the server '{0}'..."
|
2016-05-15 09:29:57 -05:00
|
|
|
).format(
|
2018-06-15 05:36:07 -05:00
|
|
|
"{0} ({1}:{2})".format(name, host, port)
|
2016-05-15 09:29:57 -05:00
|
|
|
)
|
2016-05-16 01:28:36 -05:00
|
|
|
)
|
2016-05-15 09:29:57 -05:00
|
|
|
|
|
|
|
res += '</div><div class="h5"><b>'
|
2016-05-16 01:28:36 -05:00
|
|
|
res += html.safe_str(
|
2016-05-15 09:29:57 -05:00
|
|
|
_("Running command:")
|
2016-05-16 01:28:36 -05:00
|
|
|
)
|
2016-11-18 06:05:19 -06:00
|
|
|
res += '</b><br><span class="pg-bg-cmd enable-selection">'
|
2016-05-16 01:28:36 -05:00
|
|
|
res += html.safe_str(cmd)
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
res += self.cmd
|
2016-11-18 06:05:19 -06:00
|
|
|
res += '</span></div>'
|
2016-05-15 09:29:57 -05:00
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route("/")
|
|
|
|
@login_required
|
|
|
|
def index():
|
2017-04-05 07:38:14 -05:00
|
|
|
return bad_request(errormsg=_("This URL cannot be called directly."))
|
2016-05-15 09:29:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route("/restore.js")
|
|
|
|
@login_required
|
|
|
|
def script():
|
|
|
|
"""render own javascript"""
|
|
|
|
return Response(
|
|
|
|
response=render_template(
|
|
|
|
"restore/js/restore.js", _=_
|
|
|
|
),
|
|
|
|
status=200,
|
|
|
|
mimetype="application/javascript"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
def filename_with_file_manager_path(_file):
|
2016-05-15 09:29:57 -05:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
file: File name returned from client file manager
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
Filename to use for backup with full path taken from preference
|
|
|
|
"""
|
|
|
|
# Set file manager directory from preference
|
|
|
|
storage_dir = get_storage_directory()
|
|
|
|
|
|
|
|
if storage_dir:
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
_file = os.path.join(storage_dir, _file.lstrip(u'/').lstrip(u'\\'))
|
|
|
|
elif not os.path.isabs(_file):
|
|
|
|
_file = os.path.join(document_dir(), _file)
|
|
|
|
|
2018-06-29 09:14:37 -05:00
|
|
|
if not os.path.isfile(_file) and not os.path.exists(_file):
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
return None
|
2016-05-15 09:29:57 -05:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
return fs_short_path(_file)
|
2016-05-15 09:29:57 -05:00
|
|
|
|
|
|
|
|
2017-06-12 22:36:42 -05:00
|
|
|
@blueprint.route('/job/<int:sid>', methods=['POST'], endpoint='create_job')
|
2016-05-15 09:29:57 -05:00
|
|
|
@login_required
|
|
|
|
def create_restore_job(sid):
|
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
sid: Server ID
|
|
|
|
|
|
|
|
Creates a new job for restore task
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
None
|
|
|
|
"""
|
|
|
|
if request.form:
|
|
|
|
# Convert ImmutableDict to dict
|
|
|
|
data = dict(request.form)
|
2016-07-26 09:05:14 -05:00
|
|
|
data = json.loads(data['data'][0], encoding='utf-8')
|
2016-05-15 09:29:57 -05:00
|
|
|
else:
|
2016-07-26 09:05:14 -05:00
|
|
|
data = json.loads(request.data, encoding='utf-8')
|
2016-05-15 09:29:57 -05:00
|
|
|
|
2017-03-09 03:54:55 -06:00
|
|
|
try:
|
|
|
|
_file = filename_with_file_manager_path(data['file'])
|
|
|
|
except Exception as e:
|
|
|
|
return bad_request(errormsg=str(e))
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
|
|
|
|
if _file is None:
|
|
|
|
return make_json_response(
|
2018-06-15 05:36:07 -05:00
|
|
|
status=410,
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
success=0,
|
2017-11-01 10:18:07 -05:00
|
|
|
errormsg=_("File could not be found.")
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
)
|
2016-05-15 09:29:57 -05:00
|
|
|
|
|
|
|
# Fetch the server details like hostname, port, roles etc
|
|
|
|
server = Server.query.filter_by(
|
|
|
|
id=sid
|
|
|
|
).first()
|
|
|
|
|
|
|
|
if server is None:
|
|
|
|
return make_json_response(
|
|
|
|
success=0,
|
2016-06-17 16:05:49 -05:00
|
|
|
errormsg=_("Could not find the specified server.")
|
2016-05-15 09:29:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
# To fetch MetaData for the server
|
|
|
|
from pgadmin.utils.driver import get_driver
|
|
|
|
|
|
|
|
driver = get_driver(PG_DEFAULT_DRIVER)
|
|
|
|
manager = driver.connection_manager(server.id)
|
|
|
|
conn = manager.connection()
|
|
|
|
connected = conn.connected()
|
|
|
|
|
|
|
|
if not connected:
|
|
|
|
return make_json_response(
|
|
|
|
success=0,
|
2016-06-17 08:21:14 -05:00
|
|
|
errormsg=_("Please connect to the server first.")
|
2016-05-15 09:29:57 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
utility = manager.utility('restore')
|
|
|
|
|
|
|
|
args = []
|
|
|
|
|
|
|
|
if 'list' in data:
|
|
|
|
args.append('--list')
|
|
|
|
else:
|
|
|
|
def set_param(key, param):
|
|
|
|
if key in data and data[key]:
|
|
|
|
args.append(param)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def set_value(key, param, value):
|
|
|
|
if key in data:
|
|
|
|
if value:
|
2016-06-17 08:01:30 -05:00
|
|
|
if value is True and data[key]:
|
|
|
|
args.append(param)
|
2016-05-15 09:29:57 -05:00
|
|
|
args.append(data[key])
|
|
|
|
else:
|
2016-06-17 08:01:30 -05:00
|
|
|
args.append(param)
|
2016-05-15 09:29:57 -05:00
|
|
|
args.append(value)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def set_multiple(key, param, with_schema=True):
|
|
|
|
if key in data:
|
|
|
|
if len(data[key]) > 0:
|
|
|
|
if with_schema:
|
2016-06-17 08:01:30 -05:00
|
|
|
# TODO:// This is temporary
|
|
|
|
# Once object tree is implemented then we will use
|
|
|
|
# list of tuples 'else' part
|
|
|
|
if isinstance(data[key], list):
|
|
|
|
s, t = data[key]
|
2016-05-15 09:29:57 -05:00
|
|
|
args.extend([
|
|
|
|
param,
|
|
|
|
driver.qtIdent(
|
|
|
|
conn, s
|
2016-06-17 08:01:30 -05:00
|
|
|
) + '.' + driver.qtIdent(conn, t)
|
2016-05-15 09:29:57 -05:00
|
|
|
])
|
2016-06-17 08:01:30 -05:00
|
|
|
else:
|
|
|
|
for s, o in data[key]:
|
|
|
|
args.extend([
|
|
|
|
param,
|
|
|
|
driver.qtIdent(
|
|
|
|
conn, s
|
|
|
|
) + '.' + driver.qtIdent(conn, o)
|
|
|
|
])
|
2016-05-15 09:29:57 -05:00
|
|
|
else:
|
|
|
|
for o in data[key]:
|
|
|
|
args.extend([param, o])
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
args.extend([
|
2018-05-30 20:25:42 -05:00
|
|
|
'--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),
|
2016-05-15 09:29:57 -05:00
|
|
|
'--username', server.username, '--no-password'
|
|
|
|
])
|
|
|
|
|
|
|
|
set_value('role', '--role', True)
|
|
|
|
set_value('database', '--dbname', True)
|
|
|
|
|
|
|
|
if data['format'] == 'directory':
|
2016-06-17 08:01:30 -05:00
|
|
|
args.extend(['--format=d'])
|
2016-05-15 09:29:57 -05:00
|
|
|
|
2018-07-02 09:52:15 -05:00
|
|
|
set_param('pre_data', '--section=pre-data')
|
|
|
|
set_param('data', '--section=data')
|
|
|
|
set_param('post_data', '--section=post-data')
|
2016-05-15 09:29:57 -05:00
|
|
|
|
|
|
|
if not set_param('only_data', '--data-only'):
|
|
|
|
set_param('dns_owner', '--no-owner')
|
2018-07-02 09:52:15 -05:00
|
|
|
set_param('dns_privilege', '--no-privileges')
|
2016-05-15 09:29:57 -05:00
|
|
|
set_param('dns_tablespace', '--no-tablespaces')
|
|
|
|
|
|
|
|
if not set_param('only_schema', '--schema-only'):
|
|
|
|
set_param('disable_trigger', '--disable-triggers')
|
|
|
|
|
|
|
|
set_param('include_create_database', '--create')
|
|
|
|
set_param('clean', '--clean')
|
|
|
|
set_param('single_transaction', '--single-transaction')
|
2018-07-02 09:52:15 -05:00
|
|
|
set_param('no_data_fail_table', '--no-data-for-failed-tables')
|
|
|
|
set_param('use_set_session_auth', '--use-set-session-authorization')
|
2016-05-15 09:29:57 -05:00
|
|
|
set_param('exit_on_error', '--exit-on-error')
|
|
|
|
|
|
|
|
set_value('no_of_jobs', '--jobs', True)
|
|
|
|
set_param('verbose', '--verbose')
|
|
|
|
|
|
|
|
set_multiple('schemas', '--schema', False)
|
2017-03-31 02:33:25 -05:00
|
|
|
set_multiple('tables', '--table', False)
|
|
|
|
set_multiple('functions', '--function', False)
|
|
|
|
set_multiple('triggers', '--trigger', False)
|
|
|
|
set_multiple('trigger_funcs', '--function', False)
|
|
|
|
set_multiple('indexes', '--index', False)
|
2016-05-15 09:29:57 -05:00
|
|
|
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
args.append(fs_short_path(_file))
|
2016-05-15 09:29:57 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
p = BatchProcess(
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
desc=RestoreMessage(
|
|
|
|
sid,
|
|
|
|
data['file'].encode('utf-8') if hasattr(
|
|
|
|
data['file'], 'encode'
|
|
|
|
) else data['file'],
|
2018-01-26 10:54:21 -06:00
|
|
|
*args
|
Resolved quite a few file-system encoding/decoding related cases.
In order to resolve the non-ascii characters in path (in user directory,
storage path, etc) on windows, we have converted the path into the
short-path, so that - we don't need to deal with the encoding issues
(specially with Python 2).
We've resolved majority of the issues with this patch.
We still need couple issues to resolve after this in the same area.
TODO
* Add better support for non-ascii characters in the database name on
windows with Python 3
* Improve the messages created after the background processes by
different modules (such as Backup, Restore, Import/Export, etc.),
which does not show short-paths, and xml representable characters for
non-ascii characters, when found in the database objects, and the file
PATH.
Fixes #2174, #1797, #2166, #1940
Initial patch by: Surinder Kumar
Reviewed by: Murtuza Zabuawala
2017-03-07 04:00:57 -06:00
|
|
|
),
|
2016-05-15 09:29:57 -05:00
|
|
|
cmd=utility, args=args
|
|
|
|
)
|
2016-05-15 11:59:14 -05:00
|
|
|
manager.export_password_env(p.id)
|
2018-06-19 18:58:46 -05:00
|
|
|
# Check for connection timeout and if it is greater than 0 then
|
|
|
|
# set the environment variable PGCONNECT_TIMEOUT.
|
|
|
|
if manager.connect_timeout > 0:
|
|
|
|
env = dict()
|
|
|
|
env['PGCONNECT_TIMEOUT'] = str(manager.connect_timeout)
|
|
|
|
p.set_env_variables(server, env=env)
|
|
|
|
else:
|
|
|
|
p.set_env_variables(server)
|
|
|
|
|
2016-05-15 09:29:57 -05:00
|
|
|
p.start()
|
|
|
|
jid = p.id
|
|
|
|
except Exception as e:
|
|
|
|
current_app.logger.exception(e)
|
|
|
|
return make_json_response(
|
|
|
|
status=410,
|
|
|
|
success=0,
|
|
|
|
errormsg=str(e)
|
|
|
|
)
|
|
|
|
# Return response
|
|
|
|
return make_json_response(
|
|
|
|
data={'job_id': jid, 'Success': 1}
|
|
|
|
)
|
|
|
|
|
2016-06-21 08:21:06 -05:00
|
|
|
|
2016-05-15 09:29:57 -05:00
|
|
|
"""
|
|
|
|
TODO://
|
|
|
|
Add browser tree
|
|
|
|
"""
|