Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SQL] az sql log-replay stop: Drop DB only if it was created with LRS #22939

Merged
merged 4 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/sql/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ def load_command_table(self, _):
managed_databases_operations,
client_factory=get_sql_managed_databases_operations) as g:
g.custom_command('start', 'managed_db_log_replay_start', supports_no_wait=True)
g.command('stop', 'begin_delete', confirmation=True, supports_no_wait=True)
g.custom_command('stop', 'managed_db_log_replay_stop', confirmation=True, supports_no_wait=True)
g.custom_command('complete', 'managed_db_log_replay_complete_restore')
g.wait_command('wait')

Expand Down
32 changes: 32 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
get_sql_servers_operations,
get_sql_managed_instances_operations,
get_sql_restorable_dropped_database_managed_backup_short_term_retention_policies_operations,
get_sql_managed_database_restore_details_operations,
)


Expand Down Expand Up @@ -5173,6 +5174,37 @@ def managed_db_log_replay_start(
parameters=kwargs)


def managed_db_log_replay_stop(
cmd,
client,
database_name,
managed_instance_name,
resource_group_name):
'''
Stop log replay restore.
'''

restore_details_client = get_sql_managed_database_restore_details_operations(cmd.cli_ctx, None)

# Determine if managed DB was created using log replay service, raise exception if not
restore_details = restore_details_client.get(
database_name=database_name,
managed_instance_name=managed_instance_name,
resource_group_name=resource_group_name,
restore_details_name=RestoreDetailsName.DEFAULT)

# If type is present, it must be lrsrestore in order to proceed with stop-log-replay
if (hasattr(restore_details, 'type_properties_type') and restore_details.type_properties_type.lower() != 'lrsrestore'):
raise CLIError(
f'Cannot stop the log replay as database {database_name} on the instance {managed_instance_name} '
f'in the resource group {resource_group_name} was not created with log replay service.')
evelyn-ys marked this conversation as resolved.
Show resolved Hide resolved

return client.begin_delete(
database_name=database_name,
managed_instance_name=managed_instance_name,
resource_group_name=resource_group_name)


def managed_db_log_replay_complete_restore(
client,
database_name,
Expand Down