Skip to content
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
de11560
added ltr mi policy to commands/params
xaliciayang Mar 22, 2020
3d2172d
add custom commands/params for ltr mi backup APIs; updated params for…
xaliciayang Mar 23, 2020
197c900
added LTR Policy tests
xaliciayang Mar 23, 2020
7fca0f7
fixing pylint
xaliciayang Mar 23, 2020
233c779
fix pylint
xaliciayang Mar 23, 2020
8932742
updated commands
xaliciayang Mar 24, 2020
0887b12
fix setting location for ltr restore
xaliciayang Mar 24, 2020
32bdfd3
adding test cases for all LTR MI functions
xaliciayang Mar 24, 2020
756738c
removing unrelated files
xaliciayang Mar 24, 2020
59e19c4
added help, some fixes to parameters
xaliciayang Mar 25, 2020
9f9aee5
edit test cases
xaliciayang Mar 25, 2020
e3a393d
removed print line
xaliciayang Mar 25, 2020
0ec14bb
removing unneeded files; removing whitespace fixes
xaliciayang Mar 25, 2020
3f45a78
whitespace fixing; adding some details to params
xaliciayang Mar 25, 2020
bd9f71c
updating help/params, some typos
xaliciayang Mar 25, 2020
2382a1f
updated help
xaliciayang Mar 25, 2020
4ebae7b
more changes to help
xaliciayang Mar 25, 2020
60a1cfa
recording file
xaliciayang Mar 26, 2020
01d1bb1
switch back resource names
xaliciayang Mar 26, 2020
d0d2f6a
test resource names
xaliciayang Mar 26, 2020
dcf401f
fix a db name
xaliciayang Mar 27, 2020
b5b74a0
shorten 'long-term-retention' and '--only-latest-per-database'
xaliciayang Mar 30, 2020
72989c1
updated recording
xaliciayang Mar 30, 2020
ccf3da9
- consolidate all list-by-* to list
xaliciayang Mar 31, 2020
561da9f
remove ltr restore from help
xaliciayang Mar 31, 2020
eb981f1
updated test recording for ltr
xaliciayang Mar 31, 2020
7534e97
remove managed_db_restore_ltr_backup from commands
xaliciayang Mar 31, 2020
57277e5
replace "list-by-*" with "list" in help
xaliciayang Apr 1, 2020
5ad302f
remove blank lines from params
xaliciayang Apr 1, 2020
c935c15
revert restore ltr backup command to be separate from PITR
xaliciayang Apr 3, 2020
687e9bb
re-recorded
xaliciayang Apr 4, 2020
9661b27
change help to use ltr restore
xaliciayang Apr 4, 2020
920401f
undo changes for restore (pitr)
xaliciayang Apr 4, 2020
4d39351
revert changes in PITR restore tests
xaliciayang Apr 6, 2020
dd0eb2d
style/pylint
xaliciayang Apr 6, 2020
223b945
moved restore under ltr-backup
xaliciayang Apr 6, 2020
94b0530
update ltr restore command in help
xaliciayang Apr 6, 2020
97c0ade
add wait to help
xaliciayang Apr 6, 2020
4b32d6a
rename restore function for MI
xaliciayang Apr 7, 2020
41aa6dd
rename restore custom function (again)
xaliciayang Apr 7, 2020
0ac9bfb
clarified param requirements for ltr-backup restore
xaliciayang Apr 7, 2020
8490995
changed help descriptions for retention params
xaliciayang Apr 8, 2020
9493d8e
remove whitespace
xaliciayang Apr 10, 2020
204b6fb
changed --name to represent backup name in ltr-backup commands
xaliciayang Apr 10, 2020
7452420
added lines for style
xaliciayang Apr 10, 2020
f9d22b3
fix help
xaliciayang Apr 10, 2020
bc782bd
update week_of_year help
xaliciayang Apr 10, 2020
0be376f
add \ to help; add confirmation for delete; add checks in tests; re-r…
xaliciayang Apr 14, 2020
96c6b3a
enable ltr-backup show to accept backup-id
xaliciayang Apr 16, 2020
35badd4
enable delete with backup_id
xaliciayang Apr 16, 2020
fb05415
adjust usage of --latest in test
xaliciayang Apr 16, 2020
7898a1d
remove py files
xaliciayang Apr 16, 2020
98ea63f
added hard length checks to tests; added show test using backup id; a…
xaliciayang Apr 16, 2020
81450d1
test re-record
xaliciayang Apr 16, 2020
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
73 changes: 72 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 @@ -631,7 +631,7 @@

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

