Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/backup/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
6 changes: 5 additions & 1 deletion src/azure-cli/azure/cli/command_modules/backup/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
14 changes: 11 additions & 3 deletions src/azure-cli/azure/cli/command_modules/backup/custom_wl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# --------------------------------------------------------------------------------------------

from uuid import uuid4
from datetime import datetime, timedelta, timezone

# pylint: disable=import-error
# pylint: disable=broad-except
Expand Down Expand Up @@ -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)

Expand All @@ -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,
Expand Down