Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adding the make-backups-immutable parameter to ltr policy
  • Loading branch information
rebeccaxu-ms committed Dec 7, 2023
commit ccdfd31f568d294b8b7210a51fbd5c1a3033d1d3
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/sql/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
short-summary: Update long term retention settings for a database.
examples:
- name: Set long term retention for a database.
text: az sql db ltr-policy set -g mygroup -s myserver -n mydb --weekly-retention "P1W" --monthly-retention "P6M" --yearly-retention "P1Y" --week-of-year 26
text: az sql db ltr-policy set -g mygroup -s myserver -n mydb --weekly-retention "P1W" --monthly-retention "P6M" --yearly-retention "P1Y" --week-of-year 26 --make-backups-immutable true
"""

helps['sql db ltr-policy show'] = """
Expand Down
7 changes: 6 additions & 1 deletion src/azure-cli/azure/cli/command_modules/sql/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,8 @@ def _configure_security_policy_storage_params(arg_ctx):
'weekly_retention',
'monthly_retention',
'yearly_retention',
'week_of_year'])
'week_of_year',
'make_backups_immutable'])

c.argument('weekly_retention',
help='Retention for the weekly backup. '
Expand All @@ -1281,6 +1282,10 @@ def _configure_security_policy_storage_params(arg_ctx):
c.argument('week_of_year',
help='The Week of Year, 1 to 52, in which to take the yearly LTR backup.')

c.argument('make_backups_immutable',
help='Whether to make the LTR backups immutable.',
arg_type=get_three_state_flag())

with self.argument_context('sql db ltr-backup') as c:
c.argument('location_name',
required=True,
Expand Down
10 changes: 10 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 @@ -3000,6 +3000,7 @@ def update_long_term_retention(
monthly_retention=None,
yearly_retention=None,
week_of_year=None,
make_backups_immutable=None,
**kwargs):
'''
Updates long term retention for managed database
Expand All @@ -3010,6 +3011,13 @@ def update_long_term_retention(
if yearly_retention and not week_of_year:
raise CLIError('Please specify week of year for yearly retention.')

if make_backups_immutable:
confirmation = prompt_y_n("""Immutable LTR backups can't be changed or deleted.
You'll be charged for LTR backups for the full retention period.
Do you want to proceed?""")
if not confirmation:
return

kwargs['weekly_retention'] = weekly_retention

kwargs['monthly_retention'] = monthly_retention
Expand All @@ -3018,6 +3026,8 @@ def update_long_term_retention(

kwargs['week_of_year'] = week_of_year

kwargs['make_backups_immutable'] = make_backups_immutable

policy = client.begin_create_or_update(
database_name=database_name,
server_name=server_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,7 @@ def test_sql_db_long_term_retention(
'monthly_retention': 'P1M',
'yearly_retention': 'P2M',
'week_of_year': 12,
'make_backups_immutable': 'False',
'encryption_protector' : 'https://test123343strehan.vault.azure.net/keys/testk1/604b0e26e2a24eeaab30b80c8d7bb1c1',
'keys' : '"https://test123343strehan.vault.azure.net/keys/k2/66f51a6e70f04067af8eaf77805e88b1" "https://test123343strehan.vault.azure.net/keys/testk1/604b0e26e2a24eeaab30b80c8d7bb1c1" "https://test123343strehan.vault.azure.net/keys/testk1/96151496df864e32aa62a3c1857b2931"',
'umi' : '/subscriptions/e1775f9f-a286-474d-b6f0-29c42ac74554/resourcegroups/ArmTemplate/providers/Microsoft.ManagedIdentity/userAssignedIdentities/shobhittest'
Expand All @@ -1242,12 +1243,14 @@ def test_sql_db_long_term_retention(
self.cmd(
'sql db ltr-policy set -g {rg} -s {server_name} -n {database_name}'
' --weekly-retention {weekly_retention} --monthly-retention {monthly_retention}'
' --yearly-retention {yearly_retention} --week-of-year {week_of_year}',
' --yearly-retention {yearly_retention} --week-of-year {week_of_year}'
' --make-backups-immutable {make_backups_immutable}',
checks=[
self.check('resourceGroup', '{rg}'),
self.check('weeklyRetention', '{weekly_retention}'),
self.check('monthlyRetention', '{monthly_retention}'),
self.check('yearlyRetention', '{yearly_retention}')])
self.check('yearlyRetention', '{yearly_retention}'),
self.check('makeBackupsImmutable', '{make_backups_immutable}')])

# test get long term retention policy on live database
self.cmd(
Expand All @@ -1256,7 +1259,8 @@ def test_sql_db_long_term_retention(
self.check('resourceGroup', '{rg}'),
self.check('weeklyRetention', '{weekly_retention}'),
self.check('monthlyRetention', '{monthly_retention}'),
self.check('yearlyRetention', '{yearly_retention}')])
self.check('yearlyRetention', '{yearly_retention}'),
self.check('makeBackupsImmutable', '{make_backups_immutable}')])

# test list long term retention backups for location
# with resource group
Expand Down