helps['sql midb short-term-retention-policy set'] = """
Expand All @@ -654,6 +654,77 @@
text: az sql midb short-term-retention-policy show -g mygroup --mi myinstance -n mymanageddb --deleted-time "2018-05-20T05:34:22"
"""

helps['sql midb ltr-policy'] = """
type: group
short-summary: Manage SQL Managed Instance database long term retention policy.
"""

helps['sql midb ltr-policy set'] = """
type: command
short-summary: Update long term retention settings for a managed database.
examples:
- name: Set long term retention for a managed database.
text: az sql midb ltr-policy set -g mygroup --mi myinstance -n mymanageddb --weekly-retention "P1W" --monthly-retention "P6M" --yearly-retention "P1Y" --week-of-year 26
"""

helps['sql midb ltr-policy show'] = """
type: command
short-summary: Show the long term retention policy for a managed database.
examples:
- name: Show long term retention policy for a managed database.
text: az sql midb ltr-policy show -g mygroup --mi myinstance -n mymanageddb
"""

helps['sql midb ltr-backup'] = """
type: group
short-summary: Manage SQL Managed Instance database long term retention backups.
"""

helps['sql midb ltr-backup show'] = """
type: command
short-summary: Get a long term retention backup for a managed database.
examples:
- name: Show long term retention backup for a managed database.
text: az sql midb ltr-backup show -l southeastasia --mi myinstance -n mymanageddb --backup-name "3214b3fb-fba9-43e7-96a3-09e35ffcb336;132292152080000000"
"""

helps['sql midb ltr-backup list'] = """
type: command
short-summary: List the long term retention backups for a location, instance or database.
examples:
- name: List long term retention backups for a managed database.
text: az sql midb ltr-backup list -l southeastasia --mi myinstance -n mymanageddb
- name: List long term retention backups for a managed instance (list only the latest LTR backups, which belong to live databases).
text: az sql midb ltr-backup list -l southeastasia --mi myinstance --database-state Live --only-latest-per-database True
- name: List long term retention backups for a managed instance (with resource group argument).
text: az sql midb ltr-backup list -l southeastasia -g mygroup --mi myinstance
- name: List long term retention backups for a location (list only the latest LTR backups, which belong to live databases).
text: az sql midb ltr-backup list -l southeastasia --database-state Live --only-latest-per-database True
- name: List long term retention backups for a location (with resource group argument).
text: az sql midb ltr-backup list -l southeastasia -g mygroup
"""

helps['sql midb ltr-backup delete'] = """
type: command
short-summary: Delete a long term retention backup.
examples:
- name: Delete long term retention backup for a managed database.
text: az sql midb ltr-backup delete -l southeastasia --mi myinstance -n mymanageddb --backup-name "3214b3fb-fba9-43e7-96a3-09e35ffcb336;132292152080000000"
"""

helps['sql midb ltr-backup restore'] = """
type: command
short-summary: Restore a long term retention backup to a new database.
examples:
- name: Restore a managed database using LTR backup.
text: az sql midb ltr-backup restore --dest-name targetmidb --dest-mi myinstance --dest-resource-group mygroup --backup-id "/subscriptions/6caa113c-794c-42f8-ab9d-878d8aa104dc/resourceGroups/mygroup/providers/Microsoft.Sql/locations/southeastasia/longTermRetentionManagedInstances/myinstance/longTermRetentionDatabases/sourcemidb/longTermRetentionManagedInstanceBackups/3214b3fb-fba9-43e7-96a3-09e35ffcb336;132292152080000000"
"""

helps['sql midb ltr-backup wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of the managed database is met.
"""

helps['sql server'] = """
type: group
short-summary: Manage SQL servers.
Expand Down
107 changes: 94 additions & 13 deletions src/azure-cli/azure/cli/command_modules/sql/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1483,22 +1483,103 @@ def _configure_security_policy_storage_params(arg_ctx):
'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(
'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.')

