Tworzy lub modyfikuje zasady tworzenia kopii zapasowych. To jest operacja asynchroniczna. Stan operacji można pobrać przy użyciu interfejsu API GetPolicyOperationResult.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}?api-version=2023-02-01
Parametry identyfikatora URI
Nazwa |
W |
Wymagane |
Typ |
Opis |
policyName
|
path |
True
|
string
|
Zasady tworzenia kopii zapasowych, które mają zostać utworzone.
|
resourceGroupName
|
path |
True
|
string
|
Nazwa grupy zasobów, w której znajduje się magazyn usługi Recovery Services.
|
subscriptionId
|
path |
True
|
string
|
Identyfikator subskrypcji.
|
vaultName
|
path |
True
|
string
|
Nazwa magazynu usługi Recovery Services.
|
api-version
|
query |
True
|
string
|
Wersja interfejsu API klienta.
|
Treść żądania
Nazwa |
Typ |
Opis |
eTag
|
string
|
Opcjonalny element ETag.
|
location
|
string
|
Lokalizacja zasobu.
|
properties
|
ProtectionPolicy:
|
ProtectionPolicyResource właściwości
|
tags
|
object
|
Tagi zasobów.
|
Odpowiedzi
Nazwa |
Typ |
Opis |
200 OK
|
ProtectionPolicyResource
|
OK
|
202 Accepted
|
|
Zaakceptowano
|
Other Status Codes
|
CloudError
|
Odpowiedź na błąd opisująca, dlaczego operacja nie powiodła się.
|
Zabezpieczenia
azure_auth
Przepływ OAuth2 usługi Azure Active Directory
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
Nazwa |
Opis |
user_impersonation
|
personifikuj konto użytkownika.
|
Przykłady
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=2023-02-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/2023-02-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 azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup 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/2023-02-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/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/a498cae6d1a93f4c33073f0747b93b22815c09b7/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-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),
},
}, 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:00Z"); 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:00Z"); 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:00Z"); 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:00Z"); 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:00Z"); 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/2023-02-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
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.RecoveryServicesBackup;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Daily.json
// this example is just showing the usage of "ProtectionPolicies_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this BackupProtectionPolicyResource
string vaultName = "swaggertestvault";
BackupProtectionPolicyCollection collection = resourceGroupResource.GetBackupProtectionPolicies(vaultName);
// invoke the operation
string policyName = "dailyPolicy2";
BackupProtectionPolicyData data = new BackupProtectionPolicyData(new AzureLocation("placeholder"))
{
Properties = new FileShareProtectionPolicy()
{
WorkLoadType = BackupWorkloadType.AzureFileShare,
SchedulePolicy = new SimpleSchedulePolicy()
{
ScheduleRunFrequency = ScheduleRunType.Daily,
ScheduleRunTimes =
{
DateTimeOffset.Parse("2021-09-29T08:00:00.000Z")
},
},
RetentionPolicy = new LongTermRetentionPolicy()
{
DailySchedule = new DailyRetentionSchedule()
{
RetentionTimes =
{
DateTimeOffset.Parse("2021-09-29T08:00:00.000Z")
},
RetentionDuration = new RetentionDuration()
{
Count = 5,
DurationType = RetentionDurationType.Days,
},
},
WeeklySchedule = new WeeklyRetentionSchedule()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
RetentionTimes =
{
DateTimeOffset.Parse("2021-09-29T08:00:00.000Z")
},
RetentionDuration = new RetentionDuration()
{
Count = 12,
DurationType = RetentionDurationType.Weeks,
},
},
MonthlySchedule = new MonthlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.First
},
},
RetentionTimes =
{
DateTimeOffset.Parse("2021-09-29T08:00:00.000Z")
},
RetentionDuration = new RetentionDuration()
{
Count = 60,
DurationType = RetentionDurationType.Months,
},
},
YearlySchedule = new YearlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
MonthsOfYear =
{
BackupMonthOfYear.January
},
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.First
},
},
RetentionTimes =
{
DateTimeOffset.Parse("2021-09-29T08:00:00.000Z")
},
RetentionDuration = new RetentionDuration()
{
Count = 10,
DurationType = RetentionDurationType.Years,
},
},
},
TimeZone = "UTC",
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyName, data);
BackupProtectionPolicyResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
BackupProtectionPolicyData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
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=2023-02-01
{
"properties": {
"backupManagementType": "AzureIaasVM",
"timeZone": "India Standard Time",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"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.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/2023-02-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))
.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 azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup 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",
},
"timeZone": "India Standard Time",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-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/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/a498cae6d1a93f4c33073f0747b93b22815c09b7/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-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+00:00"); 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+00:00"); 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+00:00"); 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+00:00"); 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:00Z"); return t }())},
},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
},
TimeZone: to.Ptr("India Standard Time"),
},
}, 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+00:00"); 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+00:00"); 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+00:00"); 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+00:00"); 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:00Z"); return t}())},
// },
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
// },
// 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/2023-02-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",
},
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
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.RecoveryServicesBackup;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-01/examples/AzureIaasVm/V2Policy/IaaS_v2_daily.json
// this example is just showing the usage of "ProtectionPolicies_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this BackupProtectionPolicyResource
string vaultName = "NetSDKTestRsVault";
BackupProtectionPolicyCollection collection = resourceGroupResource.GetBackupProtectionPolicies(vaultName);
// invoke the operation
string policyName = "v2-daily-sample";
BackupProtectionPolicyData data = new BackupProtectionPolicyData(new AzureLocation("placeholder"))
{
Properties = new IaasVmProtectionPolicy()
{
SchedulePolicy = new SimpleSchedulePolicyV2()
{
ScheduleRunFrequency = ScheduleRunType.Daily,
ScheduleRunTimes =
{
DateTimeOffset.Parse("2018-01-24T10:00:00Z")
},
},
RetentionPolicy = new LongTermRetentionPolicy()
{
DailySchedule = new DailyRetentionSchedule()
{
RetentionTimes =
{
DateTimeOffset.Parse("2021-12-17T08:00:00+00:00")
},
RetentionDuration = new RetentionDuration()
{
Count = 180,
DurationType = RetentionDurationType.Days,
},
},
WeeklySchedule = new WeeklyRetentionSchedule()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
RetentionTimes =
{
DateTimeOffset.Parse("2021-12-17T08:00:00+00:00")
},
RetentionDuration = new RetentionDuration()
{
Count = 12,
DurationType = RetentionDurationType.Weeks,
},
},
MonthlySchedule = new MonthlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.First
},
},
RetentionTimes =
{
DateTimeOffset.Parse("2021-12-17T08:00:00+00:00")
},
RetentionDuration = new RetentionDuration()
{
Count = 60,
DurationType = RetentionDurationType.Months,
},
},
YearlySchedule = new YearlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
MonthsOfYear =
{
BackupMonthOfYear.January
},
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.First
},
},
RetentionTimes =
{
DateTimeOffset.Parse("2021-12-17T08:00:00+00:00")
},
RetentionDuration = new RetentionDuration()
{
Count = 10,
DurationType = RetentionDurationType.Years,
},
},
},
InstantRPRetentionRangeInDays = 30,
TimeZone = "India Standard Time",
PolicyType = IaasVmPolicyType.V2,
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyName, data);
BackupProtectionPolicyResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
BackupProtectionPolicyData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
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",
"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=2023-02-01
{
"properties": {
"backupManagementType": "AzureIaasVM",
"timeZone": "India Standard Time",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"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.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/2023-02-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))
.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 azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup 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",
},
"timeZone": "India Standard Time",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-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/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/a498cae6d1a93f4c33073f0747b93b22815c09b7/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-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+00:00"); 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+00:00"); 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+00:00"); 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+00:00"); 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:00Z"); return t }()),
},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeHourly),
},
TimeZone: to.Ptr("India Standard Time"),
},
}, 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+00:00"); 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+00:00"); 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+00:00"); 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+00:00"); 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:00Z"); return t}()),
// },
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeHourly),
// },
// 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/2023-02-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",
},
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
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.RecoveryServicesBackup;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-01/examples/AzureIaasVm/V2Policy/IaaS_v2_hourly.json
// this example is just showing the usage of "ProtectionPolicies_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this BackupProtectionPolicyResource
string vaultName = "NetSDKTestRsVault";
BackupProtectionPolicyCollection collection = resourceGroupResource.GetBackupProtectionPolicies(vaultName);
// invoke the operation
string policyName = "v2-daily-sample";
BackupProtectionPolicyData data = new BackupProtectionPolicyData(new AzureLocation("placeholder"))
{
Properties = new IaasVmProtectionPolicy()
{
SchedulePolicy = new SimpleSchedulePolicyV2()
{
ScheduleRunFrequency = ScheduleRunType.Hourly,
HourlySchedule = new BackupHourlySchedule()
{
Interval = 4,
ScheduleWindowStartOn = DateTimeOffset.Parse("2021-12-17T08:00:00Z"),
ScheduleWindowDuration = 16,
},
},
RetentionPolicy = new LongTermRetentionPolicy()
{
DailySchedule = new DailyRetentionSchedule()
{
RetentionTimes =
{
DateTimeOffset.Parse("2021-12-17T08:00:00+00:00")
},
RetentionDuration = new RetentionDuration()
{
Count = 180,
DurationType = RetentionDurationType.Days,
},
},
WeeklySchedule = new WeeklyRetentionSchedule()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
RetentionTimes =
{
DateTimeOffset.Parse("2021-12-17T08:00:00+00:00")
},
RetentionDuration = new RetentionDuration()
{
Count = 12,
DurationType = RetentionDurationType.Weeks,
},
},
MonthlySchedule = new MonthlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.First
},
},
RetentionTimes =
{
DateTimeOffset.Parse("2021-12-17T08:00:00+00:00")
},
RetentionDuration = new RetentionDuration()
{
Count = 60,
DurationType = RetentionDurationType.Months,
},
},
YearlySchedule = new YearlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
MonthsOfYear =
{
BackupMonthOfYear.January
},
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.First
},
},
RetentionTimes =
{
DateTimeOffset.Parse("2021-12-17T08:00:00+00:00")
},
RetentionDuration = new RetentionDuration()
{
Count = 10,
DurationType = RetentionDurationType.Years,
},
},
},
InstantRPRetentionRangeInDays = 30,
TimeZone = "India Standard Time",
PolicyType = IaasVmPolicyType.V2,
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyName, data);
BackupProtectionPolicyResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
BackupProtectionPolicyData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
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",
"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=2023-02-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/2023-02-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 azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup 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/2023-02-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/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/a498cae6d1a93f4c33073f0747b93b22815c09b7/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-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:00Z"); 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:00Z"); 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:00Z"); 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:00Z"); return t }())},
},
TimeZone: to.Ptr("Pacific Standard Time"),
},
}, 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:00Z"); 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:00Z"); 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:00Z"); 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:00Z"); 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/2023-02-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
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.RecoveryServicesBackup;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-01/examples/AzureIaasVm/ProtectionPolicies_CreateOrUpdate_Complex.json
// this example is just showing the usage of "ProtectionPolicies_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this BackupProtectionPolicyResource
string vaultName = "NetSDKTestRsVault";
BackupProtectionPolicyCollection collection = resourceGroupResource.GetBackupProtectionPolicies(vaultName);
// invoke the operation
string policyName = "testPolicy1";
BackupProtectionPolicyData data = new BackupProtectionPolicyData(new AzureLocation("placeholder"))
{
Properties = new IaasVmProtectionPolicy()
{
SchedulePolicy = new SimpleSchedulePolicy()
{
ScheduleRunFrequency = ScheduleRunType.Weekly,
ScheduleRunDays =
{
BackupDayOfWeek.Monday,BackupDayOfWeek.Wednesday,BackupDayOfWeek.Thursday
},
ScheduleRunTimes =
{
DateTimeOffset.Parse("2018-01-24T10:00:00Z")
},
},
RetentionPolicy = new LongTermRetentionPolicy()
{
WeeklySchedule = new WeeklyRetentionSchedule()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Monday,BackupDayOfWeek.Wednesday,BackupDayOfWeek.Thursday
},
RetentionTimes =
{
DateTimeOffset.Parse("2018-01-24T10:00:00Z")
},
RetentionDuration = new RetentionDuration()
{
Count = 1,
DurationType = RetentionDurationType.Weeks,
},
},
MonthlySchedule = new MonthlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Wednesday,BackupDayOfWeek.Thursday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.First,BackupWeekOfMonth.Third
},
},
RetentionTimes =
{
DateTimeOffset.Parse("2018-01-24T10:00:00Z")
},
RetentionDuration = new RetentionDuration()
{
Count = 2,
DurationType = RetentionDurationType.Months,
},
},
YearlySchedule = new YearlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
MonthsOfYear =
{
BackupMonthOfYear.February,BackupMonthOfYear.November
},
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Monday,BackupDayOfWeek.Thursday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.Fourth
},
},
RetentionTimes =
{
DateTimeOffset.Parse("2018-01-24T10:00:00Z")
},
RetentionDuration = new RetentionDuration()
{
Count = 4,
DurationType = RetentionDurationType.Years,
},
},
},
TimeZone = "Pacific Standard Time",
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyName, data);
BackupProtectionPolicyResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
BackupProtectionPolicyData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
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=2023-02-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/2023-02-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
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/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/a498cae6d1a93f4c33073f0747b93b22815c09b7/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-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:00Z"); 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:00Z"); 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:00Z"); 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:00Z"); 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:00Z"); 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),
},
}, 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:00Z"); 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:00Z"); 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:00Z"); 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:00Z"); 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:00Z"); 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/2023-02-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
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.RecoveryServicesBackup;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-01/examples/AzureWorkload/ProtectionPolicies_CreateOrUpdate_Complex.json
// this example is just showing the usage of "ProtectionPolicies_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this BackupProtectionPolicyResource
string vaultName = "NetSDKTestRsVault";
BackupProtectionPolicyCollection collection = resourceGroupResource.GetBackupProtectionPolicies(vaultName);
// invoke the operation
string policyName = "testPolicy1";
BackupProtectionPolicyData data = new BackupProtectionPolicyData(new AzureLocation("placeholder"))
{
Properties = new VmWorkloadProtectionPolicy()
{
WorkLoadType = BackupWorkloadType.SqlDatabase,
Settings = new BackupCommonSettings()
{
TimeZone = "Pacific Standard Time",
IsSqlCompression = false,
},
SubProtectionPolicy =
{
new SubProtectionPolicy()
{
PolicyType = SubProtectionPolicyType.Full,
SchedulePolicy = new SimpleSchedulePolicy()
{
ScheduleRunFrequency = ScheduleRunType.Weekly,
ScheduleRunDays =
{
BackupDayOfWeek.Sunday,BackupDayOfWeek.Tuesday
},
ScheduleRunTimes =
{
DateTimeOffset.Parse("2018-01-24T10:00:00Z")
},
},
RetentionPolicy = new LongTermRetentionPolicy()
{
WeeklySchedule = new WeeklyRetentionSchedule()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday,BackupDayOfWeek.Tuesday
},
RetentionTimes =
{
DateTimeOffset.Parse("2018-01-24T10:00:00Z")
},
RetentionDuration = new RetentionDuration()
{
Count = 2,
DurationType = RetentionDurationType.Weeks,
},
},
MonthlySchedule = new MonthlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.Second
},
},
RetentionTimes =
{
DateTimeOffset.Parse("2018-01-24T10:00:00Z")
},
RetentionDuration = new RetentionDuration()
{
Count = 1,
DurationType = RetentionDurationType.Months,
},
},
YearlySchedule = new YearlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
MonthsOfYear =
{
BackupMonthOfYear.January,BackupMonthOfYear.June,BackupMonthOfYear.December
},
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.Last
},
},
RetentionTimes =
{
DateTimeOffset.Parse("2018-01-24T10:00:00Z")
},
RetentionDuration = new RetentionDuration()
{
Count = 1,
DurationType = RetentionDurationType.Years,
},
},
},
},new SubProtectionPolicy()
{
PolicyType = SubProtectionPolicyType.Differential,
SchedulePolicy = new SimpleSchedulePolicy()
{
ScheduleRunFrequency = ScheduleRunType.Weekly,
ScheduleRunDays =
{
BackupDayOfWeek.Friday
},
ScheduleRunTimes =
{
DateTimeOffset.Parse("2018-01-24T10:00:00Z")
},
},
RetentionPolicy = new SimpleRetentionPolicy()
{
RetentionDuration = new RetentionDuration()
{
Count = 8,
DurationType = RetentionDurationType.Days,
},
},
},new SubProtectionPolicy()
{
PolicyType = SubProtectionPolicyType.Log,
SchedulePolicy = new LogSchedulePolicy()
{
ScheduleFrequencyInMins = 60,
},
RetentionPolicy = new SimpleRetentionPolicy()
{
RetentionDuration = new RetentionDuration()
{
Count = 7,
DurationType = RetentionDurationType.Days,
},
},
}
},
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyName, data);
BackupProtectionPolicyResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
BackupProtectionPolicyData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
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=2023-02-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/2023-02-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 azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup 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/2023-02-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/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/a498cae6d1a93f4c33073f0747b93b22815c09b7/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-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),
},
}, 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:00Z"); 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:00Z"); 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:00Z"); 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:00Z"); 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:00Z"); 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/2023-02-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
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.RecoveryServicesBackup;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Hourly.json
// this example is just showing the usage of "ProtectionPolicies_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this BackupProtectionPolicyResource
string vaultName = "swaggertestvault";
BackupProtectionPolicyCollection collection = resourceGroupResource.GetBackupProtectionPolicies(vaultName);
// invoke the operation
string policyName = "newPolicy2";
BackupProtectionPolicyData data = new BackupProtectionPolicyData(new AzureLocation("placeholder"))
{
Properties = new FileShareProtectionPolicy()
{
WorkLoadType = BackupWorkloadType.AzureFileShare,
SchedulePolicy = new SimpleSchedulePolicy()
{
ScheduleRunFrequency = ScheduleRunType.Hourly,
HourlySchedule = new BackupHourlySchedule()
{
Interval = 4,
ScheduleWindowStartOn = DateTimeOffset.Parse("2021-09-29T08:00:00.000Z"),
ScheduleWindowDuration = 12,
},
},
RetentionPolicy = new LongTermRetentionPolicy()
{
DailySchedule = new DailyRetentionSchedule()
{
RetentionTimes =
{
},
RetentionDuration = new RetentionDuration()
{
Count = 5,
DurationType = RetentionDurationType.Days,
},
},
WeeklySchedule = new WeeklyRetentionSchedule()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
RetentionTimes =
{
},
RetentionDuration = new RetentionDuration()
{
Count = 12,
DurationType = RetentionDurationType.Weeks,
},
},
MonthlySchedule = new MonthlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.First
},
},
RetentionTimes =
{
},
RetentionDuration = new RetentionDuration()
{
Count = 60,
DurationType = RetentionDurationType.Months,
},
},
YearlySchedule = new YearlyRetentionSchedule()
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
MonthsOfYear =
{
BackupMonthOfYear.January
},
RetentionScheduleWeekly = new WeeklyRetentionFormat()
{
DaysOfTheWeek =
{
BackupDayOfWeek.Sunday
},
WeeksOfTheMonth =
{
BackupWeekOfMonth.First
},
},
RetentionTimes =
{
},
RetentionDuration = new RetentionDuration()
{
Count = 10,
DurationType = RetentionDurationType.Years,
},
},
},
TimeZone = "UTC",
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyName, data);
BackupProtectionPolicyResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
BackupProtectionPolicyData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
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=2023-02-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/2023-02-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 azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup 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/2023-02-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/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/a498cae6d1a93f4c33073f0747b93b22815c09b7/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-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:00Z"); 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:00Z"); return t }())},
},
TimeZone: to.Ptr("Pacific Standard Time"),
},
}, 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:00Z"); 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:00Z"); 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/2023-02-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
using System;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.RecoveryServicesBackup;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.Resources;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2023-02-01/examples/AzureIaasVm/ProtectionPolicies_CreateOrUpdate_Simple.json
// this example is just showing the usage of "ProtectionPolicies_CreateOrUpdate" operation, for the dependent resources, they will have to be created separately.
// get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line
TokenCredential cred = new DefaultAzureCredential();
// authenticate your client
ArmClient client = new ArmClient(cred);
// this example assumes you already have this ResourceGroupResource created on azure
// for more information of creating ResourceGroupResource, please refer to the document of ResourceGroupResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
ResourceIdentifier resourceGroupResourceId = ResourceGroupResource.CreateResourceIdentifier(subscriptionId, resourceGroupName);
ResourceGroupResource resourceGroupResource = client.GetResourceGroupResource(resourceGroupResourceId);
// get the collection of this BackupProtectionPolicyResource
string vaultName = "NetSDKTestRsVault";
BackupProtectionPolicyCollection collection = resourceGroupResource.GetBackupProtectionPolicies(vaultName);
// invoke the operation
string policyName = "testPolicy1";
BackupProtectionPolicyData data = new BackupProtectionPolicyData(new AzureLocation("placeholder"))
{
Properties = new IaasVmProtectionPolicy()
{
SchedulePolicy = new SimpleSchedulePolicy()
{
ScheduleRunFrequency = ScheduleRunType.Daily,
ScheduleRunTimes =
{
DateTimeOffset.Parse("2018-01-24T02:00:00Z")
},
},
RetentionPolicy = new LongTermRetentionPolicy()
{
DailySchedule = new DailyRetentionSchedule()
{
RetentionTimes =
{
DateTimeOffset.Parse("2018-01-24T02:00:00Z")
},
RetentionDuration = new RetentionDuration()
{
Count = 1,
DurationType = RetentionDurationType.Days,
},
},
},
TimeZone = "Pacific Standard Time",
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, policyName, data);
BackupProtectionPolicyResource result = lro.Value;
// the variable result is a resource, you could call other operations on this instance as well
// but just for demo, we get its data from this resource instance
BackupProtectionPolicyData resourceData = result.Data;
// for demo we just print out the id
Console.WriteLine($"Succeeded on id: {resourceData.Id}");
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
Definicje
AzureFileShareProtectionPolicy
Zasady tworzenia kopii zapasowych usługi AzureStorage.
Nazwa |
Typ |
Opis |
backupManagementType
|
string:
AzureStorage
|
Ta właściwość będzie używana jako dyskryminująca do decydowania o określonych typach w łańcuchu polimorficznych typów.
|
protectedItemsCount
|
integer
|
Liczba elementów skojarzonych z tą zasadą.
|
resourceGuardOperationRequests
|
string[]
|
Żądania operacji ResourceGuard
|
retentionPolicy
|
RetentionPolicy:
|
Zasady przechowywania ze szczegółami dotyczącymi zakresów przechowywania kopii zapasowych.
|
schedulePolicy
|
SchedulePolicy:
|
Harmonogram tworzenia kopii zapasowych określony w ramach zasad tworzenia kopii zapasowych.
|
timeZone
|
string
|
Opcjonalne dane wejściowe strefy czasowej jako ciąg. Na przykład: TimeZone = "Pacific Standard Time".
|
workLoadType
|
WorkloadType
|
Typ obciążenia dla zarządzania kopiami zapasowymi
|
AzureIaaSVMProtectionPolicy
Zasady tworzenia kopii zapasowych specyficzne dla obciążenia maszyny wirtualnej IaaS.
Nazwa |
Typ |
Opis |
backupManagementType
|
string:
AzureIaasVM
|
Ta właściwość będzie używana jako dyskryminująca do decydowania o określonych typach w łańcuchu polimorficznych typów.
|
instantRPDetails
|
InstantRPAdditionalDetails
|
|
instantRpRetentionRangeInDays
|
integer
|
Zakres zasad przechowywania natychmiastowej jednostki rp w dniach
|
policyType
|
IAASVMPolicyType
|
|
protectedItemsCount
|
integer
|
Liczba elementów skojarzonych z tą zasadą.
|
resourceGuardOperationRequests
|
string[]
|
Żądania operacji ResourceGuard
|
retentionPolicy
|
RetentionPolicy:
|
Zasady przechowywania ze szczegółami dotyczącymi zakresów przechowywania kopii zapasowych.
|
schedulePolicy
|
SchedulePolicy:
|
Harmonogram tworzenia kopii zapasowych określony w ramach zasad tworzenia kopii zapasowych.
|
tieringPolicy
|
<string,
TieringPolicy>
|
Zasady obsługi warstw, aby automatycznie przenosić adresy IP do innej warstwy Klucz jest warstwą docelową zdefiniowaną w wyliczenie RecoveryPointTierType.
Zasady obsługi warstw określa kryteria przenoszenia dostawcy zasobów do warstwy docelowej.
|
timeZone
|
string
|
Opcjonalne dane wejściowe strefy czasowej jako ciąg. Na przykład: TimeZone = "Pacific Standard Time".
|
AzureSqlProtectionPolicy
Azure SQL zasad tworzenia kopii zapasowych specyficznych dla obciążenia.
Nazwa |
Typ |
Opis |
backupManagementType
|
string:
AzureSql
|
Ta właściwość będzie używana jako dyskryminująca do decydowania o określonych typach w łańcuchu polimorficznych typów.
|
protectedItemsCount
|
integer
|
Liczba elementów skojarzonych z tą zasadą.
|
resourceGuardOperationRequests
|
string[]
|
Żądania operacji ResourceGuard
|
retentionPolicy
|
RetentionPolicy:
|
Szczegóły zasad przechowywania.
|
AzureVmWorkloadProtectionPolicy
Zasady tworzenia kopii zapasowych specyficzne dla obciążenia maszyny wirtualnej platformy Azure (Mercury).
Nazwa |
Typ |
Opis |
backupManagementType
|
string:
AzureWorkload
|
Ta właściwość będzie używana jako dyskryminująca do decydowania o określonych typach w łańcuchu polimorficznych typów.
|
makePolicyConsistent
|
boolean
|
Naprawianie niespójności zasad
|
protectedItemsCount
|
integer
|
Liczba elementów skojarzonych z tą zasadą.
|
resourceGuardOperationRequests
|
string[]
|
Żądania operacji ResourceGuard
|
settings
|
Settings
|
Typowe ustawienia zarządzania kopiami zapasowymi
|
subProtectionPolicy
|
SubProtectionPolicy[]
|
Lista zasad ochrony podrzędnej, które obejmują harmonogram i przechowywanie
|
workLoadType
|
WorkloadType
|
Typ obciążenia dla zarządzania kopiami zapasowymi
|
CloudError
Odpowiedź o błędzie z usługi Container Instance.
CloudErrorBody
Odpowiedź o błędzie z usługi Container Instance.
Nazwa |
Typ |
Opis |
additionalInfo
|
ErrorAdditionalInfo[]
|
Dodatkowe informacje o błędzie.
|
code
|
string
|
Identyfikator błędu. Kody są niezmienne i mają być używane programowo.
|
details
|
CloudErrorBody[]
|
Lista dodatkowych szczegółów dotyczących błędu.
|
message
|
string
|
Komunikat opisujący błąd, który ma być odpowiedni do wyświetlania w interfejsie użytkownika.
|
target
|
string
|
Element docelowy określonego błędu. Na przykład nazwa właściwości w błędzie.
|
Format przechowywania dziennego.
Nazwa |
Typ |
Opis |
daysOfTheMonth
|
Day[]
|
Lista dni miesiąca.
|
DailyRetentionSchedule
Harmonogram przechowywania dziennego.
Nazwa |
Typ |
Opis |
retentionDuration
|
RetentionDuration
|
Czas przechowywania zasad przechowywania.
|
retentionTimes
|
string[]
|
Czas przechowywania zasad przechowywania.
|
DailySchedule
Nazwa |
Typ |
Opis |
scheduleRunTimes
|
string[]
|
Lista godzin dnia, które należy uruchomić w tym harmonogramie.
|
Day
Dzień tygodnia.
Nazwa |
Typ |
Opis |
date
|
integer
|
Data miesiąca
|
isLast
|
boolean
|
Czy data jest datą ostatniego miesiąca
|
DayOfWeek
Nazwa |
Typ |
Opis |
Friday
|
string
|
|
Monday
|
string
|
|
Saturday
|
string
|
|
Sunday
|
string
|
|
Thursday
|
string
|
|
Tuesday
|
string
|
|
Wednesday
|
string
|
|
ErrorAdditionalInfo
Dodatkowe informacje o błędzie zarządzania zasobami.
Nazwa |
Typ |
Opis |
info
|
object
|
Dodatkowe informacje.
|
type
|
string
|
Dodatkowy typ informacji.
|
GenericProtectionPolicy
Zasady tworzenia kopii zapasowych specyficzne dla obciążenia maszyny wirtualnej platformy Azure (Mercury).
Nazwa |
Typ |
Opis |
backupManagementType
|
string:
GenericProtectionPolicy
|
Ta właściwość będzie używana jako dyskryminująca do decydowania o określonych typach w łańcuchu polimorficznych typów.
|
fabricName
|
string
|
Nazwa sieci szkieletowej tych zasad.
|
protectedItemsCount
|
integer
|
Liczba elementów skojarzonych z tą zasadą.
|
resourceGuardOperationRequests
|
string[]
|
Żądania operacji ResourceGuard
|
subProtectionPolicy
|
SubProtectionPolicy[]
|
Lista zasad ochrony podrzędnej, które obejmują harmonogram i przechowywanie
|
timeZone
|
string
|
Opcjonalne dane wejściowe strefy czasowej jako ciąg. Na przykład: TimeZone = "Pacific Standard Time".
|
HourlySchedule
Nazwa |
Typ |
Opis |
interval
|
integer
|
Interwał wyzwalania kopii zapasowej. Dla wartości godzinowej wartość może być 4/6/8/12
|
scheduleWindowDuration
|
integer
|
Aby określić czas trwania okna tworzenia kopii zapasowej
|
scheduleWindowStartTime
|
string
|
Aby określić godzinę rozpoczęcia okna tworzenia kopii zapasowej
|
IAASVMPolicyType
Nazwa |
Typ |
Opis |
Invalid
|
string
|
|
V1
|
string
|
|
V2
|
string
|
|
InstantRPAdditionalDetails
Nazwa |
Typ |
Opis |
azureBackupRGNamePrefix
|
string
|
|
azureBackupRGNameSuffix
|
string
|
|
LogSchedulePolicy
Harmonogram zasad dziennika.
Nazwa |
Typ |
Opis |
scheduleFrequencyInMins
|
integer
|
Częstotliwość operacji harmonogramu dziennika tych zasad w minutach.
|
schedulePolicyType
|
string:
LogSchedulePolicy
|
Ta właściwość będzie używana jako dyskryminująca do decydowania o określonych typach w łańcuchu polimorficznych typów.
|
LongTermRetentionPolicy
Zasady długoterminowego przechowywania.
LongTermSchedulePolicy
Harmonogram zasad długoterminowych.
Nazwa |
Typ |
Opis |
schedulePolicyType
|
string:
LongTermSchedulePolicy
|
Ta właściwość będzie używana jako dyskryminująca do decydowania o określonych typach w łańcuchu polimorficznych typów.
|
MabProtectionPolicy
Zasady tworzenia kopii zapasowych specyficzne dla kontenera usługi Mab.
Nazwa |
Typ |
Opis |
backupManagementType
|
string:
MAB
|
Ta właściwość będzie używana jako dyskryminująca do decydowania o określonych typach w łańcuchu polimorficznych typów.
|
protectedItemsCount
|
integer
|
Liczba elementów skojarzonych z tą zasadą.
|
resourceGuardOperationRequests
|
string[]
|
Żądania operacji ResourceGuard
|
retentionPolicy
|
RetentionPolicy:
|
Szczegóły zasad przechowywania.
|
schedulePolicy
|
SchedulePolicy:
|
Harmonogram tworzenia kopii zapasowych zasad tworzenia kopii zapasowych.
|
MonthlyRetentionSchedule
Harmonogram przechowywania miesięcznego.
Nazwa |
Typ |
Opis |
retentionDuration
|
RetentionDuration
|
Czas przechowywania zasad przechowywania.
|
retentionScheduleDaily
|
DailyRetentionFormat
|
Format przechowywania dziennego dla zasad przechowywania miesięcznego.
|
retentionScheduleFormatType
|
RetentionScheduleFormat
|
Typ formatu harmonogramu przechowywania dla zasad przechowywania miesięcznego.
|
retentionScheduleWeekly
|
WeeklyRetentionFormat
|
Format przechowywania tygodniowego dla zasad przechowywania miesięcznego.
|
retentionTimes
|
string[]
|
Czas przechowywania zasad przechowywania.
|
MonthOfYear
Lista miesięcy roku rocznej zasady przechowywania.
Nazwa |
Typ |
Opis |
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
Typ zasad kopii zapasowej
Nazwa |
Typ |
Opis |
CopyOnlyFull
|
string
|
|
Differential
|
string
|
|
Full
|
string
|
|
Incremental
|
string
|
|
Invalid
|
string
|
|
Log
|
string
|
|
SnapshotCopyOnlyFull
|
string
|
|
SnapshotFull
|
string
|
|
ProtectionPolicyResource
Klasa podstawowa dla zasad kopii zapasowych. Zasady tworzenia kopii zapasowych specyficzne dla obciążenia pochodzą z tej klasy.
Nazwa |
Typ |
Opis |
eTag
|
string
|
Opcjonalny element ETag.
|
id
|
string
|
Identyfikator zasobu reprezentuje pełną ścieżkę do zasobu.
|
location
|
string
|
Lokalizacja zasobu.
|
name
|
string
|
Nazwa zasobu skojarzona z zasobem.
|
properties
|
ProtectionPolicy:
|
ProtectionPolicyResource właściwości
|
tags
|
object
|
Tagi zasobów.
|
type
|
string
|
Typ zasobu reprezentuje pełną ścieżkę formularza Namespace/ResourceType/ResourceType/...
|
RetentionDuration
Czas przechowywania.
Nazwa |
Typ |
Opis |
count
|
integer
|
Liczba typów czasu trwania. Czas trwania przechowywania jest uzyskiwany przez zliczanie typu czasu trwania Liczba razy.
Na przykład gdy wartość Count = 3 i DurationType = Tygodnie, czas przechowywania będzie wynosić trzy tygodnie.
|
durationType
|
RetentionDurationType
|
Typ czasu przechowywania zasad przechowywania.
|
RetentionDurationType
Typ czasu trwania przechowywania: dni/tygodnie/miesiące/lata Używane tylko wtedy, gdy dla warstwy TieringMode ustawiono wartość TierAfter
Nazwa |
Typ |
Opis |
Days
|
string
|
|
Invalid
|
string
|
|
Months
|
string
|
|
Weeks
|
string
|
|
Years
|
string
|
|
Typ formatu harmonogramu przechowywania dla zasad przechowywania miesięcznego.
Nazwa |
Typ |
Opis |
Daily
|
string
|
|
Invalid
|
string
|
|
Weekly
|
string
|
|
ScheduleRunType
Częstotliwość operacji harmonogramu tych zasad.
Nazwa |
Typ |
Opis |
Daily
|
string
|
|
Hourly
|
string
|
|
Invalid
|
string
|
|
Weekly
|
string
|
|
Settings
Typowe pole ustawień do zarządzania kopiami zapasowymi
Nazwa |
Typ |
Opis |
isCompression
|
boolean
|
Flaga kompresji obciążenia. Zostało to dodane tak, aby polecenie "isSqlCompression" zostało wycofane po uaktualnieniu klientów do rozważenia tej flagi.
|
issqlcompression
|
boolean
|
Flaga kompresji SQL
|
timeZone
|
string
|
Opcjonalne dane wejściowe strefy czasowej jako ciąg. Na przykład: TimeZone = "Pacific Standard Time".
|
SimpleRetentionPolicy
Proste przechowywanie zasad.
Nazwa |
Typ |
Opis |
retentionDuration
|
RetentionDuration
|
Czas przechowywania zasad ochrony.
|
retentionPolicyType
|
string:
SimpleRetentionPolicy
|
Ta właściwość będzie używana jako dyskryminująca do decydowania o określonych typach w łańcuchu polimorficznych typów.
|
SimpleSchedulePolicy
Prosty harmonogram zasad.
Nazwa |
Typ |
Opis |
hourlySchedule
|
HourlySchedule
|
Harmonogram godzinowy tych zasad
|
schedulePolicyType
|
string:
SimpleSchedulePolicy
|
Ta właściwość będzie używana jako dyskryminująca do decydowania o określonych typach w łańcuchu polimorficznych typów.
|
scheduleRunDays
|
DayOfWeek[]
|
Lista dni tygodnia, które należy uruchomić w tym harmonogramie.
|
scheduleRunFrequency
|
ScheduleRunType
|
Częstotliwość operacji harmonogramu tych zasad.
|
scheduleRunTimes
|
string[]
|
Lista godzin dnia, które należy uruchomić w tym harmonogramie.
|
scheduleWeeklyFrequency
|
integer
|
Przy każdej liczbie tygodni ten harmonogram musi być uruchamiany.
|
SimpleSchedulePolicyV2
Harmonogram zasad W wersji 2 dla IaaS, który obsługuje kopie zapasowe godzinowe.
Nazwa |
Typ |
Opis |
dailySchedule
|
DailySchedule
|
Dzienny harmonogram tych zasad
|
hourlySchedule
|
HourlySchedule
|
harmonogram godzinowy tych zasad
|
schedulePolicyType
|
string:
SimpleSchedulePolicyV2
|
Ta właściwość będzie używana jako dyskryminująca do decydowania o określonych typach w łańcuchu polimorficznych typów.
|
scheduleRunFrequency
|
ScheduleRunType
|
Częstotliwość operacji harmonogramu tych zasad.
|
weeklySchedule
|
WeeklySchedule
|
Harmonogram tygodniowy tych zasad
|
SubProtectionPolicy
Zasady ochrony podrzędnej, które obejmują harmonogram i przechowywanie
Nazwa |
Typ |
Opis |
policyType
|
PolicyType
|
Typ zasad kopii zapasowej
|
retentionPolicy
|
RetentionPolicy:
|
Zasady przechowywania ze szczegółami dotyczącymi zakresów przechowywania kopii zapasowych.
|
schedulePolicy
|
SchedulePolicy:
|
Harmonogram tworzenia kopii zapasowych określony w ramach zasad tworzenia kopii zapasowych.
|
tieringPolicy
|
<string,
TieringPolicy>
|
Zasady obsługi warstw w celu automatycznego przenoszenia adresów IP do innej warstwy.
Klucz jest warstwą docelową zdefiniowaną w wyliczenie RecoveryPointTierType.
Zasady obsługi warstw określa kryteria przenoszenia dostawcy zasobów do warstwy docelowej.
|
TieringMode
Tryb obsługi warstw w celu kontrolowania automatycznego obsługi warstw punktów odzyskiwania. Obsługiwane wartości to:
- TierRecommended: Warstwa wszystkie punkty odzyskiwania zalecane do warstwy
- TierAfter: Warstwa wszystkie punkty odzyskiwania po stałym okresie, jak określono w poniższym okresie czasu trwania i czasu trwania.
- DoNotTier: nie należy warstwowyć żadnych punktów odzyskiwania
Nazwa |
Typ |
Opis |
DoNotTier
|
string
|
|
Invalid
|
string
|
|
TierAfter
|
string
|
|
TierRecommended
|
string
|
|
TieringPolicy
Zasady obsługi warstw dla warstwy docelowej.
Jeśli zasady nie zostały określone dla danej warstwy docelowej, usługa zachowuje istniejące skonfigurowane zasady obsługi warstw dla tej warstwy
Nazwa |
Typ |
Opis |
duration
|
integer
|
Liczba dni/tygodni/miesięcy/lat przechowywania kopii zapasowych w bieżącej warstwie przed warstwą.
Używane tylko wtedy, gdy właściwość TieringMode jest ustawiona na TierAfter
|
durationType
|
RetentionDurationType
|
Typ czasu trwania przechowywania: dni/tygodnie/miesiące/lata Używane tylko wtedy, gdy dla warstwy TieringMode ustawiono wartość TierAfter
|
tieringMode
|
TieringMode
|
Tryb obsługi warstw w celu kontrolowania automatycznego obsługi warstw punktów odzyskiwania. Obsługiwane wartości to:
- TierRecommended: Warstwa wszystkie punkty odzyskiwania zalecane do warstwy
- TierAfter: Warstwa wszystkie punkty odzyskiwania po stałym okresie, jak określono w poniższym okresie czasu trwania i czasu trwania.
- DoNotTier: nie należy warstwowyć żadnych punktów odzyskiwania
|
Format przechowywania tygodniowego.
Nazwa |
Typ |
Opis |
daysOfTheWeek
|
DayOfWeek[]
|
Lista dni tygodnia.
|
weeksOfTheMonth
|
WeekOfMonth[]
|
Lista tygodni miesiąca.
|
WeeklyRetentionSchedule
Harmonogram przechowywania tygodniowego.
Nazwa |
Typ |
Opis |
daysOfTheWeek
|
DayOfWeek[]
|
Lista dni tygodnia dla zasad przechowywania tygodniowego.
|
retentionDuration
|
RetentionDuration
|
Czas przechowywania zasad przechowywania.
|
retentionTimes
|
string[]
|
Czas przechowywania zasad przechowywania.
|
WeeklySchedule
Nazwa |
Typ |
Opis |
scheduleRunDays
|
DayOfWeek[]
|
|
scheduleRunTimes
|
string[]
|
Lista godzin dnia, które należy uruchomić w tym harmonogramie.
|
WeekOfMonth
Lista tygodni miesiąca.
Nazwa |
Typ |
Opis |
First
|
string
|
|
Fourth
|
string
|
|
Invalid
|
string
|
|
Last
|
string
|
|
Second
|
string
|
|
Third
|
string
|
|
WorkloadType
Typ obciążenia dla zarządzania kopiami zapasowymi
Nazwa |
Typ |
Opis |
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
Harmonogram przechowywania rocznego.
Nazwa |
Typ |
Opis |
monthsOfYear
|
MonthOfYear[]
|
Lista miesięcy roku rocznej zasady przechowywania.
|
retentionDuration
|
RetentionDuration
|
Czas przechowywania zasad przechowywania.
|
retentionScheduleDaily
|
DailyRetentionFormat
|
Format przechowywania dziennego dla zasad przechowywania rocznego.
|
retentionScheduleFormatType
|
RetentionScheduleFormat
|
Format harmonogramu przechowywania dla zasad przechowywania długoterminowego.
|
retentionScheduleWeekly
|
WeeklyRetentionFormat
|
Format przechowywania tygodniowego dla zasad przechowywania rocznego.
|
retentionTimes
|
string[]
|
Czas przechowywania zasad przechowywania.
|