|
@@ -102,7 +102,7 @@ def make_database_dump_pattern(
|
|
return dump.make_database_dump_filename(make_dump_path(location_config), name, hostname='*')
|
|
return dump.make_database_dump_filename(make_dump_path(location_config), name, hostname='*')
|
|
|
|
|
|
|
|
|
|
-def restore_database_dump(database_config, log_prefix, location_config, dry_run, extract_process):
|
|
|
|
|
|
+def restore_database_dump(database_config, log_prefix, location_config, dry_run, extract_process, connection_params):
|
|
'''
|
|
'''
|
|
Restore the given MongoDB database from an extract stream. The database is supplied as a
|
|
Restore the given MongoDB database from an extract stream. The database is supplied as a
|
|
one-element sequence containing a dict describing the database, as per the configuration schema.
|
|
one-element sequence containing a dict describing the database, as per the configuration schema.
|
|
@@ -122,7 +122,7 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run,
|
|
dump_filename = dump.make_database_dump_filename(
|
|
dump_filename = dump.make_database_dump_filename(
|
|
make_dump_path(location_config), database['name'], database.get('hostname')
|
|
make_dump_path(location_config), database['name'], database.get('hostname')
|
|
)
|
|
)
|
|
- restore_command = build_restore_command(extract_process, database, dump_filename)
|
|
|
|
|
|
+ restore_command = build_restore_command(extract_process, database, dump_filename, connection_params)
|
|
|
|
|
|
logger.debug(f"{log_prefix}: Restoring MongoDB database {database['name']}{dry_run_label}")
|
|
logger.debug(f"{log_prefix}: Restoring MongoDB database {database['name']}{dry_run_label}")
|
|
if dry_run:
|
|
if dry_run:
|
|
@@ -138,10 +138,15 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run,
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
-def build_restore_command(extract_process, database, dump_filename):
|
|
|
|
|
|
+def build_restore_command(extract_process, database, dump_filename, connection_params):
|
|
'''
|
|
'''
|
|
Return the mongorestore command from a single database configuration.
|
|
Return the mongorestore command from a single database configuration.
|
|
'''
|
|
'''
|
|
|
|
+ hostname = connection_params['hostname'] or database.get('restore_hostname', database.get('hostname'))
|
|
|
|
+ port = str(connection_params['port'] or database.get('restore_port', database.get('port')))
|
|
|
|
+ username = connection_params['username'] or database.get('restore_username', database.get('username'))
|
|
|
|
+ password = connection_params['password'] or database.get('restore_password', database.get('password'))
|
|
|
|
+
|
|
command = ['mongorestore']
|
|
command = ['mongorestore']
|
|
if extract_process:
|
|
if extract_process:
|
|
command.append('--archive')
|
|
command.append('--archive')
|
|
@@ -149,14 +154,14 @@ def build_restore_command(extract_process, database, dump_filename):
|
|
command.extend(('--dir', dump_filename))
|
|
command.extend(('--dir', dump_filename))
|
|
if database['name'] != 'all':
|
|
if database['name'] != 'all':
|
|
command.extend(('--drop', '--db', database['name']))
|
|
command.extend(('--drop', '--db', database['name']))
|
|
- if 'hostname' in database:
|
|
|
|
- command.extend(('--host', database['hostname']))
|
|
|
|
- if 'port' in database:
|
|
|
|
- command.extend(('--port', str(database['port'])))
|
|
|
|
- if 'username' in database:
|
|
|
|
- command.extend(('--username', database['username']))
|
|
|
|
- if 'password' in database:
|
|
|
|
- command.extend(('--password', database['password']))
|
|
|
|
|
|
+ if hostname:
|
|
|
|
+ command.extend(('--host', hostname))
|
|
|
|
+ if port:
|
|
|
|
+ command.extend(('--port', str(port)))
|
|
|
|
+ if username:
|
|
|
|
+ command.extend(('--username', username))
|
|
|
|
+ if password:
|
|
|
|
+ command.extend(('--password', password))
|
|
if 'authentication_database' in database:
|
|
if 'authentication_database' in database:
|
|
command.extend(('--authenticationDatabase', database['authentication_database']))
|
|
command.extend(('--authenticationDatabase', database['authentication_database']))
|
|
if 'restore_options' in database:
|
|
if 'restore_options' in database:
|