mysql support

This commit is contained in:
Divyansh Singh 2023-06-15 01:47:46 +05:30
parent 67f4d43aec
commit 205e5b1524
2 changed files with 13 additions and 10 deletions

View file

@ -185,7 +185,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 MySQL/MariaDB database from an extract stream. The database is supplied as a Restore the given MySQL/MariaDB 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.
@ -199,15 +199,21 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run,
raise ValueError('The database configuration value is invalid') raise ValueError('The database configuration value is invalid')
database = database_config[0] database = database_config[0]
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'))
restore_command = ( restore_command = (
('mysql', '--batch') ('mysql', '--batch')
+ (tuple(database['restore_options'].split(' ')) if 'restore_options' in database else ()) + (tuple(database['restore_options'].split(' ')) if 'restore_options' in database else ())
+ (('--host', database['hostname']) if 'hostname' in database else ()) + (('--host', database['hostname']) if hostname else ())
+ (('--port', str(database['port'])) if 'port' in database else ()) + (('--port', str(database['port'])) if port else ())
+ (('--protocol', 'tcp') if 'hostname' in database or 'port' in database else ()) + (('--protocol', 'tcp') if hostname or port else ())
+ (('--user', database['username']) if 'username' in database else ()) + (('--user', database['username']) if username else ())
) )
extra_environment = {'MYSQL_PWD': database['password']} if 'password' in database else None extra_environment = {'MYSQL_PWD': password} if password else None
logger.debug(f"{log_prefix}: Restoring MySQL database {database['name']}{dry_run_label}") logger.debug(f"{log_prefix}: Restoring MySQL database {database['name']}{dry_run_label}")
if dry_run: if dry_run:

View file

@ -28,11 +28,9 @@ def make_extra_environment(database, restore_connection_params=None):
If restore connection params are given, this is for a restore operation. If restore connection params are given, this is for a restore operation.
''' '''
extra = dict() extra = dict()
if 'password' in database:
extra['PGPASSWORD'] = database['password']
try: try:
extra['PGPASSWORD'] = restore_connection_params.get('password') or database['restore_password'] extra['PGPASSWORD'] = restore_connection_params.get('password') or database['restore_password'] or database['password']
except (AttributeError, KeyError): except (AttributeError, KeyError):
pass pass
@ -223,7 +221,6 @@ def restore_database_dump(database_config, log_prefix, location_config, dry_run,
hostname = connection_params['hostname'] or database.get('restore_hostname', database.get('hostname')) 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'))) 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')) username = connection_params['username'] or database.get('restore_username', database.get('username'))
password = connection_params['password'] or database.get('restore_password', database.get('password'))
all_databases = bool(database['name'] == 'all') all_databases = bool(database['name'] == 'all')
dump_filename = dump.make_database_dump_filename( dump_filename = dump.make_database_dump_filename(