Skip to content
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/_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 --access-tier "Archive"
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 --access-tier "Archive" --make-backups-immutable true
"""

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

c.argument('weekly_retention',
Expand All @@ -1282,6 +1283,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())

c.argument('backup_storage_access_tier',
options_list=['--access-tier', '--backup-storage-access-tier'],
arg_type=get_enum_type(["Hot", "Archive"]),
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 @@ -3003,6 +3003,7 @@ def update_long_term_retention(
monthly_retention=None,
yearly_retention=None,
week_of_year=None,
make_backups_immutable=None,
backup_storage_access_tier=None,
**kwargs):
'''
Expand All @@ -3014,6 +3015,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

if backup_storage_access_tier and backup_storage_access_tier.lower() not in BACKUP_STORAGE_ACCESS_TIERS:
raise CLIError('Please specify a valid backup storage access tier type for backup storage access tier.'
'See \'--help\' for more details.')
Expand All @@ -3026,6 +3034,8 @@ def update_long_term_retention(

kwargs['week_of_year'] = week_of_year

kwargs['make_backups_immutable'] = make_backups_immutable

kwargs['backup_storage_access_tier'] = backup_storage_access_tier

policy = client.begin_create_or_update(
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',
'backup_storage_access_tier': 'Archive',
'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"',
Expand All @@ -1244,12 +1245,14 @@ def test_sql_db_long_term_retention(
'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}'
' --make-backups-immutable {make_backups_immutable}',
' --access-tier {backup_storage_access_tier}',
checks=[
self.check('resourceGroup', '{rg}'),
self.check('weeklyRetention', '{weekly_retention}'),
self.check('monthlyRetention', '{monthly_retention}'),
self.check('yearlyRetention', '{yearly_retention}'),
self.check('makeBackupsImmutable', '{make_backups_immutable}'),
self.check('backupStorageAccessTier', '{backup_storage_access_tier}')])

# test get long term retention policy on live database
Expand All @@ -1260,6 +1263,7 @@ def test_sql_db_long_term_retention(
self.check('weeklyRetention', '{weekly_retention}'),
self.check('monthlyRetention', '{monthly_retention}'),
self.check('yearlyRetention', '{yearly_retention}'),
self.check('makeBackupsImmutable', '{make_backups_immutable}'),
self.check('backupStorageAccessTier', '{backup_storage_access_tier}')])

# test list long term retention backups for location
Expand Down