Skip to content
Merged
39 changes: 38 additions & 1 deletion src/azure-cli/azure/cli/command_modules/sql/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,12 +601,24 @@
text: az sql midb list -g mygroup --mi myinstance
"""

helps['sql midb list-deleted'] = """
type: command
short-summary: List restorable deleted managed databases.
examples:
- name: List all restorable deleted managed databases on Managed Instance .
text: az sql midb list-deleted -g mygroup --mi myinstance
"""

helps['sql midb restore'] = """
type: command
short-summary: Restore a managed database.
examples:
- name: Restore a managed database using Point in time restore
- name: Restore a live managed database using Point in time restore
text: az sql midb restore -g mygroup --mi myinstance -n mymanageddb --dest-name targetmidb --time "2018-05-20T05:34:22"
- name: Restore a dropped managed database using Point in time restore
text: az sql midb restore -g mygroup --mi myinstance -n mymanageddb --dest-name targetmidb --time "2018-05-20T05:34:22" --deleted-time "2018-05-20T05:34:22"
- name: Restore a live managed database from another instance using Point in time restore
text: az sql midb restore -g mygroup --mi myinstance -n mymanageddb --dest-name targetmidb --time "2018-05-20T05:34:22" --dest-mi targetmi --dest-resource-group targetrg
"""

helps['sql midb show'] = """
Expand All @@ -617,6 +629,31 @@
text: az sql midb show -g mygroup --mi myinstance -n mymanageddb
"""

helps['sql midb short-term-retention-policy'] = """
type: group
short-summary: Manage SQL managed instance database backup short term retention policy.
"""

helps['sql midb short-term-retention-policy set'] = """
type: command
short-summary: Update short term retention for automated backups on a single database.
examples:
- name: Set backup short term retention for live managed database.
text: az sql midb short-term-retention-policy set -g mygroup --mi myinstance -n mymanageddb --retention-days retentionindays
- name: Set backup short term retention for dropped managed database.
text: az sql midb short-term-retention-policy set -g mygroup --mi myinstance -n mymanageddb --deleted-time "2018-05-20T05:34:22" --retention-days retentionindays
"""

helps['sql midb short-term-retention-policy show'] = """
type: command
short-summary: Show short term retention for automated backups on a single database.
examples:
- name: Shows backup short term retention for live managed database.
text: az sql midb short-term-retention-policy show -g mygroup --mi myinstance -n mymanageddb
- name: Show backup short term retention for dropped managed database.
text: az sql midb short-term-retention-policy show -g mygroup --mi myinstance -n mymanageddb --deleted-time "2018-05-20T05:34:22"
"""

helps['sql server'] = """
type: group
short-summary: Manage SQL servers.
Expand Down
31 changes: 29 additions & 2 deletions src/azure-cli/azure/cli/command_modules/sql/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1419,11 +1419,17 @@ def _configure_security_policy_storage_params(arg_ctx):
with self.argument_context('sql midb restore') as c:
create_args_for_complex_type(
c, 'parameters', ManagedDatabase, [
'deleted_time',
'target_managed_database_name',
'target_managed_instance_name',
'restore_point_in_time'
])

c.argument('deleted_time',
options_list=['--deleted-time'],
help='If specified, restore from a deleted database instead of from an existing database.'
' Must match the deleted time of a deleted database on the source Managed Instance.')

c.argument('target_managed_database_name',
options_list=['--dest-name'],
required=True,
Expand All @@ -1450,8 +1456,29 @@ def _configure_security_policy_storage_params(arg_ctx):
' new database. Must be greater than or equal to the source database\'s'
' earliestRestoreDate value. ' + time_format_help)

with self.argument_context('sql midb list') as c:
c.argument('managed_instance_name', id_part=None)
with self.argument_context('sql midb short-term-retention-policy set') as c:
create_args_for_complex_type(
c, 'parameters', ManagedDatabase, [
'deleted_time',
'retention_days'
])

c.argument('deleted_time',
options_list=['--deleted-time'],
help='If specified, updates retention days for a deleted database, instead of an existing database.'
'Must match the deleted time of a deleted database on the source Managed Instance.')

c.argument('retention_days',
options_list=['--retention-days'],
required=True,
help='New backup short term retention policy in days.'
'Valid policy for live database is 7-35 days, valid policy for dropped databases is 0-35 days.')

with self.argument_context('sql midb short-term-retention-policy show') as c:
c.argument('deleted_time',
options_list=['--deleted-time'],
help='If specified, shows retention days for a deleted database, instead of an existing database.'
'Must match the deleted time of a deleted database on the source Managed Instance.')

###############################################
# sql virtual cluster #
Expand Down
12 changes: 12 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def get_sql_restorable_dropped_databases_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).restorable_dropped_databases


def get_sql_restorable_dropped_managed_databases_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).restorable_dropped_managed_databases


def get_sql_server_azure_ad_administrators_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).server_azure_ad_administrators

Expand Down Expand Up @@ -144,6 +148,14 @@ def get_sql_managed_databases_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).managed_databases


def get_sql_managed_backup_short_term_retention_policies_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).managed_backup_short_term_retention_policies


def get_sql_restorable_dropped_database_managed_backup_short_term_retention_policies_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).managed_restorable_dropped_database_backup_short_term_retention_policies


def get_sql_virtual_clusters_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).virtual_clusters

Expand Down
23 changes: 23 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@
get_sql_failover_groups_operations,
get_sql_firewall_rules_operations,
get_sql_managed_databases_operations,
get_sql_managed_backup_short_term_retention_policies_operations,
get_sql_managed_instance_azure_ad_administrators_operations,
get_sql_managed_instance_encryption_protectors_operations,
get_sql_managed_instance_keys_operations,
get_sql_managed_instances_operations,
get_sql_replication_links_operations,
get_sql_restorable_dropped_databases_operations,
get_sql_restorable_dropped_managed_databases_operations,
get_sql_server_connection_policies_operations,
get_sql_server_dns_aliases_operations,
get_sql_server_keys_operations,
Expand Down Expand Up @@ -220,6 +222,16 @@ def load_command_table(self, _):

g.command('list-deleted', 'list_by_server')

restorable_dropped_managed_databases_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#RestorableDroppedManagedDatabasesOperations.{}',
client_factory=get_sql_restorable_dropped_managed_databases_operations)

with self.command_group('sql midb',
restorable_dropped_managed_databases_operations,
client_factory=get_sql_restorable_dropped_managed_databases_operations) as g:

g.command('list-deleted', 'list_by_instance')

database_blob_auditing_policies_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#DatabaseBlobAuditingPoliciesOperations.{}',
client_factory=get_sql_database_blob_auditing_policies_operations)
Expand Down Expand Up @@ -547,6 +559,17 @@ def load_command_table(self, _):
g.command('list', 'list_by_instance')
g.command('delete', 'delete', confirmation=True, supports_no_wait=True)

managed_backup_short_term_retention_policies_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#ManagedBackupShortTermRetentionPoliciesOperations.{}',
client_factory=get_sql_managed_backup_short_term_retention_policies_operations)

with self.command_group('sql midb short-term-retention-policy',
managed_backup_short_term_retention_policies_operations,
client_factory=get_sql_managed_backup_short_term_retention_policies_operations) as g:

g.custom_command('set', 'update_short_term_retention_mi', supports_no_wait=True)
g.custom_command('show', 'get_short_term_retention_mi')

###############################################
# sql virtual cluster #
###############################################
Expand Down
Loading