Skip to content

Commit

Permalink
[BACKUP] Added Archive Support for Azure CLI (#18535)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Jun 30, 2021
1 parent e93f8ad commit f46174d
Show file tree
Hide file tree
Showing 26 changed files with 49,138 additions and 5,209 deletions.
3 changes: 3 additions & 0 deletions linter_exclusions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,9 @@ backup recoverypoint list:
backup_management_type:
rule_exclusions:
- option_length_too_long
recommended_for_archive:
rule_exclusions:
- option_length_too_long
backup recoverypoint show:
parameters:
backup_management_type:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def recovery_points_cf(cli_ctx, *_):
return _backup_client_factory(cli_ctx).recovery_points


def recovery_points_recommended_cf(cli_ctx, *_):
return _backup_client_factory(cli_ctx).recovery_points_recommended_for_move


def recovery_points_crr_cf(cli_ctx, *_):
return _backup_client_factory(cli_ctx).recovery_points_crr

Expand Down
8 changes: 8 additions & 0 deletions src/azure-cli/azure/cli/command_modules/backup/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@
crafted: true
"""

helps['backup recoverypoint move'] = """
type: command
short-summary: Move a particular recovery point of a backed up item from one tier to another tier.
examples:
- name: Move a particular recovery point of a backed up item.
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
"""

helps['backup recoverypoint show'] = """
type: command
short-summary: Shows details of a particular recovery point.
Expand Down
54 changes: 44 additions & 10 deletions src/azure-cli/azure/cli/command_modules/backup/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
allowed_azure_workload_types = ['MSSQL', 'SAPHANA', 'SAPASE', 'SAPHanaDatabase', 'SQLDataBase']
allowed_backup_management_types = ['AzureIaasVM', 'AzureStorage', 'AzureWorkload']
allowed_protectable_item_type = ['SQLAG', 'SQLInstance', 'SQLDatabase', 'HANAInstance', 'SAPHanaDatabase', 'SAPHanaSystem']
allowed_target_tier_type_chk_archivable = ['VaultArchive']
allowed_tier_type = ['VaultStandard', 'Snapshot', 'VaultArchive', 'VaultStandardRehydrated', 'SnapshotAndVaultStandard', 'SnapshotAndVaultArchive']
allowed_rehyd_priority_type = ['Standard', 'High']

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."""
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."""
workload_type_help = """Specifiy the type of applications within the Resource which should be discovered and protected by Azure Backup. """
workload_type_help = """Specify the type of applications within the Resource which should be discovered and protected by Azure Backup. """
restore_mode_help = """Specify the restore mode."""
resolve_conflict_help = "Instruction if there's a conflict with the restored data."
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."""
Expand All @@ -40,6 +43,9 @@
diskslist_help = """List of disks to be excluded or included."""
disk_list_setting_help = """option to decide whether to include or exclude the disk or reset any previous settings to default behavior"""
target_container_name_help = """The target container to which the DB recovery point should be downloaded as files."""
target_tier_help = """ The destination/target tier to which a particular recovery point has to be moved."""
tier_help = """ Provide 'tier' parameter to filter recovery points."""
rehyd_priority_type_help = """The type of priority to be maintained while rehydrating a recovery point """

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'))
container_name_type = CLIArgumentType(help=container_name_help, options_list=['--container-name', '-c'])
Expand All @@ -62,6 +68,9 @@
target_container_name_type = CLIArgumentType(options_list=['--target-container-name'], help=target_container_name_help)
filepath_type = CLIArgumentType(options_list=['--filepath'], help="The path to which the DB should be restored as files.")
from_full_rp_type = CLIArgumentType(options_list=['--from-full-rp-name'], help="Name of the starting Recovery point.")
target_tier_type = CLIArgumentType(help=target_tier_help, arg_type=get_enum_type(allowed_target_tier_type_chk_archivable), options_list=['--target-tier'])
tier_type = CLIArgumentType(help=tier_help, arg_type=get_enum_type(allowed_tier_type), options_list=['--tier'])
rehyd_priority_type = CLIArgumentType(help=rehyd_priority_type_help, arg_type=get_enum_type(allowed_rehyd_priority_type), options_list=['--rehydration-priority'])


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

for command in ['list', 'show-log-chain']:
with self.argument_context('backup recoverypoint ' + command) as c:
c.argument('vault_name', vault_name_type, id_part=None)
c.argument('start_date', type=datetime_type, help='The start date of the range in UTC (d-m-Y).')
c.argument('end_date', type=datetime_type, help='The end date of the range in UTC (d-m-Y).')
c.argument('backup_management_type', backup_management_type)
c.argument('container_name', container_name_type)
c.argument('workload_type', workload_type)
c.argument('use_secondary_region', action='store_true', help='Use this flag to list recoverypoints in secondary region.')
with self.argument_context('backup recoverypoint list') as c:
c.argument('vault_name', vault_name_type, id_part=None)
c.argument('start_date', type=datetime_type, help='The start date of the range in UTC (d-m-Y).')
c.argument('end_date', type=datetime_type, help='The end date of the range in UTC (d-m-Y).')
c.argument('backup_management_type', backup_management_type)
c.argument('container_name', container_name_type)
c.argument('workload_type', workload_type)
c.argument('use_secondary_region', action='store_true', help='Use this flag to list recoverypoints in secondary region.')
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.')
c.argument('target_tier', target_tier_type)
c.argument('tier', tier_type)
c.argument('recommended_for_archive', action="store_true", help='Use this flag to retrieve recommended archivable recoverypoints.')

with self.argument_context('backup recoverypoint move') as c:
c.argument('vault_name', vault_name_type, id_part=None)
c.argument('container_name', container_name_type)
c.argument('rp_name', rp_name_type, options_list=['--name', '-n'], id_part='child_name_4')
c.argument('backup_management_type', backup_management_type)
c.argument('workload_type', workload_type)
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'])
c.argument('destination_tier', help=target_tier_help, arg_type=get_enum_type(['VaultArchive']), options_list=['--destination-tier'])

with self.argument_context('backup recoverypoint show-log-chain') as c:
c.argument('vault_name', vault_name_type, id_part=None)
c.argument('start_date', type=datetime_type, help='The start date of the range in UTC (d-m-Y).')
c.argument('end_date', type=datetime_type, help='The end date of the range in UTC (d-m-Y).')
c.argument('backup_management_type', backup_management_type)
c.argument('container_name', container_name_type)
c.argument('workload_type', workload_type)
c.argument('use_secondary_region', action='store_true', help='Use this flag to list recoverypoints in secondary region.')

with self.argument_context('backup recoverypoint show') as c:
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')
Expand Down Expand Up @@ -276,6 +306,8 @@ def load_arguments(self, _):
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.')
c.argument('restore_as_unmanaged_disks', arg_type=get_three_state_flag(), help='Use this flag to specify to restore as unmanaged disks')
c.argument('use_secondary_region', action='store_true', help='Use this flag to show recoverypoints in secondary region.')
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')
c.argument('rehydration_priority', rehyd_priority_type)

with self.argument_context('backup restore restore-azurefileshare') as c:
c.argument('resolve_conflict', resolve_conflict_type)
Expand All @@ -296,6 +328,8 @@ def load_arguments(self, _):
with self.argument_context('backup restore restore-azurewl') as c:
c.argument('vault_name', vault_name_type, id_part=None)
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.""")
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')
c.argument('rehydration_priority', rehyd_priority_type)

