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] 'az backup restore restore-disks': Update to support NoZone as a valid target-zone #30720

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ def load_arguments(self, _):
c.argument('disk_encryption_set_id', options_list=['--disk-encryption-set-id'], help='The disk encryption set id is used for encrypting restored disks. Please ensure access to disk encryption set id that is specified here.')
c.argument('mi_system_assigned', action='store_true', help='Use this flag to specify whether a system-assigned managed identity should be used for the restore operation. MI option is not applicable for restoring unmanaged disks.')
c.argument('mi_user_assigned', help='ARM ID of the user-assigned managed identity to use for the restore operation. Specify a value for this parameter if you do not want to use a system-assigned MI for restoring the backup item.')
c.argument('target_zone', arg_type=get_enum_type(['1', '2', '3']), help='A primary region currently can have three Azure availability zones. Use this argument to specify the target zone number while doing Cross Zonal Restore.')
c.argument('target_zone', arg_type=get_enum_type(['1', '2', '3', 'NoZone']), help='A primary region currently can have three Azure availability zones. Use this argument to specify the target zone number while doing Cross Zonal Restore.')
c.argument('restore_mode', restore_mode_type)
c.argument('target_vm_name', help='Name of the VM to which the data should be restored, in the case of Alternate Location restore to a new VM.')
c.argument('target_vnet_name', help='Name of the VNet in which the target VM should be created, in the case of Alternate Location restore to a new VM.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def validate_czr(backup_config_response, recovery_point, use_secondary_region):
backup_storage_redundancy = backup_config_response.properties.storage_type
cross_region_restore_flag = backup_config_response.properties.cross_region_restore_flag
if (cross_region_restore_flag or backup_storage_redundancy == StorageType.ZONE_REDUNDANT):
if recovery_point.tier_type is not None and recovery_point.tier_type == "VaultStandard":
if recovery_point.tier_type is not None and (
recovery_point.tier_type == "VaultStandard" or
recovery_point.tier_type == "SnapshotAndVaultStandard"):
SourabhSomnathGholap marked this conversation as resolved.
Show resolved Hide resolved
if backup_storage_redundancy != StorageType.ZONE_REDUNDANT:
if recovery_point.properties.zones is None:
raise ArgumentUsageError("""
Expand All @@ -116,8 +118,8 @@ def validate_czr(backup_config_response, recovery_point, use_secondary_region):
""")
else:
raise ArgumentUsageError("""
Please ensure that the given RP tier type is 'VaultStandard' or remove --target-zone argument.
""")
Please ensure that the given RP tier type is either 'VaultStandard' or 'SnapshotAndVaultStandard',
or remove --target-zone argument.""")
else:
raise ArgumentUsageError("""
Please ensure either the vault storage redundancy is ZoneRedundant or the vault has CRR enabled or try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class VaultPreparer(AbstractPreparer, SingleValueReplacer): # pylint: disable=t
def __init__(self, name_prefix='clitest-vault', parameter_name='vault_name',
resource_group_location_parameter_name='resource_group_location',
resource_group_parameter_name='resource_group',
dev_setting_name='AZURE_CLI_TEST_DEV_BACKUP_ACCT_NAME', soft_delete=True):
dev_setting_name='AZURE_CLI_TEST_DEV_BACKUP_ACCT_NAME', soft_delete=True, storageRedundancy = None):
super().__init__(name_prefix, 24)
from azure.cli.core.mock import DummyCli
self.cli_ctx = DummyCli()
Expand All @@ -31,6 +31,7 @@ def __init__(self, name_prefix='clitest-vault', parameter_name='vault_name',
self.resource_group_location_parameter_name = resource_group_location_parameter_name
self.dev_setting_value = os.environ.get(dev_setting_name, None)
self.soft_delete = soft_delete
self.storageRedundancy = storageRedundancy

def create_resource(self, name, **kwargs):
if not self.dev_setting_value:
Expand All @@ -44,6 +45,10 @@ def create_resource(self, name, **kwargs):
if not self.soft_delete:
cmd = 'az backup vault backup-properties set -n {} -g {} --soft-delete-feature-state Disable'.format(name, self.resource_group)
execute(self.cli_ctx, cmd)

if self.storageRedundancy:
cmd = 'az backup vault update -n {} -g {} --backup-storage-redundancy {}'.format(name, self.resource_group, self.storageRedundancy)
execute(self.cli_ctx, cmd)
return {self.parameter_name: name}
return {self.parameter_name: self.dev_setting_value}

Expand Down Expand Up @@ -89,7 +94,7 @@ def _cleanup(self, vault_name, resource_group):
class VMPreparer(AbstractPreparer, SingleValueReplacer):
def __init__(self, name_prefix='clitest-vm', parameter_name='vm_name',
resource_group_location_parameter_name='resource_group_location',
resource_group_parameter_name='resource_group', dev_setting_name='AZURE_CLI_TEST_DEV_BACKUP_VM_NAME'):
resource_group_parameter_name='resource_group', dev_setting_name='AZURE_CLI_TEST_DEV_BACKUP_VM_NAME', image = "Win2012R2Datacenter"):
super().__init__(name_prefix, 15)
from azure.cli.core.mock import DummyCli
self.cli_ctx = DummyCli()
Expand All @@ -99,17 +104,18 @@ def __init__(self, name_prefix='clitest-vm', parameter_name='vm_name',
self.location = None
self.resource_group_location_parameter_name = resource_group_location_parameter_name
self.dev_setting_value = os.environ.get(dev_setting_name, None)
self.image = image

def create_resource(self, name, **kwargs):
if not self.dev_setting_value:
self.resource_group = self._get_resource_group(**kwargs)
self.location = self._get_resource_group_location(**kwargs)
param_format = '-n {} -g {} --image {} --admin-username {} --admin-password {} '
param_format += '--tags {} --nsg-rule None'
param_format += '--tags {} --nsg-rule None --security-type {}'
# param_format += '--tags {} --size {} --nsg-rule None'
param_tags = 'MabUsed=Yes Owner=sisi Purpose=CLITest DeleteBy=12-2099 AutoShutdown=No'
param_string = param_format.format(name, self.resource_group, 'Win2012R2Datacenter', name,
'%j^VYw9Q3Z@Cu$*h', param_tags) #, 'Standard_D2a_v4')
param_string = param_format.format(name, self.resource_group, self.image, name,
'%j^VYw9Q3Z@Cu$*h', param_tags, "Standard") #, 'Standard_D2a_v4')
cmd = 'az vm create {}'.format(param_string)
execute(self.cli_ctx, cmd)
return {self.parameter_name: name}
Expand Down
Loading
Loading