Crea o modifica un criterio di backup. Si tratta di un'operazione asincrona. Lo stato dell'operazione può essere recuperato tramite l'API GetPolicyOperationResult.
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}?api-version=2025-02-01
Parametri dell'URI
Nome |
In |
Necessario |
Tipo |
Descrizione |
policyName
|
path |
True
|
string
|
Criteri di backup da creare.
|
resourceGroupName
|
path |
True
|
string
|
Nome del gruppo di risorse in cui è presente l'insieme di credenziali dei servizi di ripristino.
|
subscriptionId
|
path |
True
|
string
|
ID sottoscrizione.
|
vaultName
|
path |
True
|
string
|
Nome dell'insieme di credenziali di Servizi di ripristino.
|
api-version
|
query |
True
|
string
|
Versione dell'API client.
|
Nome |
Necessario |
Tipo |
Descrizione |
x-ms-authorization-auxiliary
|
|
string
|
|
Corpo della richiesta
Nome |
Tipo |
Descrizione |
eTag
|
string
|
ETag facoltativo.
|
location
|
string
|
Percorso della risorsa.
|
properties
|
ProtectionPolicy:
|
Proprietà ProtectionPolicyResource
|
tags
|
object
|
Tag di risorsa.
|
Risposte
Nome |
Tipo |
Descrizione |
200 OK
|
ProtectionPolicyResource
|
Va bene
|
202 Accepted
|
|
Accettato
|
Other Status Codes
|
CloudError
|
Risposta di errore che descrive il motivo per cui l'operazione non è riuscita.
|
Sicurezza
azure_auth
Flusso OAuth2 di Azure Active Directory
Tipo:
oauth2
Flow:
implicit
URL di autorizzazione:
https://login.microsoftonline.com/common/oauth2/authorize
Ambiti
Nome |
Descrizione |
user_impersonation
|
rappresentare l'account utente.
|
Esempio
Create or Update Azure Storage Vault Standard Protection Policy
Esempio di richiesta
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicyV2?api-version=2025-02-01
{
"properties": {
"backupManagementType": "AzureStorage",
"workLoadType": "AzureFileShare",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": [
"2023-07-18T09:30:00.000Z"
]
},
"timeZone": "UTC",
"vaultRetentionPolicy": {
"snapshotRetentionInDays": 5,
"vaultRetention": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 30,
"durationType": "Days"
}
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 60,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"January"
],
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
}
}
}
}
}
}
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureFileShareProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.LongTermRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthOfYear;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthlyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionScheduleFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.VaultRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeekOfMonth;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.WorkloadType;
import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Samples for ProtectionPolicies CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-02-01/examples/
* AzureStorage/ProtectionPolicies_CreateOrUpdate_Hardened.json
*/
/**
* Sample code: Create or Update Azure Storage Vault Standard Protection Policy.
*
* @param manager Entry point to RecoveryServicesBackupManager.
*/
public static void createOrUpdateAzureStorageVaultStandardProtectionPolicy(
com.azure.resourcemanager.recoveryservicesbackup.RecoveryServicesBackupManager manager) {
manager
.protectionPolicies().define(
"newPolicyV2")
.withRegion(
(String) null)
.withExistingVault("swaggertestvault",
"SwaggerTestRg")
.withProperties(
new AzureFileShareProtectionPolicy()
.withWorkLoadType(
WorkloadType.AZURE_FILE_SHARE)
.withSchedulePolicy(new SimpleSchedulePolicy().withScheduleRunFrequency(ScheduleRunType.DAILY)
.withScheduleRunTimes(Arrays.asList(OffsetDateTime.parse("2023-07-18T09:30:00.000Z"))))
.withVaultRetentionPolicy(
new VaultRetentionPolicy()
.withVaultRetention(new LongTermRetentionPolicy()
.withDailySchedule(new DailyRetentionSchedule()
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2023-07-18T09:30:00.000Z")))
.withRetentionDuration(new RetentionDuration().withCount(30)
.withDurationType(RetentionDurationType.DAYS)))
.withWeeklySchedule(new WeeklyRetentionSchedule()
.withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withRetentionTimes(Arrays.asList(OffsetDateTime.parse("2023-07-18T09:30:00.000Z")))
.withRetentionDuration(new RetentionDuration().withCount(12)
.withDurationType(RetentionDurationType.WEEKS)))
.withMonthlySchedule(
new MonthlyRetentionSchedule()
.withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withRetentionScheduleWeekly(new WeeklyRetentionFormat()
.withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionTimes(
Arrays.asList(OffsetDateTime.parse("2023-07-18T09:30:00.000Z")))
.withRetentionDuration(new RetentionDuration().withCount(60)
.withDurationType(RetentionDurationType.MONTHS)))
.withYearlySchedule(
new YearlyRetentionSchedule()
.withRetentionScheduleFormatType(RetentionScheduleFormat.WEEKLY)
.withMonthsOfYear(Arrays.asList(MonthOfYear.JANUARY))
.withRetentionScheduleWeekly(new WeeklyRetentionFormat()
.withDaysOfTheWeek(Arrays.asList(DayOfWeek.SUNDAY))
.withWeeksOfTheMonth(Arrays.asList(WeekOfMonth.FIRST)))
.withRetentionTimes(
Arrays.asList(OffsetDateTime.parse("2023-07-18T09:30:00.000Z")))
.withRetentionDuration(new RetentionDuration().withCount(10)
.withDurationType(RetentionDurationType.YEARS))))
.withSnapshotRetentionInDays(5))
.withTimeZone("UTC"))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_hardened.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="swaggertestvault",
resource_group_name="SwaggerTestRg",
policy_name="newPolicyV2",
parameters={
"properties": {
"backupManagementType": "AzureStorage",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": ["2023-07-18T09:30:00.000Z"],
},
"timeZone": "UTC",
"vaultRetentionPolicy": {
"snapshotRetentionInDays": 5,
"vaultRetention": {
"dailySchedule": {
"retentionDuration": {"count": 30, "durationType": "Days"},
"retentionTimes": ["2023-07-18T09:30:00.000Z"],
},
"monthlySchedule": {
"retentionDuration": {"count": 60, "durationType": "Months"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2023-07-18T09:30:00.000Z"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday"],
"retentionDuration": {"count": 12, "durationType": "Weeks"},
"retentionTimes": ["2023-07-18T09:30:00.000Z"],
},
"yearlySchedule": {
"monthsOfYear": ["January"],
"retentionDuration": {"count": 10, "durationType": "Years"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2023-07-18T09:30:00.000Z"],
},
},
},
"workLoadType": "AzureFileShare",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-02-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Hardened.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armrecoveryservicesbackup_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/148c3b0b44f7789ced94859992493fafd0072f83/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-02-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Hardened.json
func ExampleProtectionPoliciesClient_CreateOrUpdate_createOrUpdateAzureStorageVaultStandardProtectionPolicy() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armrecoveryservicesbackup.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewProtectionPoliciesClient().CreateOrUpdate(ctx, "swaggertestvault", "SwaggerTestRg", "newPolicyV2", armrecoveryservicesbackup.ProtectionPolicyResource{
Properties: &armrecoveryservicesbackup.AzureFileShareProtectionPolicy{
BackupManagementType: to.Ptr("AzureStorage"),
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t }())},
},
TimeZone: to.Ptr("UTC"),
VaultRetentionPolicy: &armrecoveryservicesbackup.VaultRetentionPolicy{
SnapshotRetentionInDays: to.Ptr[int32](5),
VaultRetention: &armrecoveryservicesbackup.LongTermRetentionPolicy{
RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](30),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t }())},
},
MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](60),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t }())},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](12),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t }())},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](10),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t }())},
},
},
},
WorkLoadType: to.Ptr(armrecoveryservicesbackup.WorkloadTypeAzureFileShare),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("newPolicyV2"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicyV2"),
// Properties: &armrecoveryservicesbackup.AzureFileShareProtectionPolicy{
// BackupManagementType: to.Ptr("AzureStorage"),
// ProtectedItemsCount: to.Ptr[int32](0),
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t}())},
// },
// TimeZone: to.Ptr("UTC"),
// VaultRetentionPolicy: &armrecoveryservicesbackup.VaultRetentionPolicy{
// SnapshotRetentionInDays: to.Ptr[int32](5),
// VaultRetention: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](30),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t}())},
// },
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](60),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](12),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](10),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2023-07-18T09:30:00.000Z"); return t}())},
// },
// },
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
require("dotenv/config");
/**
* 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/2025-02-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Hardened.json
*/
async function createOrUpdateAzureStorageVaultStandardProtectionPolicy() {
const subscriptionId =
process.env["RECOVERYSERVICESBACKUP_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const vaultName = "swaggertestvault";
const resourceGroupName = process.env["RECOVERYSERVICESBACKUP_RESOURCE_GROUP"] || "SwaggerTestRg";
const policyName = "newPolicyV2";
const parameters = {
properties: {
backupManagementType: "AzureStorage",
schedulePolicy: {
schedulePolicyType: "SimpleSchedulePolicy",
scheduleRunFrequency: "Daily",
scheduleRunTimes: [new Date("2023-07-18T09:30:00.000Z")],
},
timeZone: "UTC",
vaultRetentionPolicy: {
snapshotRetentionInDays: 5,
vaultRetention: {
dailySchedule: {
retentionDuration: { count: 30, durationType: "Days" },
retentionTimes: [new Date("2023-07-18T09:30:00.000Z")],
},
monthlySchedule: {
retentionDuration: { count: 60, durationType: "Months" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [new Date("2023-07-18T09:30:00.000Z")],
},
retentionPolicyType: "LongTermRetentionPolicy",
weeklySchedule: {
daysOfTheWeek: ["Sunday"],
retentionDuration: { count: 12, durationType: "Weeks" },
retentionTimes: [new Date("2023-07-18T09:30:00.000Z")],
},
yearlySchedule: {
monthsOfYear: ["January"],
retentionDuration: { count: 10, durationType: "Years" },
retentionScheduleDaily: {},
retentionScheduleFormatType: "Weekly",
retentionScheduleWeekly: {
daysOfTheWeek: ["Sunday"],
weeksOfTheMonth: ["First"],
},
retentionTimes: [new Date("2023-07-18T09:30:00.000Z")],
},
},
},
workLoadType: "AzureFileShare",
},
};
const credential = new DefaultAzureCredential();
const client = new RecoveryServicesBackupClient(credential, subscriptionId);
const result = await client.protectionPolicies.createOrUpdate(
vaultName,
resourceGroupName,
policyName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.RecoveryServicesBackup;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-02-01/examples/AzureStorage/ProtectionPolicies_CreateOrUpdate_Hardened.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 BackupProtectionPolicyResource created on azure
// for more information of creating BackupProtectionPolicyResource, please refer to the document of BackupProtectionPolicyResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
string vaultName = "swaggertestvault";
string policyName = "newPolicyV2";
ResourceIdentifier backupProtectionPolicyResourceId = BackupProtectionPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, vaultName, policyName);
BackupProtectionPolicyResource backupProtectionPolicy = client.GetBackupProtectionPolicyResource(backupProtectionPolicyResourceId);
// invoke the operation
BackupProtectionPolicyData data = new BackupProtectionPolicyData(default)
{
Properties = new FileShareProtectionPolicy
{
WorkLoadType = BackupWorkloadType.AzureFileShare,
SchedulePolicy = new SimpleSchedulePolicy
{
ScheduleRunFrequency = ScheduleRunType.Daily,
ScheduleRunTimes = { default },
},
VaultRetentionPolicy = new VaultRetentionPolicy(new LongTermRetentionPolicy
{
DailySchedule = new DailyRetentionSchedule
{
RetentionTimes = { default },
RetentionDuration = new RetentionDuration
{
Count = 30,
DurationType = RetentionDurationType.Days,
},
},
WeeklySchedule = new WeeklyRetentionSchedule
{
DaysOfTheWeek = { BackupDayOfWeek.Sunday },
RetentionTimes = { default },
RetentionDuration = new RetentionDuration
{
Count = 12,
DurationType = RetentionDurationType.Weeks,
},
},
MonthlySchedule = new MonthlyRetentionSchedule
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
RetentionScheduleWeekly = new WeeklyRetentionFormat
{
DaysOfTheWeek = { BackupDayOfWeek.Sunday },
WeeksOfTheMonth = { BackupWeekOfMonth.First },
},
RetentionTimes = { default },
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 = { default },
RetentionDuration = new RetentionDuration
{
Count = 10,
DurationType = RetentionDurationType.Years,
},
},
}, 5),
TimeZone = "UTC",
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await backupProtectionPolicy.UpdateAsync(WaitUntil.Completed, 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
Risposta di esempio
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicyV2",
"name": "newPolicyV2",
"type": "Microsoft.RecoveryServices/vaults/backupPolicies",
"properties": {
"backupManagementType": "AzureStorage",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": [
"2023-07-18T09:30:00.000Z"
]
},
"vaultRetentionPolicy": {
"snapshotRetentionInDays": 5,
"vaultRetention": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 30,
"durationType": "Days"
}
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
}
},
"monthlySchedule": {
"retentionScheduleFormatType": "Weekly",
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 60,
"durationType": "Months"
}
},
"yearlySchedule": {
"retentionScheduleFormatType": "Weekly",
"monthsOfYear": [
"January"
],
"retentionScheduleDaily": null,
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2023-07-18T09:30:00.000Z"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
}
}
}
},
"timeZone": "UTC",
"protectedItemsCount": 0
}
}
Location: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicyV2/operationResults/00000000-0000-0000-0000-000000000000?api-version=2025-02-01
Azure-AsyncOperation: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicyV2/operations/00000000-0000-0000-0000-000000000000?api-version=2025-02-01
Retry-After: 60
Create or Update Daily Azure Storage Protection Policy
Esempio di richiesta
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/dailyPolicy2?api-version=2025-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/2025-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.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_daily.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="swaggertestvault",
resource_group_name="SwaggerTestRg",
policy_name="dailyPolicy2",
parameters={
"properties": {
"backupManagementType": "AzureStorage",
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {"count": 5, "durationType": "Days"},
"retentionTimes": ["2021-09-29T08:00:00.000Z"],
},
"monthlySchedule": {
"retentionDuration": {"count": 60, "durationType": "Months"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-09-29T08:00:00.000Z"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday"],
"retentionDuration": {"count": 12, "durationType": "Weeks"},
"retentionTimes": ["2021-09-29T08:00:00.000Z"],
},
"yearlySchedule": {
"monthsOfYear": ["January"],
"retentionDuration": {"count": 10, "durationType": "Years"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-09-29T08:00:00.000Z"],
},
},
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": ["2021-09-29T08:00:00.000Z"],
},
"timeZone": "UTC",
"workLoadType": "AzureFileShare",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/148c3b0b44f7789ced94859992493fafd0072f83/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("dailyPolicy2"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/dailyPolicy2"),
// Properties: &armrecoveryservicesbackup.AzureFileShareProtectionPolicy{
// BackupManagementType: to.Ptr("AzureStorage"),
// ProtectedItemsCount: to.Ptr[int32](0),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](5),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}())},
// },
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](60),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](12),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](10),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}())},
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// TimeZone: to.Ptr("UTC"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
require("dotenv/config");
/**
* 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/2025-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 Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.RecoveryServicesBackup;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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 BackupProtectionPolicyResource created on azure
// for more information of creating BackupProtectionPolicyResource, please refer to the document of BackupProtectionPolicyResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
string vaultName = "swaggertestvault";
string policyName = "dailyPolicy2";
ResourceIdentifier backupProtectionPolicyResourceId = BackupProtectionPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, vaultName, policyName);
BackupProtectionPolicyResource backupProtectionPolicy = client.GetBackupProtectionPolicyResource(backupProtectionPolicyResourceId);
// invoke the operation
BackupProtectionPolicyData data = new BackupProtectionPolicyData(default)
{
Properties = new FileShareProtectionPolicy
{
WorkLoadType = BackupWorkloadType.AzureFileShare,
SchedulePolicy = new SimpleSchedulePolicy
{
ScheduleRunFrequency = ScheduleRunType.Daily,
ScheduleRunTimes = { default },
},
RetentionPolicy = new LongTermRetentionPolicy
{
DailySchedule = new DailyRetentionSchedule
{
RetentionTimes = { default },
RetentionDuration = new RetentionDuration
{
Count = 5,
DurationType = RetentionDurationType.Days,
},
},
WeeklySchedule = new WeeklyRetentionSchedule
{
DaysOfTheWeek = { BackupDayOfWeek.Sunday },
RetentionTimes = { default },
RetentionDuration = new RetentionDuration
{
Count = 12,
DurationType = RetentionDurationType.Weeks,
},
},
MonthlySchedule = new MonthlyRetentionSchedule
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
RetentionScheduleWeekly = new WeeklyRetentionFormat
{
DaysOfTheWeek = { BackupDayOfWeek.Sunday },
WeeksOfTheMonth = { BackupWeekOfMonth.First },
},
RetentionTimes = { default },
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 = { default },
RetentionDuration = new RetentionDuration
{
Count = 10,
DurationType = RetentionDurationType.Years,
},
},
},
TimeZone = "UTC",
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await backupProtectionPolicy.UpdateAsync(WaitUntil.Completed, 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
Risposta di esempio
{
"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
Esempio di richiesta
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample?api-version=2025-02-01
{
"properties": {
"backupManagementType": "AzureIaasVM",
"timeZone": "India Standard Time",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"snapshotConsistencyType": "OnlyCrashConsistent",
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Daily",
"dailySchedule": {
"scheduleRunTimes": [
"2018-01-24T10:00:00Z"
]
}
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionDuration": {
"count": 180,
"durationType": "Days"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"monthlySchedule": {
"retentionDuration": {
"count": 60,
"durationType": "Months"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"yearlySchedule": {
"monthsOfYear": [
"January"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
}
}
}
}
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureIaaSvmProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailySchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.IaasVMSnapshotConsistencyType;
import com.azure.resourcemanager.recoveryservicesbackup.models.IaasvmPolicyType;
import com.azure.resourcemanager.recoveryservicesbackup.models.LongTermRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthOfYear;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthlyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionScheduleFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicyV2;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeekOfMonth;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Samples for ProtectionPolicies CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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)
.withSnapshotConsistencyType(IaasVMSnapshotConsistencyType.ONLY_CRASH_CONSISTENT))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python iaa_s_v2_daily.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="NetSDKTestRsVault",
resource_group_name="SwaggerTestRg",
policy_name="v2-daily-sample",
parameters={
"properties": {
"backupManagementType": "AzureIaasVM",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {"count": 180, "durationType": "Days"},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"monthlySchedule": {
"retentionDuration": {"count": 60, "durationType": "Months"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday"],
"retentionDuration": {"count": 12, "durationType": "Weeks"},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"yearlySchedule": {
"monthsOfYear": ["January"],
"retentionDuration": {"count": 10, "durationType": "Years"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
},
"schedulePolicy": {
"dailySchedule": {"scheduleRunTimes": ["2018-01-24T10:00:00Z"]},
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Daily",
},
"snapshotConsistencyType": "OnlyCrashConsistent",
"timeZone": "India Standard Time",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/148c3b0b44f7789ced94859992493fafd0072f83/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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.000Z"); return t }())},
},
MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](60),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](12),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](10),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicyV2{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicyV2"),
DailySchedule: &armrecoveryservicesbackup.DailySchedule{
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
},
SnapshotConsistencyType: to.Ptr(armrecoveryservicesbackup.IaasVMSnapshotConsistencyTypeOnlyCrashConsistent),
TimeZone: to.Ptr("India Standard Time"),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("v2-daily-sample"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample"),
// Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
// BackupManagementType: to.Ptr("AzureIaasVM"),
// ProtectedItemsCount: to.Ptr[int32](0),
// InstantRpRetentionRangeInDays: to.Ptr[int32](30),
// PolicyType: to.Ptr(armrecoveryservicesbackup.IAASVMPolicyTypeV2),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](180),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](60),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](12),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](10),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicyV2{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicyV2"),
// DailySchedule: &armrecoveryservicesbackup.DailySchedule{
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
// },
// SnapshotConsistencyType: to.Ptr(armrecoveryservicesbackup.IaasVMSnapshotConsistencyTypeOnlyCrashConsistent),
// TimeZone: to.Ptr("India Standard Time"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
require("dotenv/config");
/**
* 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/2025-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",
},
snapshotConsistencyType: "OnlyCrashConsistent",
timeZone: "India Standard Time",
},
};
const credential = new DefaultAzureCredential();
const client = new RecoveryServicesBackupClient(credential, subscriptionId);
const result = await client.protectionPolicies.createOrUpdate(
vaultName,
resourceGroupName,
policyName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.RecoveryServicesBackup;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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 BackupProtectionPolicyResource created on azure
// for more information of creating BackupProtectionPolicyResource, please refer to the document of BackupProtectionPolicyResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
string vaultName = "NetSDKTestRsVault";
string policyName = "v2-daily-sample";
ResourceIdentifier backupProtectionPolicyResourceId = BackupProtectionPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, vaultName, policyName);
BackupProtectionPolicyResource backupProtectionPolicy = client.GetBackupProtectionPolicyResource(backupProtectionPolicyResourceId);
// invoke the operation
BackupProtectionPolicyData data = new BackupProtectionPolicyData(default)
{
Properties = new IaasVmProtectionPolicy
{
SchedulePolicy = new SimpleSchedulePolicyV2
{
ScheduleRunFrequency = ScheduleRunType.Daily,
ScheduleRunTimes = { default },
},
RetentionPolicy = new LongTermRetentionPolicy
{
DailySchedule = new DailyRetentionSchedule
{
RetentionTimes = { default },
RetentionDuration = new RetentionDuration
{
Count = 180,
DurationType = RetentionDurationType.Days,
},
},
WeeklySchedule = new WeeklyRetentionSchedule
{
DaysOfTheWeek = { BackupDayOfWeek.Sunday },
RetentionTimes = { default },
RetentionDuration = new RetentionDuration
{
Count = 12,
DurationType = RetentionDurationType.Weeks,
},
},
MonthlySchedule = new MonthlyRetentionSchedule
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
RetentionScheduleWeekly = new WeeklyRetentionFormat
{
DaysOfTheWeek = { BackupDayOfWeek.Sunday },
WeeksOfTheMonth = { BackupWeekOfMonth.First },
},
RetentionTimes = { default },
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 = { default },
RetentionDuration = new RetentionDuration
{
Count = 10,
DurationType = RetentionDurationType.Years,
},
},
},
InstantRPRetentionRangeInDays = 30,
TimeZone = "India Standard Time",
PolicyType = IaasVmPolicyType.V2,
SnapshotConsistencyType = IaasVmSnapshotConsistencyType.OnlyCrashConsistent,
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await backupProtectionPolicy.UpdateAsync(WaitUntil.Completed, 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
Risposta di esempio
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample",
"name": "v2-daily-sample",
"properties": {
"backupManagementType": "AzureIaasVM",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"snapshotConsistencyType": "OnlyCrashConsistent",
"protectedItemsCount": 0,
"resourceGuardOperationRequests": null,
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {
"count": 180,
"durationType": "Days"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"monthlySchedule": {
"retentionDuration": {
"count": 60,
"durationType": "Months"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"yearlySchedule": {
"monthsOfYear": [
"January"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
}
},
"schedulePolicy": {
"dailySchedule": {
"scheduleRunTimes": [
"2018-01-24T10:00:00Z"
]
},
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Daily"
},
"timeZone": "India Standard Time"
},
"type": "Microsoft.RecoveryServices/vaults/backupPolicies"
}
Location: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample/operationResults/00000000-0000-0000-0000-000000000000?api-version=2020-06-01
Azure-AsyncOperation: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample/operations/00000000-0000-0000-0000-000000000000?api-version=2020-06-01
Retry-After: 60
Create or Update Enhanced Azure Vm Protection Policy with Hourly backup
Esempio di richiesta
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample?api-version=2025-02-01
{
"properties": {
"backupManagementType": "AzureIaasVM",
"timeZone": "India Standard Time",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"snapshotConsistencyType": "OnlyCrashConsistent",
"schedulePolicy": {
"hourlySchedule": {
"interval": 4,
"scheduleWindowDuration": 16,
"scheduleWindowStartTime": "2021-12-17T08:00:00Z"
},
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Hourly"
},
"retentionPolicy": {
"retentionPolicyType": "LongTermRetentionPolicy",
"dailySchedule": {
"retentionDuration": {
"count": 180,
"durationType": "Days"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"monthlySchedule": {
"retentionDuration": {
"count": 60,
"durationType": "Months"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"yearlySchedule": {
"monthsOfYear": [
"January"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
}
}
}
}
import com.azure.resourcemanager.recoveryservicesbackup.models.AzureIaaSvmProtectionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.DailyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.DayOfWeek;
import com.azure.resourcemanager.recoveryservicesbackup.models.HourlySchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.IaasVMSnapshotConsistencyType;
import com.azure.resourcemanager.recoveryservicesbackup.models.IaasvmPolicyType;
import com.azure.resourcemanager.recoveryservicesbackup.models.LongTermRetentionPolicy;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthOfYear;
import com.azure.resourcemanager.recoveryservicesbackup.models.MonthlyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDuration;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionDurationType;
import com.azure.resourcemanager.recoveryservicesbackup.models.RetentionScheduleFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.ScheduleRunType;
import com.azure.resourcemanager.recoveryservicesbackup.models.SimpleSchedulePolicyV2;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeekOfMonth;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionFormat;
import com.azure.resourcemanager.recoveryservicesbackup.models.WeeklyRetentionSchedule;
import com.azure.resourcemanager.recoveryservicesbackup.models.YearlyRetentionSchedule;
import java.time.OffsetDateTime;
import java.util.Arrays;
/**
* Samples for ProtectionPolicies CreateOrUpdate.
*/
public final class Main {
/*
* x-ms-original-file:
* specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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)
.withSnapshotConsistencyType(IaasVMSnapshotConsistencyType.ONLY_CRASH_CONSISTENT))
.create();
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python iaa_s_v2_hourly.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="NetSDKTestRsVault",
resource_group_name="SwaggerTestRg",
policy_name="v2-daily-sample",
parameters={
"properties": {
"backupManagementType": "AzureIaasVM",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {"count": 180, "durationType": "Days"},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"monthlySchedule": {
"retentionDuration": {"count": 60, "durationType": "Months"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday"],
"retentionDuration": {"count": 12, "durationType": "Weeks"},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
"yearlySchedule": {
"monthsOfYear": ["January"],
"retentionDuration": {"count": 10, "durationType": "Years"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": ["2021-12-17T08:00:00+00:00"],
},
},
"schedulePolicy": {
"hourlySchedule": {
"interval": 4,
"scheduleWindowDuration": 16,
"scheduleWindowStartTime": "2021-12-17T08:00:00Z",
},
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Hourly",
},
"snapshotConsistencyType": "OnlyCrashConsistent",
"timeZone": "India Standard Time",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/148c3b0b44f7789ced94859992493fafd0072f83/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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.000Z"); return t }())},
},
MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](60),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](12),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](10),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }())},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicyV2{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicyV2"),
HourlySchedule: &armrecoveryservicesbackup.HourlySchedule{
Interval: to.Ptr[int32](4),
ScheduleWindowDuration: to.Ptr[int32](16),
ScheduleWindowStartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t }()),
},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeHourly),
},
SnapshotConsistencyType: to.Ptr(armrecoveryservicesbackup.IaasVMSnapshotConsistencyTypeOnlyCrashConsistent),
TimeZone: to.Ptr("India Standard Time"),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("v2-daily-sample"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample"),
// Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
// BackupManagementType: to.Ptr("AzureIaasVM"),
// ProtectedItemsCount: to.Ptr[int32](0),
// InstantRpRetentionRangeInDays: to.Ptr[int32](30),
// PolicyType: to.Ptr(armrecoveryservicesbackup.IAASVMPolicyTypeV2),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](180),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](60),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](12),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](10),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicyV2{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicyV2"),
// HourlySchedule: &armrecoveryservicesbackup.HourlySchedule{
// Interval: to.Ptr[int32](4),
// ScheduleWindowDuration: to.Ptr[int32](16),
// ScheduleWindowStartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-12-17T08:00:00.000Z"); return t}()),
// },
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeHourly),
// },
// SnapshotConsistencyType: to.Ptr(armrecoveryservicesbackup.IaasVMSnapshotConsistencyTypeOnlyCrashConsistent),
// TimeZone: to.Ptr("India Standard Time"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
require("dotenv/config");
/**
* 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/2025-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",
},
snapshotConsistencyType: "OnlyCrashConsistent",
timeZone: "India Standard Time",
},
};
const credential = new DefaultAzureCredential();
const client = new RecoveryServicesBackupClient(credential, subscriptionId);
const result = await client.protectionPolicies.createOrUpdate(
vaultName,
resourceGroupName,
policyName,
parameters,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
using Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.RecoveryServicesBackup;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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 BackupProtectionPolicyResource created on azure
// for more information of creating BackupProtectionPolicyResource, please refer to the document of BackupProtectionPolicyResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
string vaultName = "NetSDKTestRsVault";
string policyName = "v2-daily-sample";
ResourceIdentifier backupProtectionPolicyResourceId = BackupProtectionPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, vaultName, policyName);
BackupProtectionPolicyResource backupProtectionPolicy = client.GetBackupProtectionPolicyResource(backupProtectionPolicyResourceId);
// invoke the operation
BackupProtectionPolicyData data = new BackupProtectionPolicyData(default)
{
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 = { default },
RetentionDuration = new RetentionDuration
{
Count = 180,
DurationType = RetentionDurationType.Days,
},
},
WeeklySchedule = new WeeklyRetentionSchedule
{
DaysOfTheWeek = { BackupDayOfWeek.Sunday },
RetentionTimes = { default },
RetentionDuration = new RetentionDuration
{
Count = 12,
DurationType = RetentionDurationType.Weeks,
},
},
MonthlySchedule = new MonthlyRetentionSchedule
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
RetentionScheduleWeekly = new WeeklyRetentionFormat
{
DaysOfTheWeek = { BackupDayOfWeek.Sunday },
WeeksOfTheMonth = { BackupWeekOfMonth.First },
},
RetentionTimes = { default },
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 = { default },
RetentionDuration = new RetentionDuration
{
Count = 10,
DurationType = RetentionDurationType.Years,
},
},
},
InstantRPRetentionRangeInDays = 30,
TimeZone = "India Standard Time",
PolicyType = IaasVmPolicyType.V2,
SnapshotConsistencyType = IaasVmSnapshotConsistencyType.OnlyCrashConsistent,
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await backupProtectionPolicy.UpdateAsync(WaitUntil.Completed, 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
Risposta di esempio
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample",
"name": "v2-daily-sample",
"properties": {
"backupManagementType": "AzureIaasVM",
"instantRpRetentionRangeInDays": 30,
"policyType": "V2",
"snapshotConsistencyType": "OnlyCrashConsistent",
"protectedItemsCount": 0,
"resourceGuardOperationRequests": null,
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {
"count": 180,
"durationType": "Days"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"monthlySchedule": {
"retentionDuration": {
"count": 60,
"durationType": "Months"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": [
"Sunday"
],
"retentionDuration": {
"count": 12,
"durationType": "Weeks"
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
},
"yearlySchedule": {
"monthsOfYear": [
"January"
],
"retentionDuration": {
"count": 10,
"durationType": "Years"
},
"retentionScheduleDaily": null,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": [
"Sunday"
],
"weeksOfTheMonth": [
"First"
]
},
"retentionTimes": [
"2021-12-17T08:00:00+00:00"
]
}
},
"schedulePolicy": {
"hourlySchedule": {
"interval": 4,
"scheduleWindowDuration": 16,
"scheduleWindowStartTime": "2021-12-17T08:00:00Z"
},
"schedulePolicyType": "SimpleSchedulePolicyV2",
"scheduleRunFrequency": "Hourly"
},
"timeZone": "India Standard Time"
},
"type": "Microsoft.RecoveryServices/vaults/backupPolicies"
}
Location: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample/operationResults/00000000-0000-0000-0000-000000000000?api-version=2020-06-01
Azure-AsyncOperation: https://management.azure.com/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/v2-daily-sample/operations/00000000-0000-0000-0000-000000000000?api-version=2020-06-01
Retry-After: 60
Create or Update Full Azure Vm Protection Policy
Esempio di richiesta
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1?api-version=2025-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/2025-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.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_complex.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="NetSDKTestRsVault",
resource_group_name="SwaggerTestRg",
policy_name="testPolicy1",
parameters={
"properties": {
"backupManagementType": "AzureIaasVM",
"retentionPolicy": {
"monthlySchedule": {
"retentionDuration": {"count": 2, "durationType": "Months"},
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": ["Wednesday", "Thursday"],
"weeksOfTheMonth": ["First", "Third"],
},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Monday", "Wednesday", "Thursday"],
"retentionDuration": {"count": 1, "durationType": "Weeks"},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
"yearlySchedule": {
"monthsOfYear": ["February", "November"],
"retentionDuration": {"count": 4, "durationType": "Years"},
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {
"daysOfTheWeek": ["Monday", "Thursday"],
"weeksOfTheMonth": ["Fourth"],
},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
},
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunDays": ["Monday", "Wednesday", "Thursday"],
"scheduleRunFrequency": "Weekly",
"scheduleRunTimes": ["2018-01-24T10:00:00Z"],
},
"timeZone": "Pacific Standard Time",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/148c3b0b44f7789ced94859992493fafd0072f83/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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:00.000Z"); return t }())},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekWednesday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](1),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearFebruary),
to.Ptr(armrecoveryservicesbackup.MonthOfYearNovember)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](4),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthFourth)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekWednesday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
TimeZone: to.Ptr("Pacific Standard Time"),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("testPolicy1"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1"),
// Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
// BackupManagementType: to.Ptr("AzureIaasVM"),
// ProtectedItemsCount: to.Ptr[int32](0),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](2),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekWednesday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst),
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthThird)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekWednesday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](1),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearFebruary),
// to.Ptr(armrecoveryservicesbackup.MonthOfYearNovember)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](4),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFourth)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekMonday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekWednesday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekThursday)},
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// TimeZone: to.Ptr("Pacific Standard Time"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
require("dotenv/config");
/**
* 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/2025-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 Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.RecoveryServicesBackup;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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 BackupProtectionPolicyResource created on azure
// for more information of creating BackupProtectionPolicyResource, please refer to the document of BackupProtectionPolicyResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
string vaultName = "NetSDKTestRsVault";
string policyName = "testPolicy1";
ResourceIdentifier backupProtectionPolicyResourceId = BackupProtectionPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, vaultName, policyName);
BackupProtectionPolicyResource backupProtectionPolicy = client.GetBackupProtectionPolicyResource(backupProtectionPolicyResourceId);
// invoke the operation
BackupProtectionPolicyData data = new BackupProtectionPolicyData(default)
{
Properties = new IaasVmProtectionPolicy
{
SchedulePolicy = new SimpleSchedulePolicy
{
ScheduleRunFrequency = ScheduleRunType.Weekly,
ScheduleRunDays = { BackupDayOfWeek.Monday, BackupDayOfWeek.Wednesday, BackupDayOfWeek.Thursday },
ScheduleRunTimes = { default },
},
RetentionPolicy = new LongTermRetentionPolicy
{
WeeklySchedule = new WeeklyRetentionSchedule
{
DaysOfTheWeek = { BackupDayOfWeek.Monday, BackupDayOfWeek.Wednesday, BackupDayOfWeek.Thursday },
RetentionTimes = { default },
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 = { default },
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 = { default },
RetentionDuration = new RetentionDuration
{
Count = 4,
DurationType = RetentionDurationType.Years,
},
},
},
TimeZone = "Pacific Standard Time",
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await backupProtectionPolicy.UpdateAsync(WaitUntil.Completed, 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
Risposta di esempio
{
"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
Esempio di richiesta
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1?api-version=2025-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/2025-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
from azure.identity import DefaultAzureCredential
from azure.mgmt.recoveryservicesbackup.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_complex.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="NetSDKTestRsVault",
resource_group_name="SwaggerTestRg",
policy_name="testPolicy1",
parameters={
"properties": {
"backupManagementType": "AzureWorkload",
"settings": {"issqlcompression": False, "timeZone": "Pacific Standard Time"},
"subProtectionPolicy": [
{
"policyType": "Full",
"retentionPolicy": {
"monthlySchedule": {
"retentionDuration": {"count": 1, "durationType": "Months"},
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["Second"]},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday", "Tuesday"],
"retentionDuration": {"count": 2, "durationType": "Weeks"},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
"yearlySchedule": {
"monthsOfYear": ["January", "June", "December"],
"retentionDuration": {"count": 1, "durationType": "Years"},
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["Last"]},
"retentionTimes": ["2018-01-24T10:00:00Z"],
},
},
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunDays": ["Sunday", "Tuesday"],
"scheduleRunFrequency": "Weekly",
"scheduleRunTimes": ["2018-01-24T10:00:00Z"],
},
},
{
"policyType": "Differential",
"retentionPolicy": {
"retentionDuration": {"count": 8, "durationType": "Days"},
"retentionPolicyType": "SimpleRetentionPolicy",
},
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunDays": ["Friday"],
"scheduleRunFrequency": "Weekly",
"scheduleRunTimes": ["2018-01-24T10:00:00Z"],
},
},
{
"policyType": "Log",
"retentionPolicy": {
"retentionDuration": {"count": 7, "durationType": "Days"},
"retentionPolicyType": "SimpleRetentionPolicy",
},
"schedulePolicy": {"scheduleFrequencyInMins": 60, "schedulePolicyType": "LogSchedulePolicy"},
},
],
"workLoadType": "SQLDataBase",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-02-01/examples/AzureWorkload/ProtectionPolicies_CreateOrUpdate_Complex.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armrecoveryservicesbackup_test
import (
"context"
"log"
"time"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/recoveryservices/armrecoveryservicesbackup/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/148c3b0b44f7789ced94859992493fafd0072f83/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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:00.000Z"); return t }())},
},
WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekTuesday)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](2),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary),
to.Ptr(armrecoveryservicesbackup.MonthOfYearJune),
to.Ptr(armrecoveryservicesbackup.MonthOfYearDecember)},
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](1),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
},
RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
to.Ptr(armrecoveryservicesbackup.WeekOfMonthLast)},
},
RetentionTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday),
to.Ptr(armrecoveryservicesbackup.DayOfWeekTuesday)},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
},
{
PolicyType: to.Ptr(armrecoveryservicesbackup.PolicyTypeDifferential),
RetentionPolicy: &armrecoveryservicesbackup.SimpleRetentionPolicy{
RetentionPolicyType: to.Ptr("SimpleRetentionPolicy"),
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](8),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
to.Ptr(armrecoveryservicesbackup.DayOfWeekFriday)},
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t }())},
},
},
{
PolicyType: to.Ptr(armrecoveryservicesbackup.PolicyTypeLog),
RetentionPolicy: &armrecoveryservicesbackup.SimpleRetentionPolicy{
RetentionPolicyType: to.Ptr("SimpleRetentionPolicy"),
RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
Count: to.Ptr[int32](7),
DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
},
},
SchedulePolicy: &armrecoveryservicesbackup.LogSchedulePolicy{
SchedulePolicyType: to.Ptr("LogSchedulePolicy"),
ScheduleFrequencyInMins: to.Ptr[int32](60),
},
}},
WorkLoadType: to.Ptr(armrecoveryservicesbackup.WorkloadTypeSQLDataBase),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("testPolicy1"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1"),
// Properties: &armrecoveryservicesbackup.AzureVMWorkloadProtectionPolicy{
// BackupManagementType: to.Ptr("AzureWorkload"),
// ProtectedItemsCount: to.Ptr[int32](0),
// Settings: &armrecoveryservicesbackup.Settings{
// Issqlcompression: to.Ptr(false),
// TimeZone: to.Ptr("Pacific Standard Time"),
// },
// SubProtectionPolicy: []*armrecoveryservicesbackup.SubProtectionPolicy{
// {
// PolicyType: to.Ptr(armrecoveryservicesbackup.PolicyTypeFull),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](1),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthSecond)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekTuesday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](2),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary),
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJune),
// to.Ptr(armrecoveryservicesbackup.MonthOfYearDecember)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](1),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthLast)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday),
// to.Ptr(armrecoveryservicesbackup.DayOfWeekTuesday)},
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// },
// {
// PolicyType: to.Ptr(armrecoveryservicesbackup.PolicyTypeDifferential),
// RetentionPolicy: &armrecoveryservicesbackup.SimpleRetentionPolicy{
// RetentionPolicyType: to.Ptr("SimpleRetentionPolicy"),
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](8),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunDays: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekFriday)},
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeWeekly),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T10:00:00.000Z"); return t}())},
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// },
// {
// PolicyType: to.Ptr(armrecoveryservicesbackup.PolicyTypeLog),
// RetentionPolicy: &armrecoveryservicesbackup.SimpleRetentionPolicy{
// RetentionPolicyType: to.Ptr("SimpleRetentionPolicy"),
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](7),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.LogSchedulePolicy{
// SchedulePolicyType: to.Ptr("LogSchedulePolicy"),
// ScheduleFrequencyInMins: to.Ptr[int32](60),
// },
// }},
// WorkLoadType: to.Ptr(armrecoveryservicesbackup.WorkloadTypeSQLDataBase),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
require("dotenv/config");
/**
* 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/2025-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 Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.RecoveryServicesBackup;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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 BackupProtectionPolicyResource created on azure
// for more information of creating BackupProtectionPolicyResource, please refer to the document of BackupProtectionPolicyResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
string vaultName = "NetSDKTestRsVault";
string policyName = "testPolicy1";
ResourceIdentifier backupProtectionPolicyResourceId = BackupProtectionPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, vaultName, policyName);
BackupProtectionPolicyResource backupProtectionPolicy = client.GetBackupProtectionPolicyResource(backupProtectionPolicyResourceId);
// invoke the operation
BackupProtectionPolicyData data = new BackupProtectionPolicyData(default)
{
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 = {default},
},
RetentionPolicy = new LongTermRetentionPolicy
{
WeeklySchedule = new WeeklyRetentionSchedule
{
DaysOfTheWeek = {BackupDayOfWeek.Sunday, BackupDayOfWeek.Tuesday},
RetentionTimes = {default},
RetentionDuration = new RetentionDuration
{
Count = 2,
DurationType = RetentionDurationType.Weeks,
},
},
MonthlySchedule = new MonthlyRetentionSchedule
{
RetentionScheduleFormatType = RetentionScheduleFormat.Weekly,
RetentionScheduleWeekly = new WeeklyRetentionFormat
{
DaysOfTheWeek = {BackupDayOfWeek.Sunday},
WeeksOfTheMonth = {BackupWeekOfMonth.Second},
},
RetentionTimes = {default},
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 = {default},
RetentionDuration = new RetentionDuration
{
Count = 1,
DurationType = RetentionDurationType.Years,
},
},
},
}, new SubProtectionPolicy
{
PolicyType = SubProtectionPolicyType.Differential,
SchedulePolicy = new SimpleSchedulePolicy
{
ScheduleRunFrequency = ScheduleRunType.Weekly,
ScheduleRunDays = {BackupDayOfWeek.Friday},
ScheduleRunTimes = {default},
},
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 backupProtectionPolicy.UpdateAsync(WaitUntil.Completed, 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
Risposta di esempio
{
"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
Esempio di richiesta
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicy2?api-version=2025-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/2025-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.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_hourly.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="swaggertestvault",
resource_group_name="SwaggerTestRg",
policy_name="newPolicy2",
parameters={
"properties": {
"backupManagementType": "AzureStorage",
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {"count": 5, "durationType": "Days"},
"retentionTimes": None,
},
"monthlySchedule": {
"retentionDuration": {"count": 60, "durationType": "Months"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": None,
},
"retentionPolicyType": "LongTermRetentionPolicy",
"weeklySchedule": {
"daysOfTheWeek": ["Sunday"],
"retentionDuration": {"count": 12, "durationType": "Weeks"},
"retentionTimes": None,
},
"yearlySchedule": {
"monthsOfYear": ["January"],
"retentionDuration": {"count": 10, "durationType": "Years"},
"retentionScheduleDaily": None,
"retentionScheduleFormatType": "Weekly",
"retentionScheduleWeekly": {"daysOfTheWeek": ["Sunday"], "weeksOfTheMonth": ["First"]},
"retentionTimes": None,
},
},
"schedulePolicy": {
"hourlySchedule": {
"interval": 4,
"scheduleWindowDuration": 12,
"scheduleWindowStartTime": "2021-09-29T08:00:00.000Z",
},
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Hourly",
},
"timeZone": "UTC",
"workLoadType": "AzureFileShare",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/148c3b0b44f7789ced94859992493fafd0072f83/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("newPolicy2"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/swaggertestvault/backupPolicies/newPolicy2"),
// Properties: &armrecoveryservicesbackup.AzureFileShareProtectionPolicy{
// BackupManagementType: to.Ptr("AzureStorage"),
// ProtectedItemsCount: to.Ptr[int32](0),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](5),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T20:00:00.000Z"); return t}())},
// },
// MonthlySchedule: &armrecoveryservicesbackup.MonthlyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](60),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeMonths),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T20:00:00.000Z"); return t}())},
// },
// WeeklySchedule: &armrecoveryservicesbackup.WeeklyRetentionSchedule{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](12),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeWeeks),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T20:00:00.000Z"); return t}())},
// },
// YearlySchedule: &armrecoveryservicesbackup.YearlyRetentionSchedule{
// MonthsOfYear: []*armrecoveryservicesbackup.MonthOfYear{
// to.Ptr(armrecoveryservicesbackup.MonthOfYearJanuary)},
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](10),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeYears),
// },
// RetentionScheduleFormatType: to.Ptr(armrecoveryservicesbackup.RetentionScheduleFormatWeekly),
// RetentionScheduleWeekly: &armrecoveryservicesbackup.WeeklyRetentionFormat{
// DaysOfTheWeek: []*armrecoveryservicesbackup.DayOfWeek{
// to.Ptr(armrecoveryservicesbackup.DayOfWeekSunday)},
// WeeksOfTheMonth: []*armrecoveryservicesbackup.WeekOfMonth{
// to.Ptr(armrecoveryservicesbackup.WeekOfMonthFirst)},
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T20:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// HourlySchedule: &armrecoveryservicesbackup.HourlySchedule{
// Interval: to.Ptr[int32](4),
// ScheduleWindowDuration: to.Ptr[int32](12),
// ScheduleWindowStartTime: to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2021-09-29T08:00:00.000Z"); return t}()),
// },
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeHourly),
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// TimeZone: to.Ptr("UTC"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
require("dotenv/config");
/**
* 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/2025-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 Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.RecoveryServicesBackup;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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 BackupProtectionPolicyResource created on azure
// for more information of creating BackupProtectionPolicyResource, please refer to the document of BackupProtectionPolicyResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
string vaultName = "swaggertestvault";
string policyName = "newPolicy2";
ResourceIdentifier backupProtectionPolicyResourceId = BackupProtectionPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, vaultName, policyName);
BackupProtectionPolicyResource backupProtectionPolicy = client.GetBackupProtectionPolicyResource(backupProtectionPolicyResourceId);
// invoke the operation
BackupProtectionPolicyData data = new BackupProtectionPolicyData(default)
{
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 backupProtectionPolicy.UpdateAsync(WaitUntil.Completed, 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
Risposta di esempio
{
"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
Esempio di richiesta
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1?api-version=2025-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/2025-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.activestamp import RecoveryServicesBackupClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-recoveryservicesbackup
# USAGE
python protection_policies_create_or_update_simple.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = RecoveryServicesBackupClient(
credential=DefaultAzureCredential(),
subscription_id="00000000-0000-0000-0000-000000000000",
)
response = client.protection_policies.create_or_update(
vault_name="NetSDKTestRsVault",
resource_group_name="SwaggerTestRg",
policy_name="testPolicy1",
parameters={
"properties": {
"backupManagementType": "AzureIaasVM",
"retentionPolicy": {
"dailySchedule": {
"retentionDuration": {"count": 1, "durationType": "Days"},
"retentionTimes": ["2018-01-24T02:00:00Z"],
},
"retentionPolicyType": "LongTermRetentionPolicy",
},
"schedulePolicy": {
"schedulePolicyType": "SimpleSchedulePolicy",
"scheduleRunFrequency": "Daily",
"scheduleRunTimes": ["2018-01-24T02:00:00Z"],
},
"timeZone": "Pacific Standard Time",
}
},
)
print(response)
# x-ms-original-file: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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/v4"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/148c3b0b44f7789ced94859992493fafd0072f83/specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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:00.000Z"); return t }())},
},
},
SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
ScheduleRunTimes: []*time.Time{
to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T02:00:00.000Z"); return t }())},
},
TimeZone: to.Ptr("Pacific Standard Time"),
},
}, &armrecoveryservicesbackup.ProtectionPoliciesClientCreateOrUpdateOptions{XMSAuthorizationAuxiliary: nil})
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.ProtectionPolicyResource = armrecoveryservicesbackup.ProtectionPolicyResource{
// Name: to.Ptr("testPolicy1"),
// Type: to.Ptr("Microsoft.RecoveryServices/vaults/backupPolicies"),
// ID: to.Ptr("/Subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/SwaggerTestRg/providers/Microsoft.RecoveryServices/vaults/NetSDKTestRsVault/backupPolicies/testPolicy1"),
// Properties: &armrecoveryservicesbackup.AzureIaaSVMProtectionPolicy{
// BackupManagementType: to.Ptr("AzureIaasVM"),
// ProtectedItemsCount: to.Ptr[int32](0),
// RetentionPolicy: &armrecoveryservicesbackup.LongTermRetentionPolicy{
// RetentionPolicyType: to.Ptr("LongTermRetentionPolicy"),
// DailySchedule: &armrecoveryservicesbackup.DailyRetentionSchedule{
// RetentionDuration: &armrecoveryservicesbackup.RetentionDuration{
// Count: to.Ptr[int32](1),
// DurationType: to.Ptr(armrecoveryservicesbackup.RetentionDurationTypeDays),
// },
// RetentionTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T02:00:00.000Z"); return t}())},
// },
// },
// SchedulePolicy: &armrecoveryservicesbackup.SimpleSchedulePolicy{
// SchedulePolicyType: to.Ptr("SimpleSchedulePolicy"),
// ScheduleRunFrequency: to.Ptr(armrecoveryservicesbackup.ScheduleRunTypeDaily),
// ScheduleRunTimes: []*time.Time{
// to.Ptr(func() time.Time { t, _ := time.Parse(time.RFC3339Nano, "2018-01-24T02:00:00.000Z"); return t}())},
// ScheduleWeeklyFrequency: to.Ptr[int32](0),
// },
// TimeZone: to.Ptr("Pacific Standard Time"),
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { RecoveryServicesBackupClient } = require("@azure/arm-recoveryservicesbackup");
const { DefaultAzureCredential } = require("@azure/identity");
require("dotenv/config");
/**
* 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/2025-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 Azure;
using Azure.ResourceManager;
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;
using Azure.ResourceManager.RecoveryServicesBackup.Models;
using Azure.ResourceManager.RecoveryServicesBackup;
// Generated from example definition: specification/recoveryservicesbackup/resource-manager/Microsoft.RecoveryServices/stable/2025-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 BackupProtectionPolicyResource created on azure
// for more information of creating BackupProtectionPolicyResource, please refer to the document of BackupProtectionPolicyResource
string subscriptionId = "00000000-0000-0000-0000-000000000000";
string resourceGroupName = "SwaggerTestRg";
string vaultName = "NetSDKTestRsVault";
string policyName = "testPolicy1";
ResourceIdentifier backupProtectionPolicyResourceId = BackupProtectionPolicyResource.CreateResourceIdentifier(subscriptionId, resourceGroupName, vaultName, policyName);
BackupProtectionPolicyResource backupProtectionPolicy = client.GetBackupProtectionPolicyResource(backupProtectionPolicyResourceId);
// invoke the operation
BackupProtectionPolicyData data = new BackupProtectionPolicyData(default)
{
Properties = new IaasVmProtectionPolicy
{
SchedulePolicy = new SimpleSchedulePolicy
{
ScheduleRunFrequency = ScheduleRunType.Daily,
ScheduleRunTimes = { default },
},
RetentionPolicy = new LongTermRetentionPolicy
{
DailySchedule = new DailyRetentionSchedule
{
RetentionTimes = { default },
RetentionDuration = new RetentionDuration
{
Count = 1,
DurationType = RetentionDurationType.Days,
},
},
},
TimeZone = "Pacific Standard Time",
},
};
ArmOperation<BackupProtectionPolicyResource> lro = await backupProtectionPolicy.UpdateAsync(WaitUntil.Completed, 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
Risposta di esempio
{
"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
Definizioni
AzureFileShareProtectionPolicy
Object
Criteri di backup di AzureStorage.
Nome |
Tipo |
Descrizione |
backupManagementType
|
string:
AzureStorage
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
protectedItemsCount
|
integer
(int32)
|
Numero di elementi associati a questo criterio.
|
resourceGuardOperationRequests
|
string[]
|
Richieste di operazioni di ResourceGuard
|
retentionPolicy
|
RetentionPolicy:
|
Criteri di conservazione con i dettagli sugli intervalli di conservazione delle copie di backup.
|
schedulePolicy
|
SchedulePolicy:
|
Pianificazione del backup specificata come parte dei criteri di backup.
|
timeZone
|
string
|
Input facoltativo timeZone come stringa. Ad esempio: TimeZone = "Pacific Standard Time".
|
vaultRetentionPolicy
|
VaultRetentionPolicy
|
Criteri di conservazione con i dettagli sugli intervalli di conservazione delle copie di backup con protezione avanzata.
|
workLoadType
|
WorkloadType
|
Tipo di carico di lavoro per la gestione dei backup
|
AzureIaaSVMProtectionPolicy
Object
Criteri di backup specifici del carico di lavoro delle macchine virtuali IaaS.
Nome |
Tipo |
Descrizione |
backupManagementType
|
string:
AzureIaasVM
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
instantRPDetails
|
InstantRPAdditionalDetails
|
|
instantRpRetentionRangeInDays
|
integer
(int32)
|
Intervallo di criteri di conservazione rp istantaneo in giorni
|
policyType
|
IAASVMPolicyType
|
|
protectedItemsCount
|
integer
(int32)
|
Numero di elementi associati a questo criterio.
|
resourceGuardOperationRequests
|
string[]
|
Richieste di operazioni di ResourceGuard
|
retentionPolicy
|
RetentionPolicy:
|
Criteri di conservazione con i dettagli sugli intervalli di conservazione delle copie di backup.
|
schedulePolicy
|
SchedulePolicy:
|
Pianificazione del backup specificata come parte dei criteri di backup.
|
snapshotConsistencyType
|
IaasVMSnapshotConsistencyType
|
|
tieringPolicy
|
<string,
TieringPolicy>
|
I criteri di suddivisione in livelli per spostare automaticamente gli indirizzi RP in un altro livello chiave sono livello di destinazione, definiti nell'enumerazione RecoveryPointTierType.
I criteri di suddivisione in livelli specificano i criteri per spostare rp nel livello di destinazione.
|
timeZone
|
string
|
Input facoltativo timeZone come stringa. Ad esempio: TimeZone = "Pacific Standard Time".
|
AzureSqlProtectionPolicy
Object
Criteri di backup specifici del carico di lavoro SQL di Azure.
Nome |
Tipo |
Descrizione |
backupManagementType
|
string:
AzureSql
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
protectedItemsCount
|
integer
(int32)
|
Numero di elementi associati a questo criterio.
|
resourceGuardOperationRequests
|
string[]
|
Richieste di operazioni di ResourceGuard
|
retentionPolicy
|
RetentionPolicy:
|
Dettagli dei criteri di conservazione.
|
AzureVmWorkloadProtectionPolicy
Object
Criteri di backup specifici del carico di lavoro della macchina virtuale di Azure (Mercury).
Nome |
Tipo |
Descrizione |
backupManagementType
|
string:
AzureWorkload
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
makePolicyConsistent
|
boolean
|
Correggere l'incoerenza dei criteri
|
protectedItemsCount
|
integer
(int32)
|
Numero di elementi associati a questo criterio.
|
resourceGuardOperationRequests
|
string[]
|
Richieste di operazioni di ResourceGuard
|
settings
|
Settings
|
Impostazioni comuni per la gestione dei backup
|
subProtectionPolicy
|
SubProtectionPolicy[]
|
Elenco dei criteri di protezione secondaria che includono pianificazione e conservazione
|
workLoadType
|
WorkloadType
|
Tipo di carico di lavoro per la gestione dei backup
|
CloudError
Object
Risposta di errore del servizio Istanza contenitore.
CloudErrorBody
Object
Risposta di errore del servizio Istanza contenitore.
Nome |
Tipo |
Descrizione |
additionalInfo
|
ErrorAdditionalInfo[]
|
Informazioni aggiuntive sull'errore.
|
code
|
string
|
Identificatore dell'errore. I codici sono invarianti e devono essere utilizzati a livello di codice.
|
details
|
CloudErrorBody[]
|
Elenco di dettagli aggiuntivi sull'errore.
|
message
|
string
|
Messaggio che descrive l'errore, destinato a essere adatto per la visualizzazione in un'interfaccia utente.
|
target
|
string
|
Destinazione dell'errore specifico. Ad esempio, il nome della proprietà in errore.
|
Object
Formato di conservazione giornaliero.
Nome |
Tipo |
Descrizione |
daysOfTheMonth
|
Day[]
|
Elenco dei giorni del mese.
|
DailyRetentionSchedule
Object
Pianificazione della conservazione giornaliera.
Nome |
Tipo |
Descrizione |
retentionDuration
|
RetentionDuration
|
Durata conservazione dei criteri di conservazione.
|
retentionTimes
|
string[]
(date-time)
|
Tempi di conservazione dei criteri di conservazione.
|
DailySchedule
Object
Nome |
Tipo |
Descrizione |
scheduleRunTimes
|
string[]
(date-time)
|
Elenco di orari del giorno in cui deve essere eseguita questa pianificazione.
|
Day
Object
Giorno della settimana.
Nome |
Tipo |
Descrizione |
date
|
integer
(int32)
|
Data del mese
|
isLast
|
boolean
|
Indica se Date è l'ultima data del mese
|
DayOfWeek
Enumerazione
Valore |
Descrizione |
Sunday
|
|
Monday
|
|
Tuesday
|
|
Wednesday
|
|
Thursday
|
|
Friday
|
|
Saturday
|
|
ErrorAdditionalInfo
Object
Informazioni aggiuntive sull'errore di gestione delle risorse.
Nome |
Tipo |
Descrizione |
info
|
object
|
Informazioni aggiuntive.
|
type
|
string
|
Tipo di informazioni aggiuntive.
|
GenericProtectionPolicy
Object
Criteri di backup specifici del carico di lavoro della macchina virtuale di Azure (Mercury).
Nome |
Tipo |
Descrizione |
backupManagementType
|
string:
GenericProtectionPolicy
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
fabricName
|
string
|
Nome dell'infrastruttura di questo criterio.
|
protectedItemsCount
|
integer
(int32)
|
Numero di elementi associati a questo criterio.
|
resourceGuardOperationRequests
|
string[]
|
Richieste di operazioni di ResourceGuard
|
subProtectionPolicy
|
SubProtectionPolicy[]
|
Elenco dei criteri di protezione secondaria che includono pianificazione e conservazione
|
timeZone
|
string
|
Input facoltativo timeZone come stringa. Ad esempio: TimeZone = "Pacific Standard Time".
|
HourlySchedule
Object
Nome |
Tipo |
Descrizione |
interval
|
integer
(int32)
|
Intervallo in cui deve essere attivato il backup. Per ogni ora il valore può essere 4/6/8/12
|
scheduleWindowDuration
|
integer
(int32)
|
Per specificare la durata della finestra di backup
|
scheduleWindowStartTime
|
string
(date-time)
|
Per specificare l'ora di inizio della finestra di backup
|
IAASVMPolicyType
Enumerazione
Valore |
Descrizione |
Invalid
|
|
V1
|
|
V2
|
|
IaasVMSnapshotConsistencyType
Enumerazione
Valore |
Descrizione |
OnlyCrashConsistent
|
|
InstantRPAdditionalDetails
Object
Nome |
Tipo |
Descrizione |
azureBackupRGNamePrefix
|
string
|
|
azureBackupRGNameSuffix
|
string
|
|
LogSchedulePolicy
Object
Pianificazione dei criteri di log.
Nome |
Tipo |
Descrizione |
scheduleFrequencyInMins
|
integer
(int32)
|
Frequenza dell'operazione di pianificazione log di questo criterio in pochi minuti.
|
schedulePolicyType
|
string:
LogSchedulePolicy
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
LongTermRetentionPolicy
Object
Criteri di conservazione a lungo termine.
Nome |
Tipo |
Descrizione |
dailySchedule
|
DailyRetentionSchedule
|
Pianificazione giornaliera della conservazione dei criteri di protezione.
|
monthlySchedule
|
MonthlyRetentionSchedule
|
Pianificazione della conservazione mensile dei criteri di protezione.
|
retentionPolicyType
|
string:
LongTermRetentionPolicy
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
weeklySchedule
|
WeeklyRetentionSchedule
|
Pianificazione della conservazione settimanale dei criteri di protezione.
|
yearlySchedule
|
YearlyRetentionSchedule
|
Pianificazione della conservazione annuale dei criteri di protezione.
|
LongTermSchedulePolicy
Object
Pianificazione dei criteri a lungo termine.
Nome |
Tipo |
Descrizione |
schedulePolicyType
|
string:
LongTermSchedulePolicy
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
MabProtectionPolicy
Object
Criteri di backup specifici del contenitore Mab.
Nome |
Tipo |
Descrizione |
backupManagementType
|
string:
MAB
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
protectedItemsCount
|
integer
(int32)
|
Numero di elementi associati a questo criterio.
|
resourceGuardOperationRequests
|
string[]
|
Richieste di operazioni di ResourceGuard
|
retentionPolicy
|
RetentionPolicy:
|
Dettagli dei criteri di conservazione.
|
schedulePolicy
|
SchedulePolicy:
|
Pianificazione del backup dei criteri di backup.
|
MonthlyRetentionSchedule
Object
Pianificazione della conservazione mensile.
Nome |
Tipo |
Descrizione |
retentionDuration
|
RetentionDuration
|
Durata conservazione dei criteri di conservazione.
|
retentionScheduleDaily
|
DailyRetentionFormat
|
Formato di conservazione giornaliero per i criteri di conservazione mensili.
|
retentionScheduleFormatType
|
RetentionScheduleFormat
|
Tipo di formato della pianificazione della conservazione per i criteri di conservazione mensili.
|
retentionScheduleWeekly
|
WeeklyRetentionFormat
|
Formato di conservazione settimanale per i criteri di conservazione mensili.
|
retentionTimes
|
string[]
(date-time)
|
Tempi di conservazione dei criteri di conservazione.
|
MonthOfYear
Enumerazione
Elenco dei mesi dell'anno di criteri di conservazione annuale.
Valore |
Descrizione |
Invalid
|
|
January
|
|
February
|
|
March
|
|
April
|
|
May
|
|
June
|
|
July
|
|
August
|
|
September
|
|
October
|
|
November
|
|
December
|
|
PolicyType
Enumerazione
Tipo di criteri di backup
Valore |
Descrizione |
Invalid
|
|
Full
|
|
Differential
|
|
Log
|
|
CopyOnlyFull
|
|
Incremental
|
|
SnapshotFull
|
|
SnapshotCopyOnlyFull
|
|
ProtectionPolicyResource
Object
Classe di base per i criteri di backup. I criteri di backup specifici del carico di lavoro derivano da questa classe.
Nome |
Tipo |
Descrizione |
eTag
|
string
|
ETag facoltativo.
|
id
|
string
|
L'ID risorsa rappresenta il percorso completo della risorsa.
|
location
|
string
|
Percorso della risorsa.
|
name
|
string
|
Nome della risorsa associato alla risorsa.
|
properties
|
ProtectionPolicy:
|
Proprietà ProtectionPolicyResource
|
tags
|
object
|
Tag di risorsa.
|
type
|
string
|
Tipo di risorsa rappresenta il percorso completo del modulo Spazio dei nomi/ResourceType/ResourceType/...
|
RetentionDuration
Object
Durata conservazione.
Nome |
Tipo |
Descrizione |
count
|
integer
(int32)
|
Numero di tipi di durata. La durata della conservazione viene ottenuta con il conteggio dei tempi di conteggio del tipo di durata.
Ad esempio, quando Count = 3 e DurationType = Weeks, la durata della conservazione sarà di tre settimane.
|
durationType
|
RetentionDurationType
|
Tipo di durata di conservazione dei criteri di conservazione.
|
RetentionDurationType
Enumerazione
Tipo di durata di conservazione: giorni/settimane/mesi/anni Usati solo se TieringMode è impostato su TierAfter
Valore |
Descrizione |
Invalid
|
|
Days
|
|
Weeks
|
|
Months
|
|
Years
|
|
Enumerazione
Tipo di formato della pianificazione della conservazione per i criteri di conservazione mensili.
Valore |
Descrizione |
Invalid
|
|
Daily
|
|
Weekly
|
|
ScheduleRunType
Enumerazione
Frequenza dell'operazione di pianificazione di questo criterio.
Valore |
Descrizione |
Invalid
|
|
Daily
|
|
Weekly
|
|
Hourly
|
|
Settings
Object
Campo impostazioni comuni per la gestione del backup
Nome |
Tipo |
Descrizione |
isCompression
|
boolean
|
Flag di compressione del carico di lavoro. Questa operazione è stata aggiunta in modo che "isSqlCompression" venga deprecata dopo l'aggiornamento dei client per considerare questo flag.
|
issqlcompression
|
boolean
|
Flag di compressione SQL
|
timeZone
|
string
|
Input facoltativo timeZone come stringa. Ad esempio: TimeZone = "Pacific Standard Time".
|
SimpleRetentionPolicy
Object
Conservazione dei criteri semplice.
Nome |
Tipo |
Descrizione |
retentionDuration
|
RetentionDuration
|
Durata di conservazione dei criteri di protezione.
|
retentionPolicyType
|
string:
SimpleRetentionPolicy
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
SimpleSchedulePolicy
Object
Pianificazione dei criteri semplice.
Nome |
Tipo |
Descrizione |
hourlySchedule
|
HourlySchedule
|
Pianificazione oraria di questo criterio
|
schedulePolicyType
|
string:
SimpleSchedulePolicy
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
scheduleRunDays
|
DayOfWeek[]
|
Elenco di giorni della settimana da eseguire questa pianificazione.
|
scheduleRunFrequency
|
ScheduleRunType
|
Frequenza dell'operazione di pianificazione di questo criterio.
|
scheduleRunTimes
|
string[]
(date-time)
|
Elenco di orari del giorno in cui deve essere eseguita questa pianificazione.
|
scheduleWeeklyFrequency
|
integer
(int32)
|
A ogni numero di settimane questa pianificazione deve essere eseguita.
|
SimpleSchedulePolicyV2
Object
Pianificazione dei criteri V2 per IaaS che supporta i backup orari.
Nome |
Tipo |
Descrizione |
dailySchedule
|
DailySchedule
|
Pianificazione giornaliera di questo criterio
|
hourlySchedule
|
HourlySchedule
|
pianificazione oraria di questo criterio
|
schedulePolicyType
|
string:
SimpleSchedulePolicyV2
|
Questa proprietà verrà utilizzata come discriminante per decidere i tipi specifici nella catena polimorfica di tipi.
|
scheduleRunFrequency
|
ScheduleRunType
|
Frequenza dell'operazione di pianificazione di questo criterio.
|
weeklySchedule
|
WeeklySchedule
|
Pianificazione settimanale di questo criterio
|
SnapshotBackupAdditionalDetails
Object
Campi correlati a Backup snapshot per WorkloadType SaPHanaSystem
Nome |
Tipo |
Descrizione |
instantRPDetails
|
string
|
|
instantRpRetentionRangeInDays
|
integer
(int32)
|
|
userAssignedManagedIdentityDetails
|
UserAssignedManagedIdentityDetails
|
Dettagli identità gestita assegnata dall'utente
|
SubProtectionPolicy
Object
Criteri di protezione secondaria che includono pianificazione e conservazione
Nome |
Tipo |
Descrizione |
policyType
|
PolicyType
|
Tipo di criteri di backup
|
retentionPolicy
|
RetentionPolicy:
|
Criteri di conservazione con i dettagli sugli intervalli di conservazione delle copie di backup.
|
schedulePolicy
|
SchedulePolicy:
|
Pianificazione del backup specificata come parte dei criteri di backup.
|
snapshotBackupAdditionalDetails
|
SnapshotBackupAdditionalDetails
|
Campi correlati a Backup snapshot per WorkloadType SaPHanaSystem
|
tieringPolicy
|
<string,
TieringPolicy>
|
Criteri di suddivisione in livelli per spostare automaticamente gli indirizzi IP in un altro livello.
La chiave è livello di destinazione, definita nell'enumerazione RecoveryPointTierType.
I criteri di suddivisione in livelli specificano i criteri per spostare rp nel livello di destinazione.
|
TieringMode
Enumerazione
Modalità di suddivisione in livelli per controllare la suddivisione automatica in livelli dei punti di ripristino. I valori supportati sono:
- TierRecommended: livelli per tutti i punti di ripristino consigliati per la suddivisione in livelli
- TierAfter: livelli tutti i punti di ripristino dopo un periodo fisso, come specificato in duration + durationType di seguito.
- DoNotTier: non eseguire il livello dei punti di ripristino
Valore |
Descrizione |
Invalid
|
|
TierRecommended
|
|
TierAfter
|
|
DoNotTier
|
|
TieringPolicy
Object
Criteri di suddivisione in livelli per un livello di destinazione.
Se i criteri non vengono specificati per un determinato livello di destinazione, il servizio mantiene i criteri di suddivisione in livelli configurati esistenti per tale livello
Nome |
Tipo |
Descrizione |
duration
|
integer
(int32)
|
Numero di giorni/settimane/mesi/anni per conservare i backup nel livello corrente prima della suddivisione in livelli.
Usato solo se TieringMode è impostato su TierAfter
|
durationType
|
RetentionDurationType
|
Tipo di durata di conservazione: giorni/settimane/mesi/anni Usati solo se TieringMode è impostato su TierAfter
|
tieringMode
|
TieringMode
|
Modalità di suddivisione in livelli per controllare la suddivisione automatica in livelli dei punti di ripristino. I valori supportati sono:
- TierRecommended: livelli per tutti i punti di ripristino consigliati per la suddivisione in livelli
- TierAfter: livelli tutti i punti di ripristino dopo un periodo fisso, come specificato in duration + durationType di seguito.
- DoNotTier: non eseguire il livello dei punti di ripristino
|
UserAssignedIdentityProperties
Object
Proprietà dell'identità gestita assegnata dall'utente
Nome |
Tipo |
Descrizione |
clientId
|
string
|
ID client dell'identità assegnata.
|
principalId
|
string
|
ID entità dell'identità assegnata.
|
UserAssignedManagedIdentityDetails
Object
Dettagli identità gestita assegnata dall'utente
Nome |
Tipo |
Descrizione |
identityArmId
|
string
|
ID ARM dell'identità assegnata.
|
identityName
|
string
|
Nome dell'identità assegnata.
|
userAssignedIdentityProperties
|
UserAssignedIdentityProperties
|
Proprietà dell'identità gestita assegnata dall'utente
|
VaultRetentionPolicy
Object
Criteri di conservazione dell'insieme di credenziali per AzureFileShare
Nome |
Tipo |
Descrizione |
snapshotRetentionInDays
|
integer
(int32)
|
|
vaultRetention
|
RetentionPolicy:
|
Classe di base per i criteri di conservazione.
|
Object
Formato di conservazione settimanale.
Nome |
Tipo |
Descrizione |
daysOfTheWeek
|
DayOfWeek[]
|
Elenco dei giorni della settimana.
|
weeksOfTheMonth
|
WeekOfMonth[]
|
Elenco delle settimane del mese.
|
WeeklyRetentionSchedule
Object
Pianificazione di conservazione settimanale.
Nome |
Tipo |
Descrizione |
daysOfTheWeek
|
DayOfWeek[]
|
Elenco dei giorni della settimana per i criteri di conservazione settimanali.
|
retentionDuration
|
RetentionDuration
|
Durata conservazione dei criteri di conservazione.
|
retentionTimes
|
string[]
(date-time)
|
Tempi di conservazione dei criteri di conservazione.
|
WeeklySchedule
Object
Nome |
Tipo |
Descrizione |
scheduleRunDays
|
DayOfWeek[]
|
|
scheduleRunTimes
|
string[]
(date-time)
|
Elenco di orari del giorno in cui deve essere eseguita questa pianificazione.
|
WeekOfMonth
Enumerazione
Elenco delle settimane del mese.
Valore |
Descrizione |
First
|
|
Second
|
|
Third
|
|
Fourth
|
|
Last
|
|
Invalid
|
|
WorkloadType
Enumerazione
Tipo di carico di lavoro per la gestione dei backup
Valore |
Descrizione |
Invalid
|
|
VM
|
|
FileFolder
|
|
AzureSqlDb
|
|
SQLDB
|
|
Exchange
|
|
Sharepoint
|
|
VMwareVM
|
|
SystemState
|
|
Client
|
|
GenericDataSource
|
|
SQLDataBase
|
|
AzureFileShare
|
|
SAPHanaDatabase
|
|
SAPAseDatabase
|
|
SAPHanaDBInstance
|
|
YearlyRetentionSchedule
Object
Pianificazione della conservazione annuale.
Nome |
Tipo |
Descrizione |
monthsOfYear
|
MonthOfYear[]
|
Elenco dei mesi dell'anno di criteri di conservazione annuale.
|
retentionDuration
|
RetentionDuration
|
Durata conservazione dei criteri di conservazione.
|
retentionScheduleDaily
|
DailyRetentionFormat
|
Formato di conservazione giornaliero per i criteri di conservazione annuali.
|
retentionScheduleFormatType
|
RetentionScheduleFormat
|
Formato di pianificazione della conservazione per i criteri di conservazione annuali.
|
retentionScheduleWeekly
|
WeeklyRetentionFormat
|
Formato di conservazione settimanale per i criteri di conservazione annuali.
|
retentionTimes
|
string[]
(date-time)
|
Tempi di conservazione dei criteri di conservazione.
|