Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SQL] 'az sql db str-policy set/show': Add Set and Show ShortTermRetentionPolicy #14919

Merged
merged 66 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
00b9235
{Docs} Remove stale reference in README to closed issue about extensi…
dkmiller Apr 27, 2020
ab16df0
Merge remote-tracking branch 'upstream/release'
azclibot Apr 28, 2020
03436bc
Merge remote-tracking branch 'upstream/release'
azclibot Apr 30, 2020
7d98b1f
Merge remote-tracking branch 'upstream/release'
azclibot May 19, 2020
06f6ec5
Merge remote-tracking branch 'upstream/release'
azclibot Jun 2, 2020
adab2d2
Merge remote-tracking branch 'upstream/release'
azclibot Jun 23, 2020
c7b9f98
Merge remote-tracking branch 'upstream/release'
azclibot Jul 14, 2020
18e8b8d
Merge remote-tracking branch 'upstream/release'
azclibot Jul 16, 2020
1eb5074
Merge remote-tracking branch 'upstream/release'
azclibot Aug 4, 2020
cc3a159
Merge remote-tracking branch 'upstream/release' into master
azclibot Aug 6, 2020
c712d24
draft sql db short term retention policy set and show cmdlets
Aug 26, 2020
af8f98e
Merge remote-tracking branch 'upstream/release' into master
azclibot Aug 26, 2020
b1272fb
add defination of get_sql_database_short_term_retention_policies_oper…
Aug 26, 2020
c8ec29d
renamed functions; removed deleted_time since STRPolicy doesn't suppo…
Aug 26, 2020
92510c1
fix name
Aug 26, 2020
1d0ccea
fix code style
Aug 26, 2020
80ad0da
remove unused parameter; use variable name from sdk: diff_backup_inte…
Aug 27, 2020
5ebc840
switch to use show_custom_command rather than show_command since hit …
Aug 27, 2020
b69512e
should be custom_show_command
Aug 27, 2020
d96a7f1
Merge branch 'dev' into shortTermRetentionV2020CLI
Aug 27, 2020
1cc0ce1
add SqlServerDbShortTermRetentionScenarioTest
Aug 27, 2020
9152f13
add 'create db' to SqlServerDbShortTermRetentionScenarioTest
Aug 27, 2020
f39141c
fix create db of SqlServerDbShortTermRetentionScenarioTest
Aug 28, 2020
0f904b9
Merge remote-tracking branch 'upstream/release' into master
azclibot Aug 28, 2020
97a778b
change another way to create db for SqlServerDbShortTermRetentionScen…
Aug 28, 2020
8aa86ec
update SqlServerDbShortTermRetentionScenarioTest test location to sou…
Sep 3, 2020
7536d1c
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
Sep 3, 2020
3aa1fc7
Merge branch 'dev' into shortTermRetentionV2020CLI
Sep 3, 2020
c53163d
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
Sep 4, 2020
96fdeac
Merge branch 'dev' into shortTermRetentionV2020CLI
Sep 4, 2020
9a0e5e6
upgrade azure-mgmt-sql to 0.21.0
Sep 4, 2020
4be88f6
Revert "upgrade azure-mgmt-sql to 0.21.0"
Sep 4, 2020
d17a993
Merge remote-tracking branch 'upstream/release' into master
azclibot Sep 22, 2020
27699d2
Merge remote-tracking branch 'upstream/release' into master
azclibot Sep 28, 2020
eb7e004
Merge branch 'master' of https://github.com/Azure/azure-cli into dev
Oct 5, 2020
50b3f25
Merge branch 'master' of https://github.com/Azure/azure-cli into dev
Oct 14, 2020
2dec31c
Merge branch 'dev' into shortTermRetentionV2020CLI
Oct 14, 2020
4414eed
remove unrelated comments
Oct 14, 2020
f63a733
edit test file, scenario test passed
Oct 15, 2020
c3880e2
add test record
Oct 15, 2020
db32d48
fix cli style, reupload record
Oct 15, 2020
641df73
style fix
Oct 15, 2020
0d1b10e
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
Jun 23, 2021
3fcde67
Merge branch 'dev' into shortTermRetentionV2020CLI
Jun 23, 2021
cc21e6e
edit test file + remove old scenario test file
Jun 24, 2021
d4bad22
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
Jun 24, 2021
798859a
Merge branch 'dev' into shortTermRetentionV2020CLI
Jun 24, 2021
25a98f1
upload succeed scenario test record
Jun 25, 2021
9fe5818
change custom.py changes back
Jun 25, 2021
5aec607
update python sdk version to 0.29
Jun 25, 2021
f729ae7
update azure-mgmt-sql version in setup.py file
Jun 25, 2021
ab49207
fix ServerPublicNetworkAccess to ServerNetworkAccessFlag according to…
Jun 25, 2021
b188a4c
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
Jun 25, 2021
89ba182
Merge branch 'dev' into shortTermRetentionV2020CLI
Jun 25, 2021
a6b6067
re-record failed scenario tests
Jun 29, 2021
98bdadd
upload more scenario test record
Jun 29, 2021
831bbe8
push more records
Jun 29, 2021
3d861dd
upload more scenario tests
Jun 30, 2021
c2f92a3
add more scenario test record
Jul 1, 2021
a445fce
Merge branch 'dev' of https://github.com/Azure/azure-cli into dev
Jul 1, 2021
f1b3493
Merge branch 'dev' into shortTermRetentionV2020CLI
Jul 1, 2021
ebb2109
upload more scenario test record
Jul 1, 2021
a0473e4
remove incident added pyproj and sln files
Jul 1, 2021
ff45c49
upload scenario test records
Jul 1, 2021
535d2b4
solve comment
Jul 1, 2021
3b1906d
fix code style
Jul 1, 2021
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
21 changes: 21 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,27 @@
text: az sql db list-editions -l westus --service-objective P1 --show-details max-size
"""

helps['sql db str-policy'] = """
type: group
short-summary: Manage SQL database short term retention policy.
"""

helps['sql db str-policy set'] = """
type: command
short-summary: Update short term retention settings for a live database.
examples:
- name: Set short term retention for a live database.
text: az sql db str-policy set -g mygroup -s myserver -n mydb --retention-days retentionindays --diffbackup-hours diffbackuphours
"""

helps['sql db str-policy show'] = """
type: command
short-summary: Show the short term retention policy for a live database.
examples:
- name: Show short term retention policy for a live database.
text: az sql db str-policy show -g mygroup -s myserver -n mydb
"""

helps['sql db ltr-policy'] = """
type: group
short-summary: Manage SQL database long term retention policy.
Expand Down
24 changes: 24 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 @@ -1085,6 +1085,30 @@ def _configure_security_policy_storage_params(arg_ctx):
required=False,
arg_type=backup_storage_redundancy_param_type)

