Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}?api-version=2024-04-01
URI Parameters
Name |
In |
Required |
Type |
Description |
policyName
|
path |
True
|
string
|
Backup policy to be created.
|
resourceGroupName
|
path |
True
|
string
|
The name of the resource group where the recovery services vault is present.
|
subscriptionId
|
path |
True
|
string
|
The subscription Id.
|
vaultName
|
path |
True
|
string
|
The name of the recovery services vault.
|
api-version
|
query |
True
|
string
|
Client Api Version.
|
Name |
Required |
Type |
Description |
x-ms-authorization-auxiliary
|
|
string
|
|
Request Body
Name |
Type |
Description |
eTag
|
string
|
Optional ETag.
|
location
|
string
|
Resource location.
|
properties
|
ProtectionPolicy:
|
ProtectionPolicyResource properties
|
tags
|
object
|
Resource tags.
|
Responses
Security
azure_auth
Azure Active Directory OAuth2 Flow
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
Name |
Description |
user_impersonation
|
impersonate your user account.
|
Examples
Create or Update Azure Storage Vault Standard Protection Policy
Sample request
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicyV2?api-version=2024-04-01
{
"properties": {
"backupManagementType": "AzureStorage",
"workLoadType": "AzureFileShare",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": [
"2023-07-18T09:30:00.000Z"
]
},
"timeZone": "UTC",
"vaultRetentionPolicy": {
"snapshotRetentionInDays": 5,
"vaultRetention": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 30,
"durationType": "Days"
}
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 60,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"January"
],
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
}
}
}
}
}
}
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureFileShareProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.LongTermRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthOfYear;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthlyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionScheduleFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.VaultRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeekOfMonth;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.WorkloadType;
import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Samples for ProtectionPolicies CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/
* AzureStorage/ProtectionPolicies_CreateOrUpdate_Hardened.json
*/
/**
* Sample code: Create or Update Azure Storage Vault Standard Protection Policy.
*
* @param manager Entry point to RecoveryServicesBackupManager.
*/
public static void createOrUpdateAzureStorageVaultStandardProtectionPolicy(
com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager manager) {
manager
.protectionPolicies().define(
"newPolicyV2")
.withRegion(
(String) null)
.withExistingVault("swaggertestvault",
"SwaggerTestRg")
.withProperties(
new AzureFileShareProtectionPolicy()
.withWorkLoadType(
WorkloadType.AZURE_FILE_SHARE)
.withSchedulePolicy(new SimpleSchedulePolicy().withScheduleRunFrequency(ScheduleRunType.DAILY)
.withScheduleRunTimes(Arrays.asList(OffsetDateTime.parse("2023-07-18T09:30:00.000Z"))))
.withVaultRetentionPolicy(
new VaultRetentionPolicy()
.withVaultRetention(new LongTermRetentionPolicy()
.withDailySchedule(new DailyRetentionSchedule()
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2023-07-18T09:30:00.000Z")))
.withRetentionDuration(new RetentionDuration().withCount(30)
.withDurationType(RetentionDurationType.DAYS)))
.withWeeklySchedule(new WeeklyRetentionSchedule()
.withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2023-07-18T09:30:00.000Z")))
.withRetentionDuration(new RetentionDuration().withCount(12)
.withDurationType(RetentionDurationType.WEEKS)))
.withMonthlySchedule(
new MonthlyRetentionSchedule()
.withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withRetentionScheduleWeekly(new WeeklyRetentionFormat()
.withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionTimes(
Arrays.asList(OffsetDateTime.parse("2023-07-18T09:30:00.000Z")))
.withRetentionDuration(new RetentionDuration().withCount(60)
.withDurationType(RetentionDurationType.MONTHS)))
.withYearlySchedule(
new YearlyRetentionSchedule()
.withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withMonthsOfYear(Arrays.asList(MonthOfYear.JANUARY))
.withRetentionScheduleWeekly(new WeeklyRetentionFormat()
.withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionTimes(
Arrays.asList(OffsetDateTime.parse("2023-07-18T09:30:00.000Z")))
.withRetentionDuration(new RetentionDuration().withCount(10)
.withDurationType(RetentionDurationType.YEARS))))
.withSnapshotRetentionInDays(5))
.withTimeZone("UTC"))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from typing import Any, IO, Union
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_hardened.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="swaggertestvault",
resource_group_name="SwaggerTestRg",
policy_name="newPolicyV2",
parameters={
"properties": {
"backupManagementType": "AzureStorage",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": ["2023-07-18T09:30:00.000Z"],
},
"timeZone": "UTC",
"vaultRetentionPolicy": {
"snapshotRetentionInDays": 5,
"vaultRetention": {
"dailySchedule": {
"retentionDuration": {"count": 30, "durationType": "Days"},
"retentionTimes": ["2023-07-18T09:30:00.000Z"],
},
"monthlySchedule": {
"retentionDuration": {"count": 60, "durationType": "Months"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2023-07-18T09:30:00.000Z"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday"],
"retentionDuration": {"count": 12, "durationType": "Weeks"},
"retentionTimes": ["2023-07-18T09:30:00.000Z"],
},
"yearlySchedule": {
"monthsOfYear": ["January"],
"retentionDuration": {"count": 10, "durationType": "Years"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2023-07-18T09:30:00.000Z"],
},
},
},
"workLoadType": "AzureFileShare",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Hardened.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armrecoveryservicesbackup_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/33c4457b1d13f83965f4fe3367dca4a6df898100/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Hardened.json
func ExampleProtectionPoliciesClient_CreateOrUpdate_createOrUpdateAzureStorageVaultStandardProtectionPolicy() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armrecoveryservicesbackup.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewProtectionPoliciesClient().CreateOrUpdate(ctx, "swaggertestvault", "SwaggerTestRg", "newPolicyV2", armrecoveryservicesbackup.ProtectionPolicyResource{
Properties: &armrecoveryservicesbackup.AzureFileShareProtectionPolicy{
BackupManagementType: to.Ptr("AzureStorage"),
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t }())},
},
TimeZone: to.Ptr("UTC"),
VaultRetentionPolicy: &armrecoveryservicesbackup.VaultRetentionPolicy{
SnapshotRetentionInDays: to.Ptr[int32](5),
VaultRetention: &armrecoveryservicesbackup.LongTermRetentionPolicy{
RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](30),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t }())},
},
MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](60),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t }())},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](12),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t }())},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](10),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t }())},
},
},
},
WorkLoadType: to.Ptr(armrecoveryservicesbackup.WorkloadTypeAzureFileShare),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("newPolicyV2"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicyV2"),
// Properties: &armrecoveryservicesbackup.AzureFileShareProtectionPolicy{
// BackupManagementType: to.Ptr("AzureStorage"),
// ProtectedItemsCount: to.Ptr[int32](0),
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t}())},
// },
// TimeZone: to.Ptr("UTC"),
// VaultRetentionPolicy: &armrecoveryservicesbackup.VaultRetentionPolicy{
// SnapshotRetentionInDays: to.Ptr[int32](5),
// VaultRetention: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](30),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t}())},
// },
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](60),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](12),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](10),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t}())},
// },
// },
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
*
* @summary Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
* x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Hardened.json
*/
async function createOrUpdateAzureStorageVaultStandardProtectionPolicy() {
const subscriptionId =
process.env["RECOVERYSERVICESBACKUP_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const vaultName = "swaggertestvault";
const resourceGroupName = process.env["RECOVERYSERVICESBACKUP_RESOURCE_GROUP"] || "SwaggerTestRg";
const policyName = "newPolicyV2";
const parameters = {
properties: {
backupManagementType: "AzureStorage",
schedulePolicy: {
schedulePolicyType: "SimpleSchedulePolicy",
scheduleRunFrequency: "Daily",
scheduleRunTimes: [new Date("2023-07-18T09:30:00.000Z")],
},
timeZone: "UTC",
vaultRetentionPolicy: {
snapshotRetentionInDays: 5,
vaultRetention: {
dailySchedule: {
retentionDuration: { count: 30, durationType: "Days" },
retentionTimes: [new Date("2023-07-18T09:30:00.000Z")],
},
monthlySchedule: {
retentionDuration: { count: 60, durationType: "Months" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [new Date("2023-07-18T09:30:00.000Z")],
},
retentionPolicyType: "LongTermRetentionPolicy",
weeklySchedule: {
daysOfTheWeek: ["Sunday"],
retentionDuration: { count: 12, durationType: "Weeks" },
retentionTimes: [new Date("2023-07-18T09:30:00.000Z")],
},
yearlySchedule: {
monthsOfYear: ["January"],
retentionDuration: { count: 10, durationType: "Years" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [new Date("2023-07-18T09:30:00.000Z")],
},
},
},
workLoadType: "AzureFileShare",
},
};
const credential = new DefaultAzureCredential();
const client = new RecoveryServicesBackupClient(credential, subscriptionId);
const result = await client.protectionPolicies.createOrUpdate(
vaultName,
resourceGroupName,
policyName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicyV2",
"name": "newPolicyV2",
"type": "Microsoft.RecoveryServices/vaults/backupPolicies",
"properties": {
"backupManagementType": "AzureStorage",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": [
"2023-07-18T09:30:00.000Z"
]
},
"vaultRetentionPolicy": {
"snapshotRetentionInDays": 5,
"vaultRetention": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 30,
"durationType": "Days"
}
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 60,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"January"
],
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
}
}
}
},
"timeZone": "UTC",
"protectedItemsCount": 0
}
}
Location: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicyV2/operationResults/00000000-0000-0000-0000-000000000000?api-version=2024-04-01
Azure-AsyncOperation: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicyV2/operations/00000000-0000-0000-0000-000000000000?api-version=2024-04-01
Retry-After: 60
Create or Update Daily Azure Storage Protection Policy
Sample request
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/dailyPolicy2?api-version=2024-04-01
{
"properties": {
"backupManagementType": "AzureStorage",
"workLoadType": "AzureFileShare",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": [
"2021-09-29T08:00:00.000Z"
]
},
"timeZone": "UTC",
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionTimes": [
"2021-09-29T08:00:00.000Z"
],
"retentionDuration": {
"count": 5,
"durationType": "Days"
}
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionTimes": [
"2021-09-29T08:00:00.000Z"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-09-29T08:00:00.000Z"
],
"retentionDuration": {
"count": 60,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"January"
],
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-09-29T08:00:00.000Z"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
}
}
}
}
}
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureFileShareProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.LongTermRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthOfYear;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthlyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionScheduleFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeekOfMonth;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.WorkloadType;
import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Samples for ProtectionPolicies CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/
* AzureStorage/ProtectionPolicies_CreateOrUpdate_Daily.json
*/
/**
* Sample code: Create or Update Daily Azure Storage Protection Policy.
*
* @param manager Entry point to RecoveryServicesBackupManager.
*/
public static void createOrUpdateDailyAzureStorageProtectionPolicy(
com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager manager) {
manager
.protectionPolicies().define(
"dailyPolicy2")
.withRegion((String) null).withExistingVault("swaggertestvault",
"SwaggerTestRg")
.withProperties(new AzureFileShareProtectionPolicy().withWorkLoadType(WorkloadType.AZURE_FILE_SHARE)
.withSchedulePolicy(
new SimpleSchedulePolicy().withScheduleRunFrequency(ScheduleRunType.DAILY).withScheduleRunTimes(
Arrays.asList(OffsetDateTime.parse("2021-09-29T08:00:00.000Z"))))
.withRetentionPolicy(new LongTermRetentionPolicy()
.withDailySchedule(new DailyRetentionSchedule()
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-09-29T08:00:00.000Z")))
.withRetentionDuration(
new RetentionDuration().withCount(5).withDurationType(RetentionDurationType.DAYS)))
.withWeeklySchedule(new WeeklyRetentionSchedule().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-09-29T08:00:00.000Z")))
.withRetentionDuration(
new RetentionDuration().withCount(12).withDurationType(RetentionDurationType.WEEKS)))
.withMonthlySchedule(
new MonthlyRetentionSchedule().withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withRetentionScheduleWeekly(
new WeeklyRetentionFormat().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-09-29T08:00:00.000Z")))
.withRetentionDuration(
new RetentionDuration().withCount(60).withDurationType(RetentionDurationType.MONTHS)))
.withYearlySchedule(
new YearlyRetentionSchedule().withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withMonthsOfYear(Arrays.asList(MonthOfYear.JANUARY))
.withRetentionScheduleWeekly(
new WeeklyRetentionFormat().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-09-29T08:00:00.000Z")))
.withRetentionDuration(
new RetentionDuration().withCount(10).withDurationType(RetentionDurationType.YEARS))))
.withTimeZone("UTC"))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from typing import Any, IO, Union
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_daily.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="swaggertestvault",
resource_group_name="SwaggerTestRg",
policy_name="dailyPolicy2",
parameters={
"properties": {
"backupManagementType": "AzureStorage",
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {"count": 5, "durationType": "Days"},
"retentionTimes": ["2021-09-29T08:00:00.000Z"],
},
"monthlySchedule": {
"retentionDuration": {"count": 60, "durationType": "Months"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-09-29T08:00:00.000Z"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday"],
"retentionDuration": {"count": 12, "durationType": "Weeks"},
"retentionTimes": ["2021-09-29T08:00:00.000Z"],
},
"yearlySchedule": {
"monthsOfYear": ["January"],
"retentionDuration": {"count": 10, "durationType": "Years"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-09-29T08:00:00.000Z"],
},
},
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": ["2021-09-29T08:00:00.000Z"],
},
"timeZone": "UTC",
"workLoadType": "AzureFileShare",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Daily.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armrecoveryservicesbackup_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/33c4457b1d13f83965f4fe3367dca4a6df898100/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Daily.json
func ExampleProtectionPoliciesClient_CreateOrUpdate_createOrUpdateDailyAzureStorageProtectionPolicy() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armrecoveryservicesbackup.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewProtectionPoliciesClient().CreateOrUpdate(ctx, "swaggertestvault", "SwaggerTestRg", "dailyPolicy2", armrecoveryservicesbackup.ProtectionPolicyResource{
Properties: &armrecoveryservicesbackup.AzureFileShareProtectionPolicy{
BackupManagementType: to.Ptr("AzureStorage"),
RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](5),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t }())},
},
MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](60),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t }())},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](12),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t }())},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](10),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t }())},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t }())},
},
TimeZone: to.Ptr("UTC"),
WorkLoadType: to.Ptr(armrecoveryservicesbackup.WorkloadTypeAzureFileShare),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("dailyPolicy2"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/dailyPolicy2"),
// Properties: &armrecoveryservicesbackup.AzureFileShareProtectionPolicy{
// BackupManagementType: to.Ptr("AzureStorage"),
// ProtectedItemsCount: to.Ptr[int32](0),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](5),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}())},
// },
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](60),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](12),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](10),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}())},
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// TimeZone: to.Ptr("UTC"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
*
* @summary Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
* x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Daily.json
*/
async function createOrUpdateDailyAzureStorageProtectionPolicy() {
const subscriptionId =
process.env["RECOVERYSERVICESBACKUP_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const vaultName = "swaggertestvault";
const resourceGroupName = process.env["RECOVERYSERVICESBACKUP_RESOURCE_GROUP"] || "SwaggerTestRg";
const policyName = "dailyPolicy2";
const parameters = {
properties: {
backupManagementType: "AzureStorage",
retentionPolicy: {
dailySchedule: {
retentionDuration: { count: 5, durationType: "Days" },
retentionTimes: [new Date("2021-09-29T08:00:00.000Z")],
},
monthlySchedule: {
retentionDuration: { count: 60, durationType: "Months" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [new Date("2021-09-29T08:00:00.000Z")],
},
retentionPolicyType: "LongTermRetentionPolicy",
weeklySchedule: {
daysOfTheWeek: ["Sunday"],
retentionDuration: { count: 12, durationType: "Weeks" },
retentionTimes: [new Date("2021-09-29T08:00:00.000Z")],
},
yearlySchedule: {
monthsOfYear: ["January"],
retentionDuration: { count: 10, durationType: "Years" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [new Date("2021-09-29T08:00:00.000Z")],
},
},
schedulePolicy: {
schedulePolicyType: "SimpleSchedulePolicy",
scheduleRunFrequency: "Daily",
scheduleRunTimes: [new Date("2021-09-29T08:00:00.000Z")],
},
timeZone: "UTC",
workLoadType: "AzureFileShare",
},
};
const credential = new DefaultAzureCredential();
const client = new RecoveryServicesBackupClient(credential, subscriptionId);
const result = await client.protectionPolicies.createOrUpdate(
vaultName,
resourceGroupName,
policyName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/dailyPolicy2",
"name": "dailyPolicy2",
"type": "Microsoft.RecoveryServices/vaults/backupPolicies",
"properties": {
"backupManagementType": "AzureStorage",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": [
"2021-09-29T08:00:00Z"
],
"scheduleWeeklyFrequency": 0
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionTimes": [
"2021-09-29T08:00:00Z"
],
"retentionDuration": {
"count": 5,
"durationType": "Days"
}
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionTimes": [
"2021-09-29T08:00:00Z"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-09-29T08:00:00Z"
],
"retentionDuration": {
"count": 60,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"January"
],
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-09-29T08:00:00Z"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
}
}
},
"timeZone": "UTC",
"protectedItemsCount": 0
}
}
Location: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/dailyPolicy2/operationResults/00000000-0000-0000-0000-000000000000?api-version=2016-06-01
Azure-AsyncOperation: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/dailyPolicy2/operations/00000000-0000-0000-0000-000000000000?api-version=2016-06-01
Retry-After: 60
Create or Update Enhanced Azure Vm Protection Policy with daily backup
Sample request
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample?api-version=2024-04-01
{
"properties": {
"backupManagementType": "AzureIaasVM",
"timeZone": "India Standard Time",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"snapshotConsistencyType": "OnlyCrashConsistent",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Daily",
"dailySchedule": {
"scheduleRunTimes": [
"2018-01-24T10:00:00Z"
]
}
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionDuration": {
"count": 180,
"durationType": "Days"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"monthlySchedule": {
"retentionDuration": {
"count": 60,
"durationType": "Months"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"yearlySchedule": {
"monthsOfYear": [
"January"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
}
}
}
}
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureIaaSvmProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailySchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.IaasVMSnapshotConsistencyType;
import com.azure.resourcemanager.recoveryservicesbackup.models.IaasvmPolicyType;
import com.azure.resourcemanager.recoveryservicesbackup.models.LongTermRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthOfYear;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthlyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionScheduleFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicyV2;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeekOfMonth;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Samples for ProtectionPolicies CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/
* AzureIaasVm/V2Policy/IaaS_v2_daily.json
*/
/**
* Sample code: Create or Update Enhanced Azure Vm Protection Policy with daily backup.
*
* @param manager Entry point to RecoveryServicesBackupManager.
*/
public static void createOrUpdateEnhancedAzureVmProtectionPolicyWithDailyBackup(
com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager manager) {
manager
.protectionPolicies().define(
"v2-daily-sample")
.withRegion((String) null).withExistingVault("NetSDKTestRsVault", "SwaggerTestRg")
.withProperties(new AzureIaaSvmProtectionPolicy()
.withSchedulePolicy(
new SimpleSchedulePolicyV2().withScheduleRunFrequency(ScheduleRunType.DAILY)
.withDailySchedule(new DailySchedule()
.withScheduleRunTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T10:00:00Z")))))
.withRetentionPolicy(new LongTermRetentionPolicy()
.withDailySchedule(new DailyRetentionSchedule()
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-12-17T08:00:00+00:00")))
.withRetentionDuration(
new RetentionDuration().withCount(180).withDurationType(RetentionDurationType.DAYS)))
.withWeeklySchedule(new WeeklyRetentionSchedule().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-12-17T08:00:00+00:00")))
.withRetentionDuration(
new RetentionDuration().withCount(12).withDurationType(RetentionDurationType.WEEKS)))
.withMonthlySchedule(
new MonthlyRetentionSchedule().withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withRetentionScheduleWeekly(
new WeeklyRetentionFormat().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-12-17T08:00:00+00:00")))
.withRetentionDuration(
new RetentionDuration().withCount(60).withDurationType(RetentionDurationType.MONTHS)))
.withYearlySchedule(
new YearlyRetentionSchedule().withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withMonthsOfYear(Arrays.asList(MonthOfYear.JANUARY))
.withRetentionScheduleWeekly(
new WeeklyRetentionFormat().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-12-17T08:00:00+00:00")))
.withRetentionDuration(
new RetentionDuration().withCount(10).withDurationType(RetentionDurationType.YEARS))))
.withInstantRpRetentionRangeInDays(30).withTimeZone("India Standard Time")
.withPolicyType(IaasvmPolicyType.V2)
.withSnapshotConsistencyType(IaasVMSnapshotConsistencyType.ONLY_CRASH_CONSISTENT))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from typing import Any, IO, Union
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python iaa_s_v2_daily.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="NetSDKTestRsVault",
resource_group_name="SwaggerTestRg",
policy_name="v2-daily-sample",
parameters={
"properties": {
"backupManagementType": "AzureIaasVM",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {"count": 180, "durationType": "Days"},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"monthlySchedule": {
"retentionDuration": {"count": 60, "durationType": "Months"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday"],
"retentionDuration": {"count": 12, "durationType": "Weeks"},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"yearlySchedule": {
"monthsOfYear": ["January"],
"retentionDuration": {"count": 10, "durationType": "Years"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
},
"schedulePolicy": {
"dailySchedule": {"scheduleRunTimes": ["2018-01-24T10:00:00Z"]},
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Daily",
},
"snapshotConsistencyType": "OnlyCrashConsistent",
"timeZone": "India Standard Time",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/V2Policy/IaaS_v2_daily.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armrecoveryservicesbackup_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/33c4457b1d13f83965f4fe3367dca4a6df898100/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/V2Policy/IaaS_v2_daily.json
func ExampleProtectionPoliciesClient_CreateOrUpdate_createOrUpdateEnhancedAzureVmProtectionPolicyWithDailyBackup() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armrecoveryservicesbackup.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewProtectionPoliciesClient().CreateOrUpdate(ctx, "NetSDKTestRsVault", "SwaggerTestRg", "v2-daily-sample", armrecoveryservicesbackup.ProtectionPolicyResource{
Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
BackupManagementType: to.Ptr("AzureIaasVM"),
InstantRpRetentionRangeInDays: to.Ptr[int32](30),
PolicyType: to.Ptr(armrecoveryservicesbackup.IAASVMPolicyTypeV2),
RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](180),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](60),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](12),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](10),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicyV2{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicyV2"),
DailySchedule: &armrecoveryservicesbackup.DailySchedule{
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
},
SnapshotConsistencyType: to.Ptr(armrecoveryservicesbackup.IaasVMSnapshotConsistencyTypeOnlyCrashConsistent),
TimeZone: to.Ptr("India Standard Time"),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("v2-daily-sample"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample"),
// Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
// BackupManagementType: to.Ptr("AzureIaasVM"),
// ProtectedItemsCount: to.Ptr[int32](0),
// InstantRpRetentionRangeInDays: to.Ptr[int32](30),
// PolicyType: to.Ptr(armrecoveryservicesbackup.IAASVMPolicyTypeV2),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](180),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](60),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](12),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](10),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicyV2{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicyV2"),
// DailySchedule: &armrecoveryservicesbackup.DailySchedule{
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
// },
// SnapshotConsistencyType: to.Ptr(armrecoveryservicesbackup.IaasVMSnapshotConsistencyTypeOnlyCrashConsistent),
// TimeZone: to.Ptr("India Standard Time"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
*
* @summary Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
* x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/V2Policy/IaaS_v2_daily.json
*/
async function createOrUpdateEnhancedAzureVMProtectionPolicyWithDailyBackup() {
const subscriptionId =
process.env["RECOVERYSERVICESBACKUP_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const vaultName = "NetSDKTestRsVault";
const resourceGroupName = process.env["RECOVERYSERVICESBACKUP_RESOURCE_GROUP"] || "SwaggerTestRg";
const policyName = "v2-daily-sample";
const parameters = {
properties: {
backupManagementType: "AzureIaasVM",
instantRpRetentionRangeInDays: 30,
policyType: "V2",
retentionPolicy: {
dailySchedule: {
retentionDuration: { count: 180, durationType: "Days" },
retentionTimes: [new Date("2021-12-17T08:00:00+00:00")],
},
monthlySchedule: {
retentionDuration: { count: 60, durationType: "Months" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [new Date("2021-12-17T08:00:00+00:00")],
},
retentionPolicyType: "LongTermRetentionPolicy",
weeklySchedule: {
daysOfTheWeek: ["Sunday"],
retentionDuration: { count: 12, durationType: "Weeks" },
retentionTimes: [new Date("2021-12-17T08:00:00+00:00")],
},
yearlySchedule: {
monthsOfYear: ["January"],
retentionDuration: { count: 10, durationType: "Years" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [new Date("2021-12-17T08:00:00+00:00")],
},
},
schedulePolicy: {
dailySchedule: { scheduleRunTimes: [new Date("2018-01-24T10:00:00Z")] },
schedulePolicyType: "SimpleSchedulePolicyV2",
scheduleRunFrequency: "Daily",
},
snapshotConsistencyType: "OnlyCrashConsistent",
timeZone: "India Standard Time",
},
};
const credential = new DefaultAzureCredential();
const client = new RecoveryServicesBackupClient(credential, subscriptionId);
const result = await client.protectionPolicies.createOrUpdate(
vaultName,
resourceGroupName,
policyName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample",
"name": "v2-daily-sample",
"properties": {
"backupManagementType": "AzureIaasVM",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"snapshotConsistencyType": "OnlyCrashConsistent",
"protectedItemsCount": 0,
"resourceGuardOperationRequests": null,
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {
"count": 180,
"durationType": "Days"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"monthlySchedule": {
"retentionDuration": {
"count": 60,
"durationType": "Months"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"yearlySchedule": {
"monthsOfYear": [
"January"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
}
},
"schedulePolicy": {
"dailySchedule": {
"scheduleRunTimes": [
"2018-01-24T10:00:00Z"
]
},
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Daily"
},
"timeZone": "India Standard Time"
},
"type": "Microsoft.RecoveryServices/vaults/backupPolicies"
}
Location: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample/operationResults/00000000-0000-0000-0000-000000000000?api-version=2020-06-01
Azure-AsyncOperation: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample/operations/00000000-0000-0000-0000-000000000000?api-version=2020-06-01
Retry-After: 60
Create or Update Enhanced Azure Vm Protection Policy with Hourly backup
Sample request
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample?api-version=2024-04-01
{
"properties": {
"backupManagementType": "AzureIaasVM",
"timeZone": "India Standard Time",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"snapshotConsistencyType": "OnlyCrashConsistent",
"schedulePolicy": {
"hourlySchedule": {
"interval": 4,
"scheduleWindowDuration": 16,
"scheduleWindowStartTime": "2021-12-17T08:00:00Z"
},
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Hourly"
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionDuration": {
"count": 180,
"durationType": "Days"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"monthlySchedule": {
"retentionDuration": {
"count": 60,
"durationType": "Months"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"yearlySchedule": {
"monthsOfYear": [
"January"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
}
}
}
}
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureIaaSvmProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.HourlySchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.IaasVMSnapshotConsistencyType;
import com.azure.resourcemanager.recoveryservicesbackup.models.IaasvmPolicyType;
import com.azure.resourcemanager.recoveryservicesbackup.models.LongTermRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthOfYear;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthlyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionScheduleFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicyV2;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeekOfMonth;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Samples for ProtectionPolicies CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/
* AzureIaasVm/V2Policy/IaaS_v2_hourly.json
*/
/**
* Sample code: Create or Update Enhanced Azure Vm Protection Policy with Hourly backup.
*
* @param manager Entry point to RecoveryServicesBackupManager.
*/
public static void createOrUpdateEnhancedAzureVmProtectionPolicyWithHourlyBackup(
com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager manager) {
manager
.protectionPolicies().define(
"v2-daily-sample")
.withRegion(
(String) null)
.withExistingVault("NetSDKTestRsVault", "SwaggerTestRg")
.withProperties(new AzureIaaSvmProtectionPolicy()
.withSchedulePolicy(new SimpleSchedulePolicyV2().withScheduleRunFrequency(ScheduleRunType.HOURLY)
.withHourlySchedule(new HourlySchedule().withInterval(4)
.withScheduleWindowStartTime(OffsetDateTime.parse("2021-12-17T08:00:00Z"))
.withScheduleWindowDuration(16)))
.withRetentionPolicy(new LongTermRetentionPolicy()
.withDailySchedule(new DailyRetentionSchedule()
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-12-17T08:00:00+00:00")))
.withRetentionDuration(
new RetentionDuration().withCount(180).withDurationType(RetentionDurationType.DAYS)))
.withWeeklySchedule(new WeeklyRetentionSchedule().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-12-17T08:00:00+00:00")))
.withRetentionDuration(
new RetentionDuration().withCount(12).withDurationType(RetentionDurationType.WEEKS)))
.withMonthlySchedule(
new MonthlyRetentionSchedule().withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withRetentionScheduleWeekly(
new WeeklyRetentionFormat().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-12-17T08:00:00+00:00")))
.withRetentionDuration(
new RetentionDuration().withCount(60).withDurationType(RetentionDurationType.MONTHS)))
.withYearlySchedule(
new YearlyRetentionSchedule().withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withMonthsOfYear(Arrays.asList(MonthOfYear.JANUARY))
.withRetentionScheduleWeekly(
new WeeklyRetentionFormat().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2021-12-17T08:00:00+00:00")))
.withRetentionDuration(
new RetentionDuration().withCount(10).withDurationType(RetentionDurationType.YEARS))))
.withInstantRpRetentionRangeInDays(30).withTimeZone("India Standard Time")
.withPolicyType(IaasvmPolicyType.V2)
.withSnapshotConsistencyType(IaasVMSnapshotConsistencyType.ONLY_CRASH_CONSISTENT))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from typing import Any, IO, Union
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python iaa_s_v2_hourly.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="NetSDKTestRsVault",
resource_group_name="SwaggerTestRg",
policy_name="v2-daily-sample",
parameters={
"properties": {
"backupManagementType": "AzureIaasVM",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {"count": 180, "durationType": "Days"},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"monthlySchedule": {
"retentionDuration": {"count": 60, "durationType": "Months"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday"],
"retentionDuration": {"count": 12, "durationType": "Weeks"},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"yearlySchedule": {
"monthsOfYear": ["January"],
"retentionDuration": {"count": 10, "durationType": "Years"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
},
"schedulePolicy": {
"hourlySchedule": {
"interval": 4,
"scheduleWindowDuration": 16,
"scheduleWindowStartTime": "2021-12-17T08:00:00Z",
},
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Hourly",
},
"snapshotConsistencyType": "OnlyCrashConsistent",
"timeZone": "India Standard Time",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/V2Policy/IaaS_v2_hourly.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armrecoveryservicesbackup_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/33c4457b1d13f83965f4fe3367dca4a6df898100/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/V2Policy/IaaS_v2_hourly.json
func ExampleProtectionPoliciesClient_CreateOrUpdate_createOrUpdateEnhancedAzureVmProtectionPolicyWithHourlyBackup() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armrecoveryservicesbackup.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewProtectionPoliciesClient().CreateOrUpdate(ctx, "NetSDKTestRsVault", "SwaggerTestRg", "v2-daily-sample", armrecoveryservicesbackup.ProtectionPolicyResource{
Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
BackupManagementType: to.Ptr("AzureIaasVM"),
InstantRpRetentionRangeInDays: to.Ptr[int32](30),
PolicyType: to.Ptr(armrecoveryservicesbackup.IAASVMPolicyTypeV2),
RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](180),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](60),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](12),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](10),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicyV2{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicyV2"),
HourlySchedule: &armrecoveryservicesbackup.HourlySchedule{
Interval: to.Ptr[int32](4),
ScheduleWindowDuration: to.Ptr[int32](16),
ScheduleWindowStartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }()),
},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeHourly),
},
SnapshotConsistencyType: to.Ptr(armrecoveryservicesbackup.IaasVMSnapshotConsistencyTypeOnlyCrashConsistent),
TimeZone: to.Ptr("India Standard Time"),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("v2-daily-sample"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample"),
// Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
// BackupManagementType: to.Ptr("AzureIaasVM"),
// ProtectedItemsCount: to.Ptr[int32](0),
// InstantRpRetentionRangeInDays: to.Ptr[int32](30),
// PolicyType: to.Ptr(armrecoveryservicesbackup.IAASVMPolicyTypeV2),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](180),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](60),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](12),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](10),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicyV2{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicyV2"),
// HourlySchedule: &armrecoveryservicesbackup.HourlySchedule{
// Interval: to.Ptr[int32](4),
// ScheduleWindowDuration: to.Ptr[int32](16),
// ScheduleWindowStartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}()),
// },
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeHourly),
// },
// SnapshotConsistencyType: to.Ptr(armrecoveryservicesbackup.IaasVMSnapshotConsistencyTypeOnlyCrashConsistent),
// TimeZone: to.Ptr("India Standard Time"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
*
* @summary Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
* x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/V2Policy/IaaS_v2_hourly.json
*/
async function createOrUpdateEnhancedAzureVMProtectionPolicyWithHourlyBackup() {
const subscriptionId =
process.env["RECOVERYSERVICESBACKUP_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const vaultName = "NetSDKTestRsVault";
const resourceGroupName = process.env["RECOVERYSERVICESBACKUP_RESOURCE_GROUP"] || "SwaggerTestRg";
const policyName = "v2-daily-sample";
const parameters = {
properties: {
backupManagementType: "AzureIaasVM",
instantRpRetentionRangeInDays: 30,
policyType: "V2",
retentionPolicy: {
dailySchedule: {
retentionDuration: { count: 180, durationType: "Days" },
retentionTimes: [new Date("2021-12-17T08:00:00+00:00")],
},
monthlySchedule: {
retentionDuration: { count: 60, durationType: "Months" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [new Date("2021-12-17T08:00:00+00:00")],
},
retentionPolicyType: "LongTermRetentionPolicy",
weeklySchedule: {
daysOfTheWeek: ["Sunday"],
retentionDuration: { count: 12, durationType: "Weeks" },
retentionTimes: [new Date("2021-12-17T08:00:00+00:00")],
},
yearlySchedule: {
monthsOfYear: ["January"],
retentionDuration: { count: 10, durationType: "Years" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [new Date("2021-12-17T08:00:00+00:00")],
},
},
schedulePolicy: {
hourlySchedule: {
interval: 4,
scheduleWindowDuration: 16,
scheduleWindowStartTime: new Date("2021-12-17T08:00:00Z"),
},
schedulePolicyType: "SimpleSchedulePolicyV2",
scheduleRunFrequency: "Hourly",
},
snapshotConsistencyType: "OnlyCrashConsistent",
timeZone: "India Standard Time",
},
};
const credential = new DefaultAzureCredential();
const client = new RecoveryServicesBackupClient(credential, subscriptionId);
const result = await client.protectionPolicies.createOrUpdate(
vaultName,
resourceGroupName,
policyName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample",
"name": "v2-daily-sample",
"properties": {
"backupManagementType": "AzureIaasVM",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"snapshotConsistencyType": "OnlyCrashConsistent",
"protectedItemsCount": 0,
"resourceGuardOperationRequests": null,
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {
"count": 180,
"durationType": "Days"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"monthlySchedule": {
"retentionDuration": {
"count": 60,
"durationType": "Months"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"yearlySchedule": {
"monthsOfYear": [
"January"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
}
},
"schedulePolicy": {
"hourlySchedule": {
"interval": 4,
"scheduleWindowDuration": 16,
"scheduleWindowStartTime": "2021-12-17T08:00:00Z"
},
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Hourly"
},
"timeZone": "India Standard Time"
},
"type": "Microsoft.RecoveryServices/vaults/backupPolicies"
}
Location: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample/operationResults/00000000-0000-0000-0000-000000000000?api-version=2020-06-01
Azure-AsyncOperation: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample/operations/00000000-0000-0000-0000-000000000000?api-version=2020-06-01
Retry-After: 60
Create or Update Full Azure Vm Protection Policy
Sample request
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1?api-version=2024-04-01
{
"properties": {
"backupManagementType": "AzureIaasVM",
"timeZone": "Pacific Standard Time",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Weekly",
"scheduleRunTimes": [
"2018-01-24T10:00:00Z"
],
"scheduleRunDays": [
"Monday",
"Wednesday",
"Thursday"
]
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": [
"Monday",
"Wednesday",
"Thursday"
],
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 1,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Wednesday",
"Thursday"
],
"weeksOfTheMonth": [
"First",
"Third"
]
},
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 2,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"February",
"November"
],
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Monday",
"Thursday"
],
"weeksOfTheMonth": [
"Fourth"
]
},
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 4,
"durationType": "Years"
}
}
}
}
}
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureIaaSvmProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.LongTermRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthOfYear;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthlyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionScheduleFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeekOfMonth;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Samples for ProtectionPolicies CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/
* AzureIaasVm/ProtectionPolicies_CreateOrUpdate_Complex.json
*/
/**
* Sample code: Create or Update Full Azure Vm Protection Policy.
*
* @param manager Entry point to RecoveryServicesBackupManager.
*/
public static void createOrUpdateFullAzureVmProtectionPolicy(
com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager manager) {
manager.protectionPolicies().define("testPolicy1").withRegion((String) null)
.withExistingVault("NetSDKTestRsVault", "SwaggerTestRg")
.withProperties(
new AzureIaaSvmProtectionPolicy()
.withSchedulePolicy(new SimpleSchedulePolicy().withScheduleRunFrequency(ScheduleRunType.WEEKLY)
.withScheduleRunDays(Arrays.asList(DayOfWeek.MONDAY, DayOfWeek.WEDNESDAY,
DayOfWeek.THURSDAY))
.withScheduleRunTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T10:00:00Z"))))
.withRetentionPolicy(
new LongTermRetentionPolicy()
.withWeeklySchedule(
new WeeklyRetentionSchedule()
.withDaysOfTheWeek(
Arrays.asList(DayOfWeek.MONDAY, DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T10:00:00Z")))
.withRetentionDuration(new RetentionDuration().withCount(1)
.withDurationType(RetentionDurationType.WEEKS)))
.withMonthlySchedule(new MonthlyRetentionSchedule()
.withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withRetentionScheduleWeekly(new WeeklyRetentionFormat()
.withDaysOfTheWeek(Arrays.asList(DayOfWeek.WEDNESDAY, DayOfWeek.THURSDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST, WeekOfMonth.THIRD)))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T10:00:00Z")))
.withRetentionDuration(new RetentionDuration().withCount(2)
.withDurationType(RetentionDurationType.MONTHS)))
.withYearlySchedule(new YearlyRetentionSchedule()
.withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withMonthsOfYear(Arrays.asList(MonthOfYear.FEBRUARY, MonthOfYear.NOVEMBER))
.withRetentionScheduleWeekly(new WeeklyRetentionFormat()
.withDaysOfTheWeek(Arrays.asList(DayOfWeek.MONDAY, DayOfWeek.THURSDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FOURTH)))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T10:00:00Z")))
.withRetentionDuration(new RetentionDuration().withCount(4)
.withDurationType(RetentionDurationType.YEARS))))
.withTimeZone("Pacific Standard Time"))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from typing import Any, IO, Union
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_complex.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="NetSDKTestRsVault",
resource_group_name="SwaggerTestRg",
policy_name="testPolicy1",
parameters={
"properties": {
"backupManagementType": "AzureIaasVM",
"retentionPolicy": {
"monthlySchedule": {
"retentionDuration": {"count": 2, "durationType": "Months"},
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": ["Wednesday", "Thursday"],
"weeksOfTheMonth": ["First", "Third"],
},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Monday", "Wednesday", "Thursday"],
"retentionDuration": {"count": 1, "durationType": "Weeks"},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
"yearlySchedule": {
"monthsOfYear": ["February", "November"],
"retentionDuration": {"count": 4, "durationType": "Years"},
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": ["Monday", "Thursday"],
"weeksOfTheMonth": ["Fourth"],
},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
},
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunDays": ["Monday", "Wednesday", "Thursday"],
"scheduleRunFrequency": "Weekly",
"scheduleRunTimes": ["2018-01-24T10:00:00Z"],
},
"timeZone": "Pacific Standard Time",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/ProtectionPolicies_CreateOrUpdate_Complex.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armrecoveryservicesbackup_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/33c4457b1d13f83965f4fe3367dca4a6df898100/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/ProtectionPolicies_CreateOrUpdate_Complex.json
func ExampleProtectionPoliciesClient_CreateOrUpdate_createOrUpdateFullAzureVmProtectionPolicy() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armrecoveryservicesbackup.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewProtectionPoliciesClient().CreateOrUpdate(ctx, "NetSDKTestRsVault", "SwaggerTestRg", "testPolicy1", armrecoveryservicesbackup.ProtectionPolicyResource{
Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
BackupManagementType: to.Ptr("AzureIaasVM"),
RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](2),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekWednesday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst),
to.Ptr(armrecoveryservicesbackup.WeekOfMonthThird)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekWednesday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](1),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearFebruary),
to.Ptr(armrecoveryservicesbackup.MonthOfYearNovember)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](4),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFourth)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekWednesday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
TimeZone: to.Ptr("Pacific Standard Time"),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("testPolicy1"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1"),
// Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
// BackupManagementType: to.Ptr("AzureIaasVM"),
// ProtectedItemsCount: to.Ptr[int32](0),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](2),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekWednesday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst),
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthThird)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekWednesday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](1),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearFebruary),
// to.Ptr(armrecoveryservicesbackup.MonthOfYearNovember)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](4),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFourth)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekWednesday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// TimeZone: to.Ptr("Pacific Standard Time"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
*
* @summary Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
* x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/ProtectionPolicies_CreateOrUpdate_Complex.json
*/
async function createOrUpdateFullAzureVMProtectionPolicy() {
const subscriptionId =
process.env["RECOVERYSERVICESBACKUP_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const vaultName = "NetSDKTestRsVault";
const resourceGroupName = process.env["RECOVERYSERVICESBACKUP_RESOURCE_GROUP"] || "SwaggerTestRg";
const policyName = "testPolicy1";
const parameters = {
properties: {
backupManagementType: "AzureIaasVM",
retentionPolicy: {
monthlySchedule: {
retentionDuration: { count: 2, durationType: "Months" },
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Wednesday", "Thursday"],
weeksOfTheMonth: ["First", "Third"],
},
retentionTimes: [new Date("2018-01-24T10:00:00Z")],
},
retentionPolicyType: "LongTermRetentionPolicy",
weeklySchedule: {
daysOfTheWeek: ["Monday", "Wednesday", "Thursday"],
retentionDuration: { count: 1, durationType: "Weeks" },
retentionTimes: [new Date("2018-01-24T10:00:00Z")],
},
yearlySchedule: {
monthsOfYear: ["February", "November"],
retentionDuration: { count: 4, durationType: "Years" },
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Monday", "Thursday"],
weeksOfTheMonth: ["Fourth"],
},
retentionTimes: [new Date("2018-01-24T10:00:00Z")],
},
},
schedulePolicy: {
schedulePolicyType: "SimpleSchedulePolicy",
scheduleRunDays: ["Monday", "Wednesday", "Thursday"],
scheduleRunFrequency: "Weekly",
scheduleRunTimes: [new Date("2018-01-24T10:00:00Z")],
},
timeZone: "Pacific Standard Time",
},
};
const credential = new DefaultAzureCredential();
const client = new RecoveryServicesBackupClient(credential, subscriptionId);
const result = await client.protectionPolicies.createOrUpdate(
vaultName,
resourceGroupName,
policyName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"id": "/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1",
"name": "testPolicy1",
"type": "Microsoft.RecoveryServices/vaults/backupPolicies",
"properties": {
"backupManagementType": "AzureIaasVM",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Weekly",
"scheduleRunDays": [
"Monday",
"Wednesday",
"Thursday"
],
"scheduleRunTimes": [
"2018-01-24T10:00:00Z"
],
"scheduleWeeklyFrequency": 0
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": [
"Monday",
"Wednesday",
"Thursday"
],
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 1,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Wednesday",
"Thursday"
],
"weeksOfTheMonth": [
"First",
"Third"
]
},
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 2,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"February",
"November"
],
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Monday",
"Thursday"
],
"weeksOfTheMonth": [
"Fourth"
]
},
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 4,
"durationType": "Years"
}
}
},
"timeZone": "Pacific Standard Time",
"protectedItemsCount": 0
}
}
Location: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1/operationResults/00000000-0000-0000-0000-000000000000?api-version=2016-06-01
Azure-AsyncOperation: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1/operations/00000000-0000-0000-0000-000000000000?api-version=2016-06-01
Retry-After: 60
Create or Update Full Azure Workload Protection Policy
Sample request
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1?api-version=2024-04-01
{
"properties": {
"backupManagementType": "AzureWorkload",
"workLoadType": "SQLDataBase",
"settings": {
"timeZone": "Pacific Standard Time",
"issqlcompression": false
},
"subProtectionPolicy": [
{
"policyType": "Full",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Weekly",
"scheduleRunTimes": [
"2018-01-24T10:00:00Z"
],
"scheduleRunDays": [
"Sunday",
"Tuesday"
]
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday",
"Tuesday"
],
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 2,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"Second"
]
},
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 1,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"January",
"June",
"December"
],
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"Last"
]
},
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 1,
"durationType": "Years"
}
}
}
},
{
"policyType": "Differential",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Weekly",
"scheduleRunTimes": [
"2018-01-24T10:00:00Z"
],
"scheduleRunDays": [
"Friday"
]
},
"retentionPolicy": {
"retentionPolicyType": "SimpleRetentionPolicy",
"retentionDuration": {
"count": 8,
"durationType": "Days"
}
}
},
{
"policyType": "Log",
"schedulePolicy": {
"schedulePolicyType": "LogSchedulePolicy",
"scheduleFrequencyInMins": 60
},
"retentionPolicy": {
"retentionPolicyType": "SimpleRetentionPolicy",
"retentionDuration": {
"count": 7,
"durationType": "Days"
}
}
}
]
}
}
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureVmWorkloadProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.LogSchedulePolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.LongTermRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthOfYear;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthlyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.PolicyType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionScheduleFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.Settings;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.SubProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeekOfMonth;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.WorkloadType;
import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Samples for ProtectionPolicies CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/
* AzureWorkload/ProtectionPolicies_CreateOrUpdate_Complex.json
*/
/**
* Sample code: Create or Update Full Azure Workload Protection Policy.
*
* @param manager Entry point to RecoveryServicesBackupManager.
*/
public static void createOrUpdateFullAzureWorkloadProtectionPolicy(
com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager manager) {
manager
.protectionPolicies().define(
"testPolicy1")
.withRegion((String) null).withExistingVault("NetSDKTestRsVault", "SwaggerTestRg")
.withProperties(
new AzureVmWorkloadProtectionPolicy().withWorkLoadType(WorkloadType.SQLDATA_BASE)
.withSettings(new Settings().withTimeZone("Pacific Standard Time").withIssqlcompression(false))
.withSubProtectionPolicy(Arrays.asList(
new SubProtectionPolicy().withPolicyType(PolicyType.FULL)
.withSchedulePolicy(
new SimpleSchedulePolicy().withScheduleRunFrequency(ScheduleRunType.WEEKLY)
.withScheduleRunDays(Arrays.asList(DayOfWeek.SUNDAY, DayOfWeek.TUESDAY))
.withScheduleRunTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T10:00:00Z"))))
.withRetentionPolicy(
new LongTermRetentionPolicy()
.withWeeklySchedule(new WeeklyRetentionSchedule()
.withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY, DayOfWeek.TUESDAY))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T10:00:00Z")))
.withRetentionDuration(new RetentionDuration().withCount(2)
.withDurationType(RetentionDurationType.WEEKS)))
.withMonthlySchedule(new MonthlyRetentionSchedule()
.withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withRetentionScheduleWeekly(new WeeklyRetentionFormat()
.withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.SECOND)))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T10:00:00Z")))
.withRetentionDuration(new RetentionDuration().withCount(1)
.withDurationType(RetentionDurationType.MONTHS)))
.withYearlySchedule(new YearlyRetentionSchedule()
.withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withMonthsOfYear(
Arrays.asList(MonthOfYear.JANUARY, MonthOfYear.JUNE, MonthOfYear.DECEMBER))
.withRetentionScheduleWeekly(new WeeklyRetentionFormat()
.withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.LAST)))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T10:00:00Z")))
.withRetentionDuration(new RetentionDuration().withCount(1)
.withDurationType(RetentionDurationType.YEARS)))),
new SubProtectionPolicy().withPolicyType(PolicyType.DIFFERENTIAL)
.withSchedulePolicy(
new SimpleSchedulePolicy().withScheduleRunFrequency(ScheduleRunType.WEEKLY)
.withScheduleRunDays(Arrays.asList(DayOfWeek.FRIDAY))
.withScheduleRunTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T10:00:00Z"))))
.withRetentionPolicy(new SimpleRetentionPolicy().withRetentionDuration(
new RetentionDuration().withCount(8).withDurationType(RetentionDurationType.DAYS))),
new SubProtectionPolicy().withPolicyType(PolicyType.LOG)
.withSchedulePolicy(new LogSchedulePolicy().withScheduleFrequencyInMins(60))
.withRetentionPolicy(new SimpleRetentionPolicy().withRetentionDuration(
new RetentionDuration().withCount(7).withDurationType(RetentionDurationType.DAYS))))))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from typing import Any, IO, Union
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_complex.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="NetSDKTestRsVault",
resource_group_name="SwaggerTestRg",
policy_name="testPolicy1",
parameters={
"properties": {
"backupManagementType": "AzureWorkload",
"settings": {"issqlcompression": False, "timeZone": "Pacific Standard Time"},
"subProtectionPolicy": [
{
"policyType": "Full",
"retentionPolicy": {
"monthlySchedule": {
"retentionDuration": {"count": 1, "durationType": "Months"},
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["Second"]},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday", "Tuesday"],
"retentionDuration": {"count": 2, "durationType": "Weeks"},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
"yearlySchedule": {
"monthsOfYear": ["January", "June", "December"],
"retentionDuration": {"count": 1, "durationType": "Years"},
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["Last"]},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
},
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunDays": ["Sunday", "Tuesday"],
"scheduleRunFrequency": "Weekly",
"scheduleRunTimes": ["2018-01-24T10:00:00Z"],
},
},
{
"policyType": "Differential",
"retentionPolicy": {
"retentionDuration": {"count": 8, "durationType": "Days"},
"retentionPolicyType": "SimpleRetentionPolicy",
},
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunDays": ["Friday"],
"scheduleRunFrequency": "Weekly",
"scheduleRunTimes": ["2018-01-24T10:00:00Z"],
},
},
{
"policyType": "Log",
"retentionPolicy": {
"retentionDuration": {"count": 7, "durationType": "Days"},
"retentionPolicyType": "SimpleRetentionPolicy",
},
"schedulePolicy": {"scheduleFrequencyInMins": 60, "schedulePolicyType": "LogSchedulePolicy"},
},
],
"workLoadType": "SQLDataBase",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureWorkload/ProtectionPolicies_CreateOrUpdate_Complex.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armrecoveryservicesbackup_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/33c4457b1d13f83965f4fe3367dca4a6df898100/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureWorkload/ProtectionPolicies_CreateOrUpdate_Complex.json
func ExampleProtectionPoliciesClient_CreateOrUpdate_createOrUpdateFullAzureWorkloadProtectionPolicy() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armrecoveryservicesbackup.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewProtectionPoliciesClient().CreateOrUpdate(ctx, "NetSDKTestRsVault", "SwaggerTestRg", "testPolicy1", armrecoveryservicesbackup.ProtectionPolicyResource{
Properties: &armrecoveryservicesbackup.AzureVMWorkloadProtectionPolicy{
BackupManagementType: to.Ptr("AzureWorkload"),
Settings: &armrecoveryservicesbackup.Settings{
Issqlcompression: to.Ptr(false),
TimeZone: to.Ptr("Pacific Standard Time"),
},
SubProtectionPolicy: []*armrecoveryservicesbackup.SubProtectionPolicy{
{
PolicyType: to.Ptr(armrecoveryservicesbackup.PolicyTypeFull),
RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](1),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthSecond)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekTuesday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](2),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary),
to.Ptr(armrecoveryservicesbackup.MonthOfYearJune),
to.Ptr(armrecoveryservicesbackup.MonthOfYearDecember)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](1),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthLast)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekTuesday)},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
},
{
PolicyType: to.Ptr(armrecoveryservicesbackup.PolicyTypeDifferential),
RetentionPolicy: &armrecoveryservicesbackup.SimpleRetentionPolicy{
RetentionPolicyType: to.Ptr("SimpleRetentionPolicy"),
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](8),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekFriday)},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
},
{
PolicyType: to.Ptr(armrecoveryservicesbackup.PolicyTypeLog),
RetentionPolicy: &armrecoveryservicesbackup.SimpleRetentionPolicy{
RetentionPolicyType: to.Ptr("SimpleRetentionPolicy"),
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](7),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
},
},
SchedulePolicy: &armrecoveryservicesbackup.LogSchedulePolicy{
SchedulePolicyType: to.Ptr("LogSchedulePolicy"),
ScheduleFrequencyInMins: to.Ptr[int32](60),
},
}},
WorkLoadType: to.Ptr(armrecoveryservicesbackup.WorkloadTypeSQLDataBase),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("testPolicy1"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1"),
// Properties: &armrecoveryservicesbackup.AzureVMWorkloadProtectionPolicy{
// BackupManagementType: to.Ptr("AzureWorkload"),
// ProtectedItemsCount: to.Ptr[int32](0),
// Settings: &armrecoveryservicesbackup.Settings{
// Issqlcompression: to.Ptr(false),
// TimeZone: to.Ptr("Pacific Standard Time"),
// },
// SubProtectionPolicy: []*armrecoveryservicesbackup.SubProtectionPolicy{
// {
// PolicyType: to.Ptr(armrecoveryservicesbackup.PolicyTypeFull),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](1),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthSecond)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekTuesday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](2),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary),
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJune),
// to.Ptr(armrecoveryservicesbackup.MonthOfYearDecember)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](1),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthLast)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekTuesday)},
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// },
// {
// PolicyType: to.Ptr(armrecoveryservicesbackup.PolicyTypeDifferential),
// RetentionPolicy: &armrecoveryservicesbackup.SimpleRetentionPolicy{
// RetentionPolicyType: to.Ptr("SimpleRetentionPolicy"),
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](8),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekFriday)},
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// },
// {
// PolicyType: to.Ptr(armrecoveryservicesbackup.PolicyTypeLog),
// RetentionPolicy: &armrecoveryservicesbackup.SimpleRetentionPolicy{
// RetentionPolicyType: to.Ptr("SimpleRetentionPolicy"),
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](7),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.LogSchedulePolicy{
// SchedulePolicyType: to.Ptr("LogSchedulePolicy"),
// ScheduleFrequencyInMins: to.Ptr[int32](60),
// },
// }},
// WorkLoadType: to.Ptr(armrecoveryservicesbackup.WorkloadTypeSQLDataBase),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
*
* @summary Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
* x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureWorkload/ProtectionPolicies_CreateOrUpdate_Complex.json
*/
async function createOrUpdateFullAzureWorkloadProtectionPolicy() {
const subscriptionId =
process.env["RECOVERYSERVICESBACKUP_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const vaultName = "NetSDKTestRsVault";
const resourceGroupName = process.env["RECOVERYSERVICESBACKUP_RESOURCE_GROUP"] || "SwaggerTestRg";
const policyName = "testPolicy1";
const parameters = {
properties: {
backupManagementType: "AzureWorkload",
settings: { issqlcompression: false, timeZone: "Pacific Standard Time" },
subProtectionPolicy: [
{
policyType: "Full",
retentionPolicy: {
monthlySchedule: {
retentionDuration: { count: 1, durationType: "Months" },
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["Second"],
},
retentionTimes: [new Date("2018-01-24T10:00:00Z")],
},
retentionPolicyType: "LongTermRetentionPolicy",
weeklySchedule: {
daysOfTheWeek: ["Sunday", "Tuesday"],
retentionDuration: { count: 2, durationType: "Weeks" },
retentionTimes: [new Date("2018-01-24T10:00:00Z")],
},
yearlySchedule: {
monthsOfYear: ["January", "June", "December"],
retentionDuration: { count: 1, durationType: "Years" },
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["Last"],
},
retentionTimes: [new Date("2018-01-24T10:00:00Z")],
},
},
schedulePolicy: {
schedulePolicyType: "SimpleSchedulePolicy",
scheduleRunDays: ["Sunday", "Tuesday"],
scheduleRunFrequency: "Weekly",
scheduleRunTimes: [new Date("2018-01-24T10:00:00Z")],
},
},
{
policyType: "Differential",
retentionPolicy: {
retentionDuration: { count: 8, durationType: "Days" },
retentionPolicyType: "SimpleRetentionPolicy",
},
schedulePolicy: {
schedulePolicyType: "SimpleSchedulePolicy",
scheduleRunDays: ["Friday"],
scheduleRunFrequency: "Weekly",
scheduleRunTimes: [new Date("2018-01-24T10:00:00Z")],
},
},
{
policyType: "Log",
retentionPolicy: {
retentionDuration: { count: 7, durationType: "Days" },
retentionPolicyType: "SimpleRetentionPolicy",
},
schedulePolicy: {
scheduleFrequencyInMins: 60,
schedulePolicyType: "LogSchedulePolicy",
},
},
],
workLoadType: "SQLDataBase",
},
};
const credential = new DefaultAzureCredential();
const client = new RecoveryServicesBackupClient(credential, subscriptionId);
const result = await client.protectionPolicies.createOrUpdate(
vaultName,
resourceGroupName,
policyName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"id": "/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1",
"name": "testPolicy1",
"type": "Microsoft.RecoveryServices/vaults/backupPolicies",
"properties": {
"backupManagementType": "AzureWorkload",
"workLoadType": "SQLDataBase",
"settings": {
"timeZone": "Pacific Standard Time",
"issqlcompression": false
},
"subProtectionPolicy": [
{
"policyType": "Full",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Weekly",
"scheduleRunDays": [
"Sunday",
"Tuesday"
],
"scheduleRunTimes": [
"2018-01-24T10:00:00Z"
],
"scheduleWeeklyFrequency": 0
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday",
"Tuesday"
],
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 2,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"Second"
]
},
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 1,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"January",
"June",
"December"
],
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"Last"
]
},
"retentionTimes": [
"2018-01-24T10:00:00Z"
],
"retentionDuration": {
"count": 1,
"durationType": "Years"
}
}
}
},
{
"policyType": "Differential",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Weekly",
"scheduleRunDays": [
"Friday"
],
"scheduleRunTimes": [
"2018-01-24T10:00:00Z"
],
"scheduleWeeklyFrequency": 0
},
"retentionPolicy": {
"retentionPolicyType": "SimpleRetentionPolicy",
"retentionDuration": {
"count": 8,
"durationType": "Days"
}
}
},
{
"policyType": "Log",
"schedulePolicy": {
"schedulePolicyType": "LogSchedulePolicy",
"scheduleFrequencyInMins": 60
},
"retentionPolicy": {
"retentionPolicyType": "SimpleRetentionPolicy",
"retentionDuration": {
"count": 7,
"durationType": "Days"
}
}
}
],
"protectedItemsCount": 0
}
}
Location: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1/operationResults/00000000-0000-0000-0000-000000000000?api-version=2016-06-01
Azure-AsyncOperation: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1/operations/00000000-0000-0000-0000-000000000000?api-version=2016-06-01
Retry-After: 60
Create or Update Hourly Azure Storage Protection Policy
Sample request
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicy2?api-version=2024-04-01
{
"properties": {
"backupManagementType": "AzureStorage",
"workLoadType": "AzureFileShare",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Hourly",
"hourlySchedule": {
"interval": 4,
"scheduleWindowStartTime": "2021-09-29T08:00:00.000Z",
"scheduleWindowDuration": 12
}
},
"timeZone": "UTC",
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionTimes": null,
"retentionDuration": {
"count": 5,
"durationType": "Days"
}
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionTimes": null,
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": null,
"retentionDuration": {
"count": 60,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"January"
],
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": null,
"retentionDuration": {
"count": 10,
"durationType": "Years"
}
}
}
}
}
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureFileShareProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.HourlySchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.LongTermRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthOfYear;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthlyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionScheduleFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeekOfMonth;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.WorkloadType;
import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Samples for ProtectionPolicies CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/
* AzureStorage/ProtectionPolicies_CreateOrUpdate_Hourly.json
*/
/**
* Sample code: Create or Update Hourly Azure Storage Protection Policy.
*
* @param manager Entry point to RecoveryServicesBackupManager.
*/
public static void createOrUpdateHourlyAzureStorageProtectionPolicy(
com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager manager) {
manager.protectionPolicies().define("newPolicy2").withRegion((String) null)
.withExistingVault("swaggertestvault", "SwaggerTestRg")
.withProperties(new AzureFileShareProtectionPolicy().withWorkLoadType(WorkloadType.AZURE_FILE_SHARE)
.withSchedulePolicy(new SimpleSchedulePolicy().withScheduleRunFrequency(ScheduleRunType.HOURLY)
.withHourlySchedule(new HourlySchedule().withInterval(4)
.withScheduleWindowStartTime(OffsetDateTime.parse("2021-09-29T08:00:00.000Z"))
.withScheduleWindowDuration(12)))
.withRetentionPolicy(
new LongTermRetentionPolicy()
.withDailySchedule(new DailyRetentionSchedule().withRetentionDuration(
new RetentionDuration().withCount(5).withDurationType(RetentionDurationType.DAYS)))
.withWeeklySchedule(
new WeeklyRetentionSchedule().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withRetentionDuration(new RetentionDuration().withCount(12)
.withDurationType(RetentionDurationType.WEEKS)))
.withMonthlySchedule(new MonthlyRetentionSchedule()
.withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withRetentionScheduleWeekly(
new WeeklyRetentionFormat().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionDuration(
new RetentionDuration().withCount(60).withDurationType(RetentionDurationType.MONTHS)))
.withYearlySchedule(new YearlyRetentionSchedule()
.withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withMonthsOfYear(Arrays.asList(MonthOfYear.JANUARY))
.withRetentionScheduleWeekly(
new WeeklyRetentionFormat().withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionDuration(
new RetentionDuration().withCount(10).withDurationType(RetentionDurationType.YEARS))))
.withTimeZone("UTC"))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from typing import Any, IO, Union
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_hourly.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="swaggertestvault",
resource_group_name="SwaggerTestRg",
policy_name="newPolicy2",
parameters={
"properties": {
"backupManagementType": "AzureStorage",
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {"count": 5, "durationType": "Days"},
"retentionTimes": None,
},
"monthlySchedule": {
"retentionDuration": {"count": 60, "durationType": "Months"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": None,
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday"],
"retentionDuration": {"count": 12, "durationType": "Weeks"},
"retentionTimes": None,
},
"yearlySchedule": {
"monthsOfYear": ["January"],
"retentionDuration": {"count": 10, "durationType": "Years"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": None,
},
},
"schedulePolicy": {
"hourlySchedule": {
"interval": 4,
"scheduleWindowDuration": 12,
"scheduleWindowStartTime": "2021-09-29T08:00:00.000Z",
},
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Hourly",
},
"timeZone": "UTC",
"workLoadType": "AzureFileShare",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Hourly.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armrecoveryservicesbackup_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/33c4457b1d13f83965f4fe3367dca4a6df898100/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Hourly.json
func ExampleProtectionPoliciesClient_CreateOrUpdate_createOrUpdateHourlyAzureStorageProtectionPolicy() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armrecoveryservicesbackup.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewProtectionPoliciesClient().CreateOrUpdate(ctx, "swaggertestvault", "SwaggerTestRg", "newPolicy2", armrecoveryservicesbackup.ProtectionPolicyResource{
Properties: &armrecoveryservicesbackup.AzureFileShareProtectionPolicy{
BackupManagementType: to.Ptr("AzureStorage"),
RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](5),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
},
},
MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](60),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](12),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](10),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
HourlySchedule: &armrecoveryservicesbackup.HourlySchedule{
Interval: to.Ptr[int32](4),
ScheduleWindowDuration: to.Ptr[int32](12),
ScheduleWindowStartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t }()),
},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeHourly),
},
TimeZone: to.Ptr("UTC"),
WorkLoadType: to.Ptr(armrecoveryservicesbackup.WorkloadTypeAzureFileShare),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("newPolicy2"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicy2"),
// Properties: &armrecoveryservicesbackup.AzureFileShareProtectionPolicy{
// BackupManagementType: to.Ptr("AzureStorage"),
// ProtectedItemsCount: to.Ptr[int32](0),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](5),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T20:00:00.000Z"); return t}())},
// },
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](60),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T20:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](12),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T20:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](10),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T20:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// HourlySchedule: &armrecoveryservicesbackup.HourlySchedule{
// Interval: to.Ptr[int32](4),
// ScheduleWindowDuration: to.Ptr[int32](12),
// ScheduleWindowStartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}()),
// },
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeHourly),
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// TimeZone: to.Ptr("UTC"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
*
* @summary Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
* x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Hourly.json
*/
async function createOrUpdateHourlyAzureStorageProtectionPolicy() {
const subscriptionId =
process.env["RECOVERYSERVICESBACKUP_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const vaultName = "swaggertestvault";
const resourceGroupName = process.env["RECOVERYSERVICESBACKUP_RESOURCE_GROUP"] || "SwaggerTestRg";
const policyName = "newPolicy2";
const parameters = {
properties: {
backupManagementType: "AzureStorage",
retentionPolicy: {
dailySchedule: {
retentionDuration: { count: 5, durationType: "Days" },
retentionTimes: [],
},
monthlySchedule: {
retentionDuration: { count: 60, durationType: "Months" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [],
},
retentionPolicyType: "LongTermRetentionPolicy",
weeklySchedule: {
daysOfTheWeek: ["Sunday"],
retentionDuration: { count: 12, durationType: "Weeks" },
retentionTimes: [],
},
yearlySchedule: {
monthsOfYear: ["January"],
retentionDuration: { count: 10, durationType: "Years" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [],
},
},
schedulePolicy: {
hourlySchedule: {
interval: 4,
scheduleWindowDuration: 12,
scheduleWindowStartTime: new Date("2021-09-29T08:00:00.000Z"),
},
schedulePolicyType: "SimpleSchedulePolicy",
scheduleRunFrequency: "Hourly",
},
timeZone: "UTC",
workLoadType: "AzureFileShare",
},
};
const credential = new DefaultAzureCredential();
const client = new RecoveryServicesBackupClient(credential, subscriptionId);
const result = await client.protectionPolicies.createOrUpdate(
vaultName,
resourceGroupName,
policyName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicy2",
"name": "newPolicy2",
"type": "Microsoft.RecoveryServices/vaults/backupPolicies",
"properties": {
"backupManagementType": "AzureStorage",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Hourly",
"hourlySchedule": {
"interval": 4,
"scheduleWindowStartTime": "2021-09-29T08:00:00Z",
"scheduleWindowDuration": 12
},
"scheduleWeeklyFrequency": 0
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionTimes": [
"2021-09-29T20:00:00Z"
],
"retentionDuration": {
"count": 5,
"durationType": "Days"
}
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionTimes": [
"2021-09-29T20:00:00Z"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-09-29T20:00:00Z"
],
"retentionDuration": {
"count": 60,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"January"
],
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-09-29T20:00:00Z"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
}
}
},
"timeZone": "UTC",
"protectedItemsCount": 0
}
}
Location: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicy2/operationResults/00000000-0000-0000-0000-000000000000?api-version=2016-06-01
Azure-AsyncOperation: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicy2/operations/00000000-0000-0000-0000-000000000000?api-version=2016-06-01
Retry-After: 60
Create or Update Simple Azure Vm Protection Policy
Sample request
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1?api-version=2024-04-01
{
"properties": {
"backupManagementType": "AzureIaasVM",
"timeZone": "Pacific Standard Time",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": [
"2018-01-24T02:00:00Z"
]
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionTimes": [
"2018-01-24T02:00:00Z"
],
"retentionDuration": {
"count": 1,
"durationType": "Days"
}
}
}
}
}
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureIaaSvmProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.LongTermRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicy;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Samples for ProtectionPolicies CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/
* AzureIaasVm/ProtectionPolicies_CreateOrUpdate_Simple.json
*/
/**
* Sample code: Create or Update Simple Azure Vm Protection Policy.
*
* @param manager Entry point to RecoveryServicesBackupManager.
*/
public static void createOrUpdateSimpleAzureVmProtectionPolicy(
com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager manager) {
manager.protectionPolicies().define("testPolicy1").withRegion((String) null)
.withExistingVault("NetSDKTestRsVault",
"SwaggerTestRg")
.withProperties(new AzureIaaSvmProtectionPolicy()
.withSchedulePolicy(new SimpleSchedulePolicy().withScheduleRunFrequency(ScheduleRunType.DAILY)
.withScheduleRunTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T02:00:00Z"))))
.withRetentionPolicy(new LongTermRetentionPolicy().withDailySchedule(new DailyRetentionSchedule()
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2018-01-24T02:00:00Z")))
.withRetentionDuration(
new RetentionDuration().withCount(1).withDurationType(RetentionDurationType.DAYS))))
.withTimeZone("Pacific Standard Time"))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from typing import Any, IO, Union
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_simple.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="NetSDKTestRsVault",
resource_group_name="SwaggerTestRg",
policy_name="testPolicy1",
parameters={
"properties": {
"backupManagementType": "AzureIaasVM",
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {"count": 1, "durationType": "Days"},
"retentionTimes": ["2018-01-24T02:00:00Z"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
},
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": ["2018-01-24T02:00:00Z"],
},
"timeZone": "Pacific Standard Time",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/ProtectionPolicies_CreateOrUpdate_Simple.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armrecoveryservicesbackup_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/33c4457b1d13f83965f4fe3367dca4a6df898100/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/ProtectionPolicies_CreateOrUpdate_Simple.json
func ExampleProtectionPoliciesClient_CreateOrUpdate_createOrUpdateSimpleAzureVmProtectionPolicy() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armrecoveryservicesbackup.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewProtectionPoliciesClient().CreateOrUpdate(ctx, "NetSDKTestRsVault", "SwaggerTestRg", "testPolicy1", armrecoveryservicesbackup.ProtectionPolicyResource{
Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
BackupManagementType: to.Ptr("AzureIaasVM"),
RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](1),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T02:00:00.000Z"); return t }())},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T02:00:00.000Z"); return t }())},
},
TimeZone: to.Ptr("Pacific Standard Time"),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("testPolicy1"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1"),
// Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
// BackupManagementType: to.Ptr("AzureIaasVM"),
// ProtectedItemsCount: to.Ptr[int32](0),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](1),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T02:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T02:00:00.000Z"); return t}())},
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// TimeZone: to.Ptr("Pacific Standard Time"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
*
* @summary Creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can be fetched
using GetPolicyOperationResult API.
* x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2024-04-01/examples/AzureIaasVm/ProtectionPolicies_CreateOrUpdate_Simple.json
*/
async function createOrUpdateSimpleAzureVMProtectionPolicy() {
const subscriptionId =
process.env["RECOVERYSERVICESBACKUP_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const vaultName = "NetSDKTestRsVault";
const resourceGroupName = process.env["RECOVERYSERVICESBACKUP_RESOURCE_GROUP"] || "SwaggerTestRg";
const policyName = "testPolicy1";
const parameters = {
properties: {
backupManagementType: "AzureIaasVM",
retentionPolicy: {
dailySchedule: {
retentionDuration: { count: 1, durationType: "Days" },
retentionTimes: [new Date("2018-01-24T02:00:00Z")],
},
retentionPolicyType: "LongTermRetentionPolicy",
},
schedulePolicy: {
schedulePolicyType: "SimpleSchedulePolicy",
scheduleRunFrequency: "Daily",
scheduleRunTimes: [new Date("2018-01-24T02:00:00Z")],
},
timeZone: "Pacific Standard Time",
},
};
const credential = new DefaultAzureCredential();
const client = new RecoveryServicesBackupClient(credential, subscriptionId);
const result = await client.protectionPolicies.createOrUpdate(
vaultName,
resourceGroupName,
policyName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample response
{
"id": "/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1",
"name": "testPolicy1",
"type": "Microsoft.RecoveryServices/vaults/backupPolicies",
"properties": {
"backupManagementType": "AzureIaasVM",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": [
"2018-01-24T02:00:00Z"
],
"scheduleWeeklyFrequency": 0
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionTimes": [
"2018-01-24T02:00:00Z"
],
"retentionDuration": {
"count": 1,
"durationType": "Days"
}
}
},
"timeZone": "Pacific Standard Time",
"protectedItemsCount": 0
}
}
Location: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1/operationResults/00000000-0000-0000-0000-000000000000?api-version=2016-06-01
Azure-AsyncOperation: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1/operations/00000000-0000-0000-0000-000000000000?api-version=2016-06-01
Retry-After: 60
Definitions
AzureFileShareProtectionPolicy
AzureStorage backup policy.
Name |
Type |
Description |
backupManagementType
|
string:
AzureStorage
|
This property will be used as the discriminator for deciding the specific types in the polymorphic chain of types.
|
protectedItemsCount
|
integer
|
Number of items associated with this policy.
|
resourceGuardOperationRequests
|
string[]
|
ResourceGuard Operation Requests
|
retentionPolicy
|
RetentionPolicy:
|
Retention policy with the details on backup copy retention ranges.
|
schedulePolicy
|
SchedulePolicy:
|
Backup schedule specified as part of backup policy.
|
timeZone
|
string
|
TimeZone optional input as string. For example: TimeZone = "Pacific Standard Time".
|
vaultRetentionPolicy
|
VaultRetentionPolicy
|
Retention policy with the details on hardened backup copy retention ranges.
|
workLoadType
|
WorkloadType
|
Type of workload for the backup management
|
AzureIaaSVMProtectionPolicy
IaaS VM workload-specific backup policy.
Name |
Type |
Description |
backupManagementType
|
string:
AzureIaasVM
|
This property will be used as the discriminator for deciding the specific types in the polymorphic chain of types.
|
instantRPDetails
|
InstantRPAdditionalDetails
|
|
instantRpRetentionRangeInDays
|
integer
|
Instant RP retention policy range in days
|
policyType
|
IAASVMPolicyType
|
|
protectedItemsCount
|
integer
|
Number of items associated with this policy.
|
resourceGuardOperationRequests
|
string[]
|
ResourceGuard Operation Requests
|
retentionPolicy
|
RetentionPolicy:
|
Retention policy with the details on backup copy retention ranges.
|
schedulePolicy
|
SchedulePolicy:
|
Backup schedule specified as part of backup policy.
|
snapshotConsistencyType
|
IaasVMSnapshotConsistencyType
|
|
tieringPolicy
|
<string,
TieringPolicy>
|
Tiering policy to automatically move RPs to another tier
Key is Target Tier, defined in RecoveryPointTierType enum.
Tiering policy specifies the criteria to move RP to the target tier.
|
timeZone
|
string
|
TimeZone optional input as string. For example: TimeZone = "Pacific Standard Time".
|
AzureSqlProtectionPolicy
Azure SQL workload-specific backup policy.
Name |
Type |
Description |
backupManagementType
|
string:
AzureSql
|
This property will be used as the discriminator for deciding the specific types in the polymorphic chain of types.
|
protectedItemsCount
|
integer
|
Number of items associated with this policy.
|
resourceGuardOperationRequests
|
string[]
|
ResourceGuard Operation Requests
|
retentionPolicy
|
RetentionPolicy:
|
Retention policy details.
|
AzureVmWorkloadProtectionPolicy
Azure VM (Mercury) workload-specific backup policy.
Name |
Type |
Description |
backupManagementType
|
string:
AzureWorkload
|
This property will be used as the discriminator for deciding the specific types in the polymorphic chain of types.
|
makePolicyConsistent
|
boolean
|
Fix the policy inconsistency
|
protectedItemsCount
|
integer
|
Number of items associated with this policy.
|
resourceGuardOperationRequests
|
string[]
|
ResourceGuard Operation Requests
|
settings
|
Settings
|
Common settings for the backup management
|
subProtectionPolicy
|
SubProtectionPolicy[]
|
List of sub-protection policies which includes schedule and retention
|
workLoadType
|
WorkloadType
|
Type of workload for the backup management
|
CloudError
An error response from the Container Instance service.
CloudErrorBody
An error response from the Container Instance service.
Name |
Type |
Description |
additionalInfo
|
ErrorAdditionalInfo[]
|
The error additional info.
|
code
|
string
|
An identifier for the error. Codes are invariant and are intended to be consumed programmatically.
|
details
|
CloudErrorBody[]
|
A list of additional details about the error.
|
message
|
string
|
A message describing the error, intended to be suitable for display in a user interface.
|
target
|
string
|
The target of the particular error. For example, the name of the property in error.
|
Daily retention format.
Name |
Type |
Description |
daysOfTheMonth
|
Day[]
|
List of days of the month.
|
DailyRetentionSchedule
Daily retention schedule.
Name |
Type |
Description |
retentionDuration
|
RetentionDuration
|
Retention duration of retention Policy.
|
retentionTimes
|
string[]
|
Retention times of retention policy.
|
DailySchedule
Name |
Type |
Description |
scheduleRunTimes
|
string[]
|
List of times of day this schedule has to be run.
|
Day
Day of the week.
Name |
Type |
Description |
date
|
integer
|
Date of the month
|
isLast
|
boolean
|
Whether Date is last date of month
|
DayOfWeek
Name |
Type |
Description |
Friday
|
string
|
|
Monday
|
string
|
|
Saturday
|
string
|
|
Sunday
|
string
|
|
Thursday
|
string
|
|
Tuesday
|
string
|
|
Wednesday
|
string
|
|
ErrorAdditionalInfo
The resource management error additional info.
Name |
Type |
Description |
info
|
object
|
The additional info.
|
type
|
string
|
The additional info type.
|
GenericProtectionPolicy
Azure VM (Mercury) workload-specific backup policy.
Name |
Type |
Description |
backupManagementType
|
string:
GenericProtectionPolicy
|
This property will be used as the discriminator for deciding the specific types in the polymorphic chain of types.
|
fabricName
|
string
|
Name of this policy's fabric.
|
protectedItemsCount
|
integer
|
Number of items associated with this policy.
|
resourceGuardOperationRequests
|
string[]
|
ResourceGuard Operation Requests
|
subProtectionPolicy
|
SubProtectionPolicy[]
|
List of sub-protection policies which includes schedule and retention
|
timeZone
|
string
|
TimeZone optional input as string. For example: TimeZone = "Pacific Standard Time".
|
HourlySchedule
Name |
Type |
Description |
interval
|
integer
|
Interval at which backup needs to be triggered. For hourly the value
can be 4/6/8/12
|
scheduleWindowDuration
|
integer
|
To specify duration of the backup window
|
scheduleWindowStartTime
|
string
|
To specify start time of the backup window
|
IAASVMPolicyType
Name |
Type |
Description |
Invalid
|
string
|
|
V1
|
string
|
|
V2
|
string
|
|
IaasVMSnapshotConsistencyType
Name |
Type |
Description |
OnlyCrashConsistent
|
string
|
|
InstantRPAdditionalDetails
Name |
Type |
Description |
azureBackupRGNamePrefix
|
string
|
|
azureBackupRGNameSuffix
|
string
|
|
LogSchedulePolicy
Log policy schedule.
Name |
Type |
Description |
scheduleFrequencyInMins
|
integer
|
Frequency of the log schedule operation of this policy in minutes.
|
schedulePolicyType
|
string:
LogSchedulePolicy
|
This property will be used as the discriminator for deciding the specific types in the polymorphic chain of types.
|
LongTermRetentionPolicy
Long term retention policy.
LongTermSchedulePolicy
Long term policy schedule.
Name |
Type |
Description |
schedulePolicyType
|
string:
LongTermSchedulePolicy
|
This property will be used as the discriminator for deciding the specific types in the polymorphic chain of types.
|
MabProtectionPolicy
Mab container-specific backup policy.
Name |
Type |
Description |
backupManagementType
|
string:
MAB
|
This property will be used as the discriminator for deciding the specific types in the polymorphic chain of types.
|
protectedItemsCount
|
integer
|
Number of items associated with this policy.
|
resourceGuardOperationRequests
|
string[]
|
ResourceGuard Operation Requests
|
retentionPolicy
|
RetentionPolicy:
|
Retention policy details.
|
schedulePolicy
|
SchedulePolicy:
|
Backup schedule of backup policy.
|
MonthlyRetentionSchedule
Monthly retention schedule.
Name |
Type |
Description |
retentionDuration
|
RetentionDuration
|
Retention duration of retention Policy.
|
retentionScheduleDaily
|
DailyRetentionFormat
|
Daily retention format for monthly retention policy.
|
retentionScheduleFormatType
|
RetentionScheduleFormat
|
Retention schedule format type for monthly retention policy.
|
retentionScheduleWeekly
|
WeeklyRetentionFormat
|
Weekly retention format for monthly retention policy.
|
retentionTimes
|
string[]
|
Retention times of retention policy.
|
MonthOfYear
List of months of year of yearly retention policy.
Name |
Type |
Description |
April
|
string
|
|
August
|
string
|
|
December
|
string
|
|
February
|
string
|
|
Invalid
|
string
|
|
January
|
string
|
|
July
|
string
|
|
June
|
string
|
|
March
|
string
|
|
May
|
string
|
|
November
|
string
|
|
October
|
string
|
|
September
|
string
|
|
PolicyType
Type of backup policy type
Name |
Type |
Description |
CopyOnlyFull
|
string
|
|
Differential
|
string
|
|
Full
|
string
|
|
Incremental
|
string
|
|
Invalid
|
string
|
|
Log
|
string
|
|
SnapshotCopyOnlyFull
|
string
|
|
SnapshotFull
|
string
|
|
ProtectionPolicyResource
Base class for backup policy. Workload-specific backup policies are derived from this class.
Name |
Type |
Description |
eTag
|
string
|
Optional ETag.
|
id
|
string
|
Resource Id represents the complete path to the resource.
|
location
|
string
|
Resource location.
|
name
|
string
|
Resource name associated with the resource.
|
properties
|
ProtectionPolicy:
|
ProtectionPolicyResource properties
|
tags
|
object
|
Resource tags.
|
type
|
string
|
Resource type represents the complete path of the form Namespace/ResourceType/ResourceType/...
|
RetentionDuration
Retention duration.
Name |
Type |
Description |
count
|
integer
|
Count of duration types. Retention duration is obtained by the counting the duration type Count times.
For example, when Count = 3 and DurationType = Weeks, retention duration will be three weeks.
|
durationType
|
RetentionDurationType
|
Retention duration type of retention policy.
|
RetentionDurationType
Retention duration type: days/weeks/months/years
Used only if TieringMode is set to TierAfter
Name |
Type |
Description |
Days
|
string
|
|
Invalid
|
string
|
|
Months
|
string
|
|
Weeks
|
string
|
|
Years
|
string
|
|
Retention schedule format type for monthly retention policy.
Name |
Type |
Description |
Daily
|
string
|
|
Invalid
|
string
|
|
Weekly
|
string
|
|
ScheduleRunType
Frequency of the schedule operation of this policy.
Name |
Type |
Description |
Daily
|
string
|
|
Hourly
|
string
|
|
Invalid
|
string
|
|
Weekly
|
string
|
|
Settings
Common settings field for backup management
Name |
Type |
Description |
isCompression
|
boolean
|
Workload compression flag. This has been added so that 'isSqlCompression'
will be deprecated once clients upgrade to consider this flag.
|
issqlcompression
|
boolean
|
SQL compression flag
|
timeZone
|
string
|
TimeZone optional input as string. For example: TimeZone = "Pacific Standard Time".
|
SimpleRetentionPolicy
Simple policy retention.
Name |
Type |
Description |
retentionDuration
|
RetentionDuration
|
Retention duration of the protection policy.
|
retentionPolicyType
|
string:
SimpleRetentionPolicy
|
This property will be used as the discriminator for deciding the specific types in the polymorphic chain of types.
|
SimpleSchedulePolicy
Simple policy schedule.
Name |
Type |
Description |
hourlySchedule
|
HourlySchedule
|
Hourly Schedule of this Policy
|
schedulePolicyType
|
string:
SimpleSchedulePolicy
|
This property will be used as the discriminator for deciding the specific types in the polymorphic chain of types.
|
scheduleRunDays
|
DayOfWeek[]
|
List of days of week this schedule has to be run.
|
scheduleRunFrequency
|
ScheduleRunType
|
Frequency of the schedule operation of this policy.
|
scheduleRunTimes
|
string[]
|
List of times of day this schedule has to be run.
|
scheduleWeeklyFrequency
|
integer
|
At every number weeks this schedule has to be run.
|
SimpleSchedulePolicyV2
The V2 policy schedule for IaaS that supports hourly backups.
Name |
Type |
Description |
dailySchedule
|
DailySchedule
|
Daily schedule of this policy
|
hourlySchedule
|
HourlySchedule
|
hourly schedule of this policy
|
schedulePolicyType
|
string:
SimpleSchedulePolicyV2
|
This property will be used as the discriminator for deciding the specific types in the polymorphic chain of types.
|
scheduleRunFrequency
|
ScheduleRunType
|
Frequency of the schedule operation of this policy.
|
weeklySchedule
|
WeeklySchedule
|
Weekly schedule of this policy
|
SnapshotBackupAdditionalDetails
Snapshot Backup related fields for WorkloadType SaPHanaSystem
Name |
Type |
Description |
instantRPDetails
|
string
|
|
instantRpRetentionRangeInDays
|
integer
|
|
userAssignedManagedIdentityDetails
|
UserAssignedManagedIdentityDetails
|
User assigned managed identity details
|
SubProtectionPolicy
Sub-protection policy which includes schedule and retention
Name |
Type |
Description |
policyType
|
PolicyType
|
Type of backup policy type
|
retentionPolicy
|
RetentionPolicy:
|
Retention policy with the details on backup copy retention ranges.
|
schedulePolicy
|
SchedulePolicy:
|
Backup schedule specified as part of backup policy.
|
snapshotBackupAdditionalDetails
|
SnapshotBackupAdditionalDetails
|
Snapshot Backup related fields for WorkloadType SaPHanaSystem
|
tieringPolicy
|
<string,
TieringPolicy>
|
Tiering policy to automatically move RPs to another tier.
Key is Target Tier, defined in RecoveryPointTierType enum.
Tiering policy specifies the criteria to move RP to the target tier.
|
TieringMode
Tiering Mode to control automatic tiering of recovery points. Supported values are:
- TierRecommended: Tier all recovery points recommended to be tiered
- TierAfter: Tier all recovery points after a fixed period, as specified in duration + durationType below.
- DoNotTier: Do not tier any recovery points
Name |
Type |
Description |
DoNotTier
|
string
|
|
Invalid
|
string
|
|
TierAfter
|
string
|
|
TierRecommended
|
string
|
|
TieringPolicy
Tiering Policy for a target tier.
If the policy is not specified for a given target tier, service retains the existing configured tiering policy for that tier
Name |
Type |
Description |
duration
|
integer
|
Number of days/weeks/months/years to retain backups in current tier before tiering.
Used only if TieringMode is set to TierAfter
|
durationType
|
RetentionDurationType
|
Retention duration type: days/weeks/months/years
Used only if TieringMode is set to TierAfter
|
tieringMode
|
TieringMode
|
Tiering Mode to control automatic tiering of recovery points. Supported values are:
- TierRecommended: Tier all recovery points recommended to be tiered
- TierAfter: Tier all recovery points after a fixed period, as specified in duration + durationType below.
- DoNotTier: Do not tier any recovery points
|
UserAssignedIdentityProperties
User assigned managed identity properties
Name |
Type |
Description |
clientId
|
string
|
The client ID of the assigned identity.
|
principalId
|
string
|
The principal ID of the assigned identity.
|
UserAssignedManagedIdentityDetails
User assigned managed identity details
Name |
Type |
Description |
identityArmId
|
string
|
The ARM id of the assigned identity.
|
identityName
|
string
|
The name of the assigned identity.
|
userAssignedIdentityProperties
|
UserAssignedIdentityProperties
|
User assigned managed identity properties
|
VaultRetentionPolicy
Vault retention policy for AzureFileShare
Name |
Type |
Description |
snapshotRetentionInDays
|
integer
|
|
vaultRetention
|
RetentionPolicy:
|
Base class for retention policy.
|
Weekly retention format.
Name |
Type |
Description |
daysOfTheWeek
|
DayOfWeek[]
|
List of days of the week.
|
weeksOfTheMonth
|
WeekOfMonth[]
|
List of weeks of month.
|
WeeklyRetentionSchedule
Weekly retention schedule.
Name |
Type |
Description |
daysOfTheWeek
|
DayOfWeek[]
|
List of days of week for weekly retention policy.
|
retentionDuration
|
RetentionDuration
|
Retention duration of retention Policy.
|
retentionTimes
|
string[]
|
Retention times of retention policy.
|
WeeklySchedule
Name |
Type |
Description |
scheduleRunDays
|
DayOfWeek[]
|
|
scheduleRunTimes
|
string[]
|
List of times of day this schedule has to be run.
|
WeekOfMonth
List of weeks of month.
Name |
Type |
Description |
First
|
string
|
|
Fourth
|
string
|
|
Invalid
|
string
|
|
Last
|
string
|
|
Second
|
string
|
|
Third
|
string
|
|
WorkloadType
Type of workload for the backup management
Name |
Type |
Description |
AzureFileShare
|
string
|
|
AzureSqlDb
|
string
|
|
Client
|
string
|
|
Exchange
|
string
|
|
FileFolder
|
string
|
|
GenericDataSource
|
string
|
|
Invalid
|
string
|
|
SAPAseDatabase
|
string
|
|
SAPHanaDBInstance
|
string
|
|
SAPHanaDatabase
|
string
|
|
SQLDB
|
string
|
|
SQLDataBase
|
string
|
|
Sharepoint
|
string
|
|
SystemState
|
string
|
|
VM
|
string
|
|
VMwareVM
|
string
|
|
YearlyRetentionSchedule
Yearly retention schedule.
Name |
Type |
Description |
monthsOfYear
|
MonthOfYear[]
|
List of months of year of yearly retention policy.
|
retentionDuration
|
RetentionDuration
|
Retention duration of retention Policy.
|
retentionScheduleDaily
|
DailyRetentionFormat
|
Daily retention format for yearly retention policy.
|
retentionScheduleFormatType
|
RetentionScheduleFormat
|
Retention schedule format for yearly retention policy.
|
retentionScheduleWeekly
|
WeeklyRetentionFormat
|
Weekly retention format for yearly retention policy.
|
retentionTimes
|
string[]
|
Retention times of retention policy.
|