c.argument('retention_days',
options_list=['--retention-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.')

with self.argument_context('sql midb ltr-policy set') as c:
create_args_for_complex_type(
c, 'parameters', ManagedDatabase, [
'weekly_retention',
'monthly_retention',
'yearly_retention',
'week_of_year'
])

c.argument('weekly_retention',
help='Retention for the weekly backup. '
'If just a number is passed instead of an ISO 8601 string, days will be assumed as the units.'
'There is a minimum of 7 days and a maximum of 10 years.')

c.argument('monthly_retention',
help='Retention for the monthly backup. '
'If just a number is passed instead of an ISO 8601 string, days will be assumed as the units.'
'There is a minimum of 7 days and a maximum of 10 years.')

c.argument('yearly_retention',
help='Retention for the yearly backup. '
'If just a number is passed instead of an ISO 8601 string, days will be assumed as the units.'
'There is a minimum of 7 days and a maximum of 10 years.')

c.argument('week_of_year',
help='The Week of Year, 1 to 52, in which to take the yearly backup.')

with self.argument_context('sql midb ltr-backup') as c:
c.argument('location_name',
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.')
arg_type=get_location_type(self.cli_ctx),
help='The location of the desired backups.')

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.')
with self.argument_context('sql midb ltr-backup list') as c:
c.argument('managed_instance_name',
options_list=['--managed-instance', '--mi'],
help='Name of the Azure SQL managed instance. '
'If specified, retrieves all requested backups under this managed instance.')

c.argument('database_name',
options_list=['--name', '-n'],
help='The name of the Azure SQL Managed Database. '
'If specified (along with instance name), retrieves all requested backups under this database.')

c.argument('database_state',
required=False,
options_list=['--database-state', '--state'],
help='\'All\', \'Live\', or \'Deleted\'. '
'Will fetch backups only from databases of specified state. '
'If no state provied, defaults to \'All\'.')

c.argument('only_latest_per_database',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--only-latest-per-database is too long as parameter. Can you give a short name for this parameter?

Copy link
Contributor Author

@xaliciayang xaliciayang Mar 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted; added '--latest'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for this argument, we will assume it to be true when provided, right? If yes, can we consider using action='store_true' for this argument to make sure it will be true when specified?

options_list=['--only-latest-per-database', '--latest'],
required=False,
help='If true, will only return the latest backup for each database')

with self.argument_context('sql midb ltr-backup restore') as c:
c.argument('target_managed_database_name',
options_list=['--dest-name'],
required=True,
help='Name of the managed database that will be created as the restore destination.')

c.argument('target_managed_instance_name',
options_list=['--dest-mi'],
required=True,
help='Name of the managed instance to restore managed database to.')

c.argument('target_resource_group_name',
options_list=['--dest-resource-group'],
required=True,
help='Name of the resource group of the managed instance to restore managed database to.')

c.argument('long_term_retention_backup_resource_id',
options_list=['--backup-id'],
required=True,
help='The resource id of the long term retention backup to be restored. '
'Use \'az sql midb ltr-backup show\' or \'az sql midb ltr-backup list\' for backup id.')

###############################################
# sql virtual cluster #
Expand Down
8 changes: 8 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 @@ -162,3 +162,11 @@ def get_sql_virtual_clusters_operations(cli_ctx, _):

def get_sql_instance_failover_groups_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).instance_failover_groups


def get_sql_managed_database_long_term_retention_policies_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).managed_instance_long_term_retention_policies


def get_sql_managed_database_long_term_retention_backups_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).long_term_retention_managed_instance_backups
40 changes: 39 additions & 1 deletion src/azure-cli/azure/cli/command_modules/sql/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
get_sql_firewall_rules_operations,
get_sql_managed_databases_operations,
get_sql_managed_backup_short_term_retention_policies_operations,
get_sql_managed_database_long_term_retention_policies_operations,
get_sql_managed_database_long_term_retention_backups_operations,
get_sql_managed_instance_azure_ad_administrators_operations,
get_sql_managed_instance_encryption_protectors_operations,
get_sql_managed_instance_keys_operations,
Expand Down Expand Up @@ -567,9 +569,45 @@ def load_command_table(self, _):
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(
'set',
'update_short_term_retention_mi',
supports_no_wait=True)
g.custom_command('show', 'get_short_term_retention_mi')

managed_database_long_term_retention_policies_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#ManagedInstanceLongTermRetentionPoliciesOperations.{}',
client_factory=get_sql_managed_database_long_term_retention_policies_operations)

with self.command_group('sql midb ltr-policy',
managed_database_long_term_retention_policies_operations,
client_factory=get_sql_managed_database_long_term_retention_policies_operations) as g:

g.custom_command('set', 'update_long_term_retention_mi')
g.show_command('show', 'get')

managed_database_long_term_retention_backups_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#LongTermRetentionManagedInstanceBackupsOperations.{}',
client_factory=get_sql_managed_database_long_term_retention_backups_operations)

with self.command_group('sql midb ltr-backup',
managed_database_long_term_retention_backups_operations,
client_factory=get_sql_managed_database_long_term_retention_backups_operations) as g:
g.show_command('show', 'get')
g.custom_command(
'list',
'list_long_term_retention_mi_backups')
g.command('delete', 'delete')

with self.command_group('sql midb ltr-backup',
managed_databases_operations,
client_factory=get_sql_managed_databases_operations) as g:
g.custom_command(
'restore',
'restore_long_term_retention_mi_backup',
supports_no_wait=True)
g.wait_command('wait')

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