###############################################
# sql db str #
###############################################
with self.argument_context('sql db str-policy set') as c:
create_args_for_complex_type(
c, 'parameters', Database, [
'retention_days',
'diffbackup_hours'
])

c.argument(
'retention_days',
options_list=['--retention-days'],
required=True,
help='New backup short term retention policy retention in days.'
'Valid retention days for live database of (DTU) Basic can be 1-7 days; Rest models can be 1-35 days.')

c.argument(
'diffbackup_hours',
options_list=['--diffbackup-hours'],
required=True,
help='New backup short term retention policy differential backup interval in hours.'
'Valid differential backup interval for live database can be 12 or 24 hours.')

###############################################
# sql dw #
###############################################
Expand Down
4 changes: 4 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 @@ -176,6 +176,10 @@ def get_sql_managed_databases_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).managed_databases


def get_sql_backup_short_term_retention_policies_operations(cli_ctx, _):
return get_sql_management_client(cli_ctx).backup_short_term_retention_policies


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

Expand Down
13 changes: 13 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 @@ -24,6 +24,7 @@
)

from ._util import (
get_sql_backup_short_term_retention_policies_operations,
get_sql_server_azure_ad_administrators_operations,
get_sql_capabilities_operations,
get_sql_databases_operations,
Expand Down Expand Up @@ -337,6 +338,18 @@ def load_command_table(self, _):
supports_no_wait=True)
g.wait_command('wait')

backup_short_term_retention_policies_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#BackupShortTermRetentionPoliciesOperations.{}',
client_factory=get_sql_backup_short_term_retention_policies_operations)

with self.command_group('sql db str-policy',
backup_short_term_retention_policies_operations,
client_factory=get_sql_backup_short_term_retention_policies_operations,
is_preview=True) as g:

g.custom_command('set', 'update_short_term_retention', supports_no_wait=True)
lululilliancoding marked this conversation as resolved.
Show resolved Hide resolved
g.custom_show_command('show', 'get_short_term_retention')

database_sensitivity_labels_operations = CliCommandType(
operations_tmpl='azure.mgmt.sql.operations#SensitivityLabelsOperations.{}',
client_factory=get_sql_database_sensitivity_labels_operations)
Expand Down
49 changes: 44 additions & 5 deletions src/azure-cli/azure/cli/command_modules/sql/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
PartnerRegionInfo,
InstanceFailoverGroupReadOnlyEndpoint,
InstanceFailoverGroupReadWriteEndpoint,
ServerPublicNetworkAccess,
ServerNetworkAccessFlag,
ServerInfo,
EncryptionProtector,
ManagedInstanceEncryptionProtector,
Expand Down Expand Up @@ -2698,6 +2698,45 @@ def update_long_term_retention(
return policy


def update_short_term_retention(
client,
database_name,
server_name,
resource_group_name,
retention_days,
diffbackup_hours,
no_wait=False):
'''
Updates short term retention for live database
'''

return sdk_no_wait(
no_wait,
client.create_or_update,
database_name=database_name,
server_name=server_name,
resource_group_name=resource_group_name,
retention_days=retention_days,
diff_backup_interval_in_hours=diffbackup_hours)


def get_short_term_retention(
client,
database_name,
server_name,
resource_group_name):
'''
Gets short term retention for live database
'''

policy = client.get(
database_name=database_name,
server_name=server_name,
resource_group_name=resource_group_name)

return policy


def _list_by_database_long_term_retention_backups(
client,
location_name,
Expand Down Expand Up @@ -3436,8 +3475,8 @@ def server_create(

if enable_public_network is not None:
kwargs['public_network_access'] = (
ServerPublicNetworkAccess.enabled if enable_public_network
else ServerPublicNetworkAccess.disabled)
ServerNetworkAccessFlag.enabled if enable_public_network
else ServerNetworkAccessFlag.disabled)

kwargs['key_id'] = key_id

Expand Down Expand Up @@ -3534,8 +3573,8 @@ def server_update(

if enable_public_network is not None:
instance.public_network_access = (
ServerPublicNetworkAccess.enabled if enable_public_network
else ServerPublicNetworkAccess.disabled)
ServerNetworkAccessFlag.enabled if enable_public_network
else ServerNetworkAccessFlag.disabled)

instance.primary_user_assigned_identity_id = (
primary_user_assigned_identity_id or instance.primary_user_assigned_identity_id)
Expand Down
Loading