Skip to content

Commit f46174d

Browse files
ShreyanshJoshiShreyansh JoshiAkshay Neemazhoxing-ms
authoredJun 30, 2021
[BACKUP] Added Archive Support for Azure CLI (Azure#18535)
* Code done! * Modified code1 * Archive tests added. * help_for_move, linter and az file changed * New line added in az and test_backup_commands * ran backup archive * Commented test_backup_archive for debugging * Changed recordings * Adding archive recording back * Added archive recording, and couple others * ran all four failed tests locally * akshay_review_changes * Corrected a error in help-text of move command * Corrected a small error in test_workload_commands. * More changes after review. * Additional changes * Changed help text of move in help.py * Made changes for use-secondary-region parameter * Changed recordings * Re-ran the 3 failing tests * Further modifications to those 3 recordings * Tweaked archive code for use_secondary_region * Changes suggested by Xing Zhou * Additional change after review * Update src/azure-cli/azure/cli/command_modules/backup/_help.py Co-authored-by: Xing Zhou <[email protected]> * Update src/azure-cli/azure/cli/command_modules/backup/custom_afs.py Co-authored-by: Xing Zhou <[email protected]> * Update src/azure-cli/azure/cli/command_modules/backup/custom_afs.py Co-authored-by: Xing Zhou <[email protected]> * Final changes suggested by Xing Zhou * Minor change Co-authored-by: Shreyansh Joshi <[email protected]> Co-authored-by: Akshay Neema <[email protected]> Co-authored-by: Xing Zhou <[email protected]>
1 parent e93f8ad commit f46174d

26 files changed

+49138
-5209
lines changed
 

‎linter_exclusions.yml

+3
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ backup recoverypoint list:
774774
backup_management_type:
775775
rule_exclusions:
776776
- option_length_too_long
777+
recommended_for_archive:
778+
rule_exclusions:
779+
- option_length_too_long
777780
backup recoverypoint show:
778781
parameters:
779782
backup_management_type:

‎src/azure-cli/azure/cli/command_modules/backup/_client_factory.py

+4
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def recovery_points_cf(cli_ctx, *_):
146146
return _backup_client_factory(cli_ctx).recovery_points
147147

148148

149+
def recovery_points_recommended_cf(cli_ctx, *_):
150+
return _backup_client_factory(cli_ctx).recovery_points_recommended_for_move
151+
152+
149153
def recovery_points_crr_cf(cli_ctx, *_):
150154
return _backup_client_factory(cli_ctx).recovery_points_crr
151155

‎src/azure-cli/azure/cli/command_modules/backup/_help.py

+8
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@
350350
crafted: true
351351
"""
352352

353+
helps['backup recoverypoint move'] = """
354+
type: command
355+
short-summary: Move a particular recovery point of a backed up item from one tier to another tier.
356+
examples:
357+
- name: Move a particular recovery point of a backed up item.
358+
text: az backup recoverypoint move --container-name MyContainer --item-name MyItem --resource-group MyResourceGroup --vault-name MyVault --name RpId --source-tier SourceTier --destination-tier DestinationTier
359+
"""
360+
353361
helps['backup recoverypoint show'] = """
354362
type: command
355363
short-summary: Shows details of a particular recovery point.

‎src/azure-cli/azure/cli/command_modules/backup/_params.py

+44-10
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
allowed_azure_workload_types = ['MSSQL', 'SAPHANA', 'SAPASE', 'SAPHanaDatabase', 'SQLDataBase']
2626
allowed_backup_management_types = ['AzureIaasVM', 'AzureStorage', 'AzureWorkload']
2727
allowed_protectable_item_type = ['SQLAG', 'SQLInstance', 'SQLDatabase', 'HANAInstance', 'SAPHanaDatabase', 'SAPHanaSystem']
28+
allowed_target_tier_type_chk_archivable = ['VaultArchive']
29+
allowed_tier_type = ['VaultStandard', 'Snapshot', 'VaultArchive', 'VaultStandardRehydrated', 'SnapshotAndVaultStandard', 'SnapshotAndVaultArchive']
30+
allowed_rehyd_priority_type = ['Standard', 'High']
2831

2932
backup_management_type_help = """Specifiy the backup management type. Define how Azure Backup manages the backup of entities within the ARM resource. For eg: AzureWorkloads refers to workloads installed within Azure VMs, AzureStorage refers to entities within Storage account. Required only if friendly name is used as Container name."""
3033
container_name_help = """Name of the backup container. Accepts 'Name' or 'FriendlyName' from the output of az backup container list command. If 'FriendlyName' is passed then BackupManagementType is required."""
31-
workload_type_help = """Specifiy the type of applications within the Resource which should be discovered and protected by Azure Backup. """
34+
workload_type_help = """Specify the type of applications within the Resource which should be discovered and protected by Azure Backup. """
3235
restore_mode_help = """Specify the restore mode."""
3336
resolve_conflict_help = "Instruction if there's a conflict with the restored data."
3437
resource_id_help = """ID of the Azure Resource containing items to be protected by Azure Backup service. Currently, only Azure VM resource IDs are supported."""
@@ -40,6 +43,9 @@
4043
diskslist_help = """List of disks to be excluded or included."""
4144
disk_list_setting_help = """option to decide whether to include or exclude the disk or reset any previous settings to default behavior"""
4245
target_container_name_help = """The target container to which the DB recovery point should be downloaded as files."""
46+
target_tier_help = """ The destination/target tier to which a particular recovery point has to be moved."""
47+
tier_help = """ Provide 'tier' parameter to filter recovery points."""
48+
rehyd_priority_type_help = """The type of priority to be maintained while rehydrating a recovery point """
4349

4450
vault_name_type = CLIArgumentType(help='Name of the Recovery services vault.', options_list=['--vault-name', '-v'], completer=get_resource_name_completion_list('Microsoft.RecoveryServices/vaults'))
4551
container_name_type = CLIArgumentType(help=container_name_help, options_list=['--container-name', '-c'])
@@ -62,6 +68,9 @@
6268
target_container_name_type = CLIArgumentType(options_list=['--target-container-name'], help=target_container_name_help)
6369
filepath_type = CLIArgumentType(options_list=['--filepath'], help="The path to which the DB should be restored as files.")
6470
from_full_rp_type = CLIArgumentType(options_list=['--from-full-rp-name'], help="Name of the starting Recovery point.")
71+
target_tier_type = CLIArgumentType(help=target_tier_help, arg_type=get_enum_type(allowed_target_tier_type_chk_archivable), options_list=['--target-tier'])
72+
tier_type = CLIArgumentType(help=tier_help, arg_type=get_enum_type(allowed_tier_type), options_list=['--tier'])
73+
rehyd_priority_type = CLIArgumentType(help=rehyd_priority_type_help, arg_type=get_enum_type(allowed_rehyd_priority_type), options_list=['--rehydration-priority'])
6574

6675

6776
# pylint: disable=too-many-statements
@@ -175,15 +184,36 @@ def load_arguments(self, _):
175184
c.argument('container_name', container_name_type, id_part='child_name_2')
176185
c.argument('item_name', item_name_type, id_part='child_name_3')
177186

178-
for command in ['list', 'show-log-chain']:
179-
with self.argument_context('backup recoverypoint ' + command) as c:
180-
c.argument('vault_name', vault_name_type, id_part=None)
181-
c.argument('start_date', type=datetime_type, help='The start date of the range in UTC (d-m-Y).')
182-
c.argument('end_date', type=datetime_type, help='The end date of the range in UTC (d-m-Y).')
183-
c.argument('backup_management_type', backup_management_type)
184-
c.argument('container_name', container_name_type)
185-
c.argument('workload_type', workload_type)
186-
c.argument('use_secondary_region', action='store_true', help='Use this flag to list recoverypoints in secondary region.')
187+
with self.argument_context('backup recoverypoint list') as c:
188+
c.argument('vault_name', vault_name_type, id_part=None)
189+
c.argument('start_date', type=datetime_type, help='The start date of the range in UTC (d-m-Y).')
190+
c.argument('end_date', type=datetime_type, help='The end date of the range in UTC (d-m-Y).')
191+
c.argument('backup_management_type', backup_management_type)
192+
c.argument('container_name', container_name_type)
193+
c.argument('workload_type', workload_type)
194+
c.argument('use_secondary_region', action='store_true', help='Use this flag to list recoverypoints in secondary region.')
195+
c.argument('is_ready_for_move', arg_type=get_three_state_flag(), help='Use this flag to retrieve the recoverypoints that are ready to be moved to destination-tier.')
196+
c.argument('target_tier', target_tier_type)
197+
c.argument('tier', tier_type)
198+
c.argument('recommended_for_archive', action="store_true", help='Use this flag to retrieve recommended archivable recoverypoints.')
199+
200+
with self.argument_context('backup recoverypoint move') as c:
201+
c.argument('vault_name', vault_name_type, id_part=None)
202+
c.argument('container_name', container_name_type)
203+
c.argument('rp_name', rp_name_type, options_list=['--name', '-n'], id_part='child_name_4')
204+
c.argument('backup_management_type', backup_management_type)
205+
c.argument('workload_type', workload_type)
206+
c.argument('source_tier', help='The source tier from which a particular recovery point has to be moved.', arg_type=get_enum_type(['VaultStandard']), options_list=['--source-tier'])
207+
c.argument('destination_tier', help=target_tier_help, arg_type=get_enum_type(['VaultArchive']), options_list=['--destination-tier'])
208+
209+
with self.argument_context('backup recoverypoint show-log-chain') as c:
210+
c.argument('vault_name', vault_name_type, id_part=None)
211+
c.argument('start_date', type=datetime_type, help='The start date of the range in UTC (d-m-Y).')
212+
c.argument('end_date', type=datetime_type, help='The end date of the range in UTC (d-m-Y).')
213+
c.argument('backup_management_type', backup_management_type)
214+
c.argument('container_name', container_name_type)
215+
c.argument('workload_type', workload_type)
216+
c.argument('use_secondary_region', action='store_true', help='Use this flag to list recoverypoints in secondary region.')
187217

188218
with self.argument_context('backup recoverypoint show') as c:
189219
c.argument('name', rp_name_type, options_list=['--name', '-n'], help='Name of the recovery point. You can use the backup recovery point list command to get the name of a backed up item.', id_part='child_name_4')
@@ -276,6 +306,8 @@ def load_arguments(self, _):
276306
c.argument('restore_only_osdisk', arg_type=get_three_state_flag(), help='Use this flag to restore only OS disks of a backed up VM.')
277307
c.argument('restore_as_unmanaged_disks', arg_type=get_three_state_flag(), help='Use this flag to specify to restore as unmanaged disks')
278308
c.argument('use_secondary_region', action='store_true', help='Use this flag to show recoverypoints in secondary region.')
309+
c.argument('rehydration_duration', type=int, help='Set the maximum time, in days (between 10-30, both inclusive) for which the recovery point stays in hydrated state. Default: 15')
310+
c.argument('rehydration_priority', rehyd_priority_type)
279311

280312
with self.argument_context('backup restore restore-azurefileshare') as c:
281313
c.argument('resolve_conflict', resolve_conflict_type)
@@ -296,6 +328,8 @@ def load_arguments(self, _):
296328
with self.argument_context('backup restore restore-azurewl') as c:
297329
c.argument('vault_name', vault_name_type, id_part=None)
298330
c.argument('recovery_config', options_list=['--recovery-config'], help="""Specify the recovery configuration of a backed up item. The configuration object can be obtained from 'backup recoveryconfig show' command.""")
331+
c.argument('rehydration_duration', type=int, help='Set the maximum time, in days (between 10-30, both inclusive) for which the recovery point stays in hydrated state. Default: 15')
332+
c.argument('rehydration_priority', rehyd_priority_type)
299333

300334
# Recoveryconfig
301335
with self.argument_context('backup recoveryconfig show') as c:

‎src/azure-cli/azure/cli/command_modules/backup/commands.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
job_details_cf, job_cancellations_cf, recovery_points_cf, restores_cf, backup_storage_configs_cf, \
1010
item_level_recovery_connections_cf, backup_protected_items_cf, backup_protectable_items_cf, \
1111
protection_containers_cf, protection_intent_cf # pylint: disable=unused-variable
12+
1213
from azure.cli.command_modules.backup._format import (
1314
transform_container_list, transform_policy_list, transform_item_list, transform_job_list,
1415
transform_recovery_point_list, transform_container, transform_item, transform_protectable_item_list, transform_job,
@@ -89,7 +90,8 @@ def load_command_table(self, _):
8990
with self.command_group('backup recoverypoint', backup_custom_base, client_factory=recovery_points_cf) as g:
9091
g.show_command('show', 'show_recovery_point')
9192
g.command('list', 'list_recovery_points', table_transformer=transform_recovery_point_list)
92-
g.show_command('show-log-chain', 'list_recovery_points', table_transformer=transform_log_chain_list)
93+
g.command('move', 'move_recovery_points')
94+
g.show_command('show-log-chain', 'show_log_chain_recovery_points', table_transformer=transform_log_chain_list)
9395

9496
with self.command_group('backup restore', backup_custom_base, client_factory=restores_cf) as g:
9597
g.command('restore-disks', 'restore_disks')

0 commit comments

Comments
 (0)
Please sign in to comment.