# Recoveryconfig
with self.argument_context('backup recoveryconfig show') as c:
Expand Down
4 changes: 3 additions & 1 deletion src/azure-cli/azure/cli/command_modules/backup/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
job_details_cf, job_cancellations_cf, recovery_points_cf, restores_cf, backup_storage_configs_cf, \
item_level_recovery_connections_cf, backup_protected_items_cf, backup_protectable_items_cf, \
protection_containers_cf, protection_intent_cf # pylint: disable=unused-variable

from azure.cli.command_modules.backup._format import (
transform_container_list, transform_policy_list, transform_item_list, transform_job_list,
transform_recovery_point_list, transform_container, transform_item, transform_protectable_item_list, transform_job,
Expand Down Expand Up @@ -89,7 +90,8 @@ def load_command_table(self, _):
with self.command_group('backup recoverypoint', backup_custom_base, client_factory=recovery_points_cf) as g:
g.show_command('show', 'show_recovery_point')
g.command('list', 'list_recovery_points', table_transformer=transform_recovery_point_list)
g.show_command('show-log-chain', 'list_recovery_points', table_transformer=transform_log_chain_list)
g.command('move', 'move_recovery_points')
g.show_command('show-log-chain', 'show_log_chain_recovery_points', table_transformer=transform_log_chain_list)

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

0 comments on commit f46174d

Please sign in to comment.