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

[BACKUP] Added Archive Support for Azure CLI #18535

Merged
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
baed726
Code done!
Jun 15, 2021
09514b0
Modified code1
Jun 16, 2021
c432deb
Archive tests added.
Jun 22, 2021
c0c2bdc
help_for_move, linter and az file changed
Jun 23, 2021
92403b3
New line added in az and test_backup_commands
Jun 23, 2021
d74f791
ran backup archive
Jun 23, 2021
8b3cc79
Commented test_backup_archive for debugging
Jun 23, 2021
d311f55
Changed recordings
Jun 23, 2021
f4ab05c
Adding archive recording back
Jun 23, 2021
f3ed600
Added archive recording, and couple others
Jun 23, 2021
3b4d08e
ran all four failed tests locally
Jun 23, 2021
ebe7981
Merge pull request #1 from akshayneema/shreyanshbranch
ShreyanshJoshi Jun 23, 2021
9f26c18
akshay_review_changes
Jun 25, 2021
ab64d08
Merge branch 'user/t-shjoshi/Archive_support_CLI' of https://github.c…
Jun 25, 2021
61d07e8
Corrected a error in help-text of move command
Jun 25, 2021
aa56130
Corrected a small error in test_workload_commands.
Jun 25, 2021
18455d8
More changes after review.
Jun 25, 2021
955214e
Additional changes
Jun 25, 2021
a58f8e7
Changed help text of move in help.py
Jun 25, 2021
e4ba30a
Made changes for use-secondary-region parameter
Jun 25, 2021
f8691ef
Resolved conflicts
Jun 28, 2021
c5d028c
Changed recordings
Jun 28, 2021
7931c71
Re-ran the 3 failing tests
Jun 28, 2021
a88b2fb
Further modifications to those 3 recordings
Jun 28, 2021
8812a07
Tweaked archive code for use_secondary_region
Jun 28, 2021
5805645
Changes suggested by Xing Zhou
Jun 29, 2021
c5c56da
Additional change after review
Jun 29, 2021
9acee32
Update src/azure-cli/azure/cli/command_modules/backup/_help.py
ShreyanshJoshi Jun 29, 2021
b36ce08
Update src/azure-cli/azure/cli/command_modules/backup/custom_afs.py
ShreyanshJoshi Jun 29, 2021
3eb73c5
Update src/azure-cli/azure/cli/command_modules/backup/custom_afs.py
ShreyanshJoshi Jun 29, 2021
b636e7a
Final changes suggested by Xing Zhou
Jun 29, 2021
127a6e0
Final changes suggested by Xing Zhou
Jun 29, 2021
ea42811
Minor change
Jun 29, 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
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
9 changes: 9 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,15 @@
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. (autogenerated)
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
crafted: true
"""
ShreyanshJoshi marked this conversation as resolved.
Show resolved Hide resolved

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
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