Skip to content

Commit

Permalink
[SQL] Change az sql log-replay stop to drop DB only if it was creat…
Browse files Browse the repository at this point in the history
…ed with LRS (#22939)

* Fix stop log replay cmd

* Update src/azure-cli/azure/cli/command_modules/sql/custom.py

* formatting
  • Loading branch information
ostojicb authored Jul 26, 2022
1 parent d27b88d commit 7f5f78e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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 @@ -827,7 +827,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 @@ -5183,6 +5184,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.')

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

0 comments on commit 7f5f78e

Please sign in to comment.