diff --git a/.gitignore b/.gitignore index 1c235329480..b3e638bf2af 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ __pycache__/ # Virtual environment env/ +env1/ env27/ venv/ .python-version diff --git a/src/azure-cli/azure/cli/command_modules/backup/_params.py b/src/azure-cli/azure/cli/command_modules/backup/_params.py index 749ad5bf6bd..cd1651f8f6f 100644 --- a/src/azure-cli/azure/cli/command_modules/backup/_params.py +++ b/src/azure-cli/azure/cli/command_modules/backup/_params.py @@ -35,8 +35,8 @@ policy_help = """JSON encoded policy definition. Use the show command with JSON output to obtain a policy object. Modify the values using a file editor and pass the object.""" target_server_type_help = """Specify the type of the server which should be discovered.""" protectable_item_name_type_help = """Specify the resource name to be protected by Azure Backup service.""" -backup_type_help = """'Full, Differential, Log, Copy-only-full' for backup Item type 'MSSQL'. 'Full, Differential' for backup item type 'SAPHANA'.""" -retain_until_help = """The date until which this backed up copy will be available for retrieval, in UTC (d-m-Y). If not specified, 30 days will be taken as default value. For SAPHANA and SQL workload, retain-until parameter value will be overridden by the underlying policy.""" +backup_type_help = """'Full, Differential, Log, CopyOnlyFull' for backup Item type 'MSSQL'. 'Full, Differential' for backup item type 'SAPHANA'.""" +retain_until_help = """The date until which this backed up copy will be available for retrieval, in UTC (d-m-Y). For SQL workload, retain-until can only be specified for backup-type 'CopyOnlyFull'. For HANA workload, user can't specify the value for retain-until. If not specified, 30 days will be taken as default value or as decided by service.""" 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.""" diff --git a/src/azure-cli/azure/cli/command_modules/backup/custom.py b/src/azure-cli/azure/cli/command_modules/backup/custom.py index 3a0c6e6b11b..61efb8160ca 100644 --- a/src/azure-cli/azure/cli/command_modules/backup/custom.py +++ b/src/azure-cli/azure/cli/command_modules/backup/custom.py @@ -7,7 +7,7 @@ import json import re import os -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from six.moves.urllib.parse import urlparse # pylint: disable=import-error # pylint: disable=too-many-lines from knack.log import get_logger @@ -446,6 +446,10 @@ def update_policy_for_item(cmd, client, resource_group_name, vault_name, item, p def backup_now(cmd, client, resource_group_name, vault_name, item, retain_until): + + if retain_until is None: + retain_until = datetime.now(timezone.utc) + timedelta(days=30) + # Get container and item URIs container_uri = _get_protection_container_uri_from_id(item.id) item_uri = _get_protected_item_uri_from_id(item.id) diff --git a/src/azure-cli/azure/cli/command_modules/backup/custom_afs.py b/src/azure-cli/azure/cli/command_modules/backup/custom_afs.py index df4be3eb807..6ea329b4203 100644 --- a/src/azure-cli/azure/cli/command_modules/backup/custom_afs.py +++ b/src/azure-cli/azure/cli/command_modules/backup/custom_afs.py @@ -2,7 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone import azure.cli.command_modules.backup.custom_help as helper # pylint: disable=import-error # pylint: disable=unused-argument @@ -86,8 +86,10 @@ def enable_for_AzureFileShare(cmd, client, resource_group_name, vault_name, afs_ def backup_now(cmd, client, resource_group_name, vault_name, item, retain_until): + if retain_until is None: - retain_until = (datetime.utcnow() + timedelta(days=30)).strftime('%d-%m-%Y') + retain_until = datetime.now(timezone.utc) + timedelta(days=30) + container_uri = helper.get_protection_container_uri_from_id(item.id) item_uri = helper.get_protected_item_uri_from_id(item.id) trigger_backup_request = _get_backup_request(retain_until) diff --git a/src/azure-cli/azure/cli/command_modules/backup/custom_base.py b/src/azure-cli/azure/cli/command_modules/backup/custom_base.py index c711f27909b..e5a6c62f6b5 100644 --- a/src/azure-cli/azure/cli/command_modules/backup/custom_base.py +++ b/src/azure-cli/azure/cli/command_modules/backup/custom_base.py @@ -3,7 +3,6 @@ # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- -from datetime import datetime, timedelta, timezone import azure.cli.command_modules.backup.custom as custom import azure.cli.command_modules.backup.custom_afs as custom_afs import azure.cli.command_modules.backup.custom_help as custom_help @@ -106,9 +105,6 @@ def backup_now(cmd, client, resource_group_name, vault_name, item_name, retain_u if isinstance(item, list): raise ValidationError("Multiple items found. Please give native names instead.") - if retain_until is None: - retain_until = datetime.now(timezone.utc) + timedelta(days=30) - if item.properties.backup_management_type.lower() == "azureiaasvm": return custom.backup_now(cmd, client, resource_group_name, vault_name, item, retain_until) diff --git a/src/azure-cli/azure/cli/command_modules/backup/custom_wl.py b/src/azure-cli/azure/cli/command_modules/backup/custom_wl.py index fbdd72ecb5e..72a29440acc 100644 --- a/src/azure-cli/azure/cli/command_modules/backup/custom_wl.py +++ b/src/azure-cli/azure/cli/command_modules/backup/custom_wl.py @@ -4,6 +4,7 @@ # -------------------------------------------------------------------------------------------- from uuid import uuid4 +from datetime import datetime, timedelta, timezone # pylint: disable=import-error # pylint: disable=broad-except @@ -377,9 +378,16 @@ def backup_now(cmd, client, resource_group_name, vault_name, item, retain_until, if backup_type is None: raise RequiredArgumentMissingError("Backup type missing. Please provide a valid backup type using " "--backup-type argument.") + message = "For SAPHANA and SQL workload, retain-until parameter value will be overridden by the underlying policy" - if retain_until is not None: + + if (retain_until is not None and backup_type != 'CopyOnlyFull'): logger.warning(message) + retain_until = datetime.now(timezone.utc) + timedelta(days=30) + + if retain_until is None: + retain_until = datetime.now(timezone.utc) + timedelta(days=30) + container_uri = cust_help.get_protection_container_uri_from_id(item.id) item_uri = cust_help.get_protected_item_uri_from_id(item.id) @@ -390,10 +398,10 @@ def backup_now(cmd, client, resource_group_name, vault_name, item, retain_until, Enable compression is not applicable for SAPHanaDatabase item type. """) - if cust_help.is_hana(backup_item_type) and backup_type in ['Log', 'CopyOnlyFull']: + if cust_help.is_hana(backup_item_type) and backup_type in ['Log', 'CopyOnlyFull', 'Incremental']: raise CLIError( """ - Backup type cannot be Log or CopyOnlyFull for SAPHanaDatabase item type. + Backup type cannot be Log, CopyOnlyFull, Incremental for SAPHanaDatabase Adhoc backup. """) properties = AzureWorkloadBackupRequest(backup_type=backup_type, enable_compression=enable_compression,