0
# Backup Policies
1
2
Comprehensive backup policy management for Azure Recovery Services including creation, modification, deletion, and assignment of backup policies. Supports various workload types including Azure VMs, SQL databases, file shares, and on-premises workloads with flexible scheduling and retention options.
3
4
## Capabilities
5
6
### Policy Management Operations
7
8
Core operations for managing backup policies with full CRUD functionality and policy assignment capabilities.
9
10
```python { .api }
11
class BackupPoliciesOperations:
12
def list(self, resource_group_name: str, vault_name: str, **kwargs) -> Iterable[ProtectionPolicyResource]:
13
"""
14
List all backup policies in a Recovery Services vault.
15
16
Parameters:
17
- resource_group_name: Resource group containing the vault
18
- vault_name: Recovery Services vault name
19
- kwargs: Additional query parameters (filter, etc.)
20
21
Returns:
22
Iterable of ProtectionPolicyResource objects
23
"""
24
25
class ProtectionPoliciesOperations:
26
def get(self, resource_group_name: str, vault_name: str, policy_name: str, **kwargs) -> ProtectionPolicyResource:
27
"""
28
Get a specific backup policy by name.
29
30
Parameters:
31
- resource_group_name: Resource group containing the vault
32
- vault_name: Recovery Services vault name
33
- policy_name: Name of the backup policy
34
- kwargs: Additional options
35
36
Returns:
37
ProtectionPolicyResource object
38
"""
39
40
def create_or_update(
41
self,
42
resource_group_name: str,
43
vault_name: str,
44
policy_name: str,
45
parameters: ProtectionPolicyResource,
46
**kwargs
47
) -> ProtectionPolicyResource:
48
"""
49
Create or update a backup policy.
50
51
Parameters:
52
- resource_group_name: Resource group containing the vault
53
- vault_name: Recovery Services vault name
54
- policy_name: Name for the backup policy
55
- parameters: Policy configuration details
56
- kwargs: Additional options
57
58
Returns:
59
Created or updated ProtectionPolicyResource
60
"""
61
62
def delete(self, resource_group_name: str, vault_name: str, policy_name: str, **kwargs) -> None:
63
"""
64
Delete a backup policy.
65
66
Parameters:
67
- resource_group_name: Resource group containing the vault
68
- vault_name: Recovery Services vault name
69
- policy_name: Name of the policy to delete
70
- kwargs: Additional options
71
"""
72
```
73
74
Usage example:
75
76
```python
77
# List all policies
78
policies = client.backup_policies.list("my-rg", "my-vault")
79
for policy in policies:
80
print(f"Policy: {policy.name}, Type: {policy.properties.backup_management_type}")
81
82
# Get specific policy
83
vm_policy = client.protection_policies.get("my-rg", "my-vault", "DefaultPolicy")
84
print(f"Schedule: {vm_policy.properties.schedule_policy}")
85
86
# Create new VM policy
87
from azure.mgmt.recoveryservicesbackup.activestamp.models import (
88
ProtectionPolicyResource,
89
AzureIaaSVMProtectionPolicy,
90
SimpleSchedulePolicy,
91
LongTermRetentionPolicy
92
)
93
94
new_policy = ProtectionPolicyResource(
95
properties=AzureIaaSVMProtectionPolicy(
96
backup_management_type="AzureIaasVM",
97
schedule_policy=SimpleSchedulePolicy(
98
schedule_run_frequency="Daily",
99
schedule_run_times=["22:00"]
100
),
101
retention_policy=LongTermRetentionPolicy(
102
daily_schedule={
103
"retention_times": ["22:00"],
104
"retention_duration": {
105
"count": 30,
106
"duration_type": "Days"
107
}
108
}
109
)
110
)
111
)
112
113
created_policy = client.protection_policies.create_or_update(
114
"my-rg", "my-vault", "MyCustomPolicy", new_policy
115
)
116
```
117
118
### Protection Policy Operations
119
120
Advanced policy operations including operation result tracking and status monitoring.
121
122
```python { .api }
123
class ProtectionPoliciesOperations:
124
def list(self, resource_group_name: str, vault_name: str, **kwargs) -> Iterable[ProtectionPolicyResource]:
125
"""List protection policies with advanced filtering options."""
126
127
def get(self, resource_group_name: str, vault_name: str, policy_name: str, **kwargs) -> ProtectionPolicyResource:
128
"""Get protection policy with detailed information."""
129
130
def create_or_update(
131
self,
132
resource_group_name: str,
133
vault_name: str,
134
policy_name: str,
135
parameters: ProtectionPolicyResource,
136
**kwargs
137
) -> ProtectionPolicyResource:
138
"""Create or update protection policy with validation."""
139
140
def delete(self, resource_group_name: str, vault_name: str, policy_name: str, **kwargs) -> None:
141
"""Delete protection policy with dependency checks."""
142
143
class ProtectionPolicyOperationResultsOperations:
144
def get(self, resource_group_name: str, vault_name: str, policy_name: str, operation_id: str, **kwargs) -> ProtectionPolicyResource:
145
"""Get operation result for policy operations."""
146
147
class ProtectionPolicyOperationStatusesOperations:
148
def get(self, resource_group_name: str, vault_name: str, policy_name: str, operation_id: str, **kwargs) -> OperationStatus:
149
"""Get operation status for policy operations."""
150
```
151
152
## Policy Types
153
154
### Azure IaaS VM Policies
155
156
Backup policies specifically designed for Azure virtual machines with flexible scheduling and retention options.
157
158
```python { .api }
159
class AzureIaaSVMProtectionPolicy:
160
def __init__(
161
self,
162
backup_management_type: str = "AzureIaasVM",
163
schedule_policy: Optional[SchedulePolicy] = None,
164
retention_policy: Optional[RetentionPolicy] = None,
165
instant_rp_retention_range_in_days: Optional[int] = None,
166
time_zone: Optional[str] = None,
167
policy_type: str = "V2",
168
**kwargs
169
):
170
"""
171
Azure IaaS VM protection policy.
172
173
Parameters:
174
- backup_management_type: Always "AzureIaasVM"
175
- schedule_policy: Backup schedule configuration
176
- retention_policy: Backup retention configuration
177
- instant_rp_retention_range_in_days: Instant recovery point retention (1-30 days)
178
- time_zone: Time zone for schedule (e.g., "UTC", "Eastern Standard Time")
179
- policy_type: Policy version ("V1" or "V2")
180
"""
181
182
backup_management_type: str
183
schedule_policy: Optional[SchedulePolicy]
184
retention_policy: Optional[RetentionPolicy]
185
instant_rp_retention_range_in_days: Optional[int]
186
time_zone: Optional[str]
187
policy_type: str
188
```
189
190
### Azure SQL Database Policies
191
192
Specialized policies for SQL database backup with transaction log backup support.
193
194
```python { .api }
195
class AzureSqlProtectionPolicy:
196
def __init__(
197
self,
198
backup_management_type: str = "AzureSql",
199
retention_policy: Optional[RetentionPolicy] = None,
200
**kwargs
201
):
202
"""
203
Azure SQL database protection policy.
204
205
Parameters:
206
- backup_management_type: Always "AzureSql"
207
- retention_policy: Backup retention configuration
208
"""
209
210
backup_management_type: str
211
retention_policy: Optional[RetentionPolicy]
212
```
213
214
### Azure File Share Policies
215
216
Policies for Azure file share backup with snapshot-based protection.
217
218
```python { .api }
219
class AzureFileShareProtectionPolicy:
220
def __init__(
221
self,
222
backup_management_type: str = "AzureStorage",
223
schedule_policy: Optional[SchedulePolicy] = None,
224
retention_policy: Optional[RetentionPolicy] = None,
225
time_zone: Optional[str] = None,
226
work_load_type: str = "AzureFileShare",
227
**kwargs
228
):
229
"""
230
Azure file share protection policy.
231
232
Parameters:
233
- backup_management_type: Always "AzureStorage"
234
- schedule_policy: Backup schedule configuration
235
- retention_policy: Backup retention configuration
236
- time_zone: Time zone for schedule
237
- work_load_type: Always "AzureFileShare"
238
"""
239
240
backup_management_type: str
241
schedule_policy: Optional[SchedulePolicy]
242
retention_policy: Optional[RetentionPolicy]
243
time_zone: Optional[str]
244
work_load_type: str
245
```
246
247
### Azure VM Workload Policies
248
249
Comprehensive policies for workloads running inside Azure VMs (SQL Server, SAP HANA, etc.).
250
251
```python { .api }
252
class AzureVmWorkloadProtectionPolicy:
253
def __init__(
254
self,
255
backup_management_type: str = "AzureWorkload",
256
work_load_type: Optional[str] = None,
257
settings: Optional[Settings] = None,
258
sub_protection_policy: Optional[List[SubProtectionPolicy]] = None,
259
make_policy_consistent: Optional[bool] = None,
260
**kwargs
261
):
262
"""
263
Azure VM workload protection policy.
264
265
Parameters:
266
- backup_management_type: Always "AzureWorkload"
267
- work_load_type: Workload type ("SQLDataBase", "SAPHanaDatabase", etc.)
268
- settings: Workload-specific settings
269
- sub_protection_policy: List of sub-policies for different backup types
270
- make_policy_consistent: Ensure policy consistency across workloads
271
"""
272
273
backup_management_type: str
274
work_load_type: Optional[str]
275
settings: Optional[Settings]
276
sub_protection_policy: Optional[List[SubProtectionPolicy]]
277
make_policy_consistent: Optional[bool]
278
```
279
280
## Schedule Policies
281
282
### Simple Schedule Policy
283
284
Basic scheduling for daily, weekly backup operations.
285
286
```python { .api }
287
class SimpleSchedulePolicy:
288
def __init__(
289
self,
290
schedule_run_frequency: str,
291
schedule_run_times: Optional[List[str]] = None,
292
schedule_run_days: Optional[List[str]] = None,
293
schedule_weekly_frequency: Optional[int] = None,
294
**kwargs
295
):
296
"""
297
Simple backup schedule policy.
298
299
Parameters:
300
- schedule_run_frequency: "Daily", "Weekly"
301
- schedule_run_times: List of times in HH:MM format (e.g., ["22:00"])
302
- schedule_run_days: Days for weekly schedule (e.g., ["Sunday", "Wednesday"])
303
- schedule_weekly_frequency: Week interval for weekly schedules
304
"""
305
306
schedule_run_frequency: str
307
schedule_run_times: Optional[List[str]]
308
schedule_run_days: Optional[List[str]]
309
schedule_weekly_frequency: Optional[int]
310
```
311
312
### Log Schedule Policy
313
314
Specialized scheduling for transaction log backups in workload scenarios.
315
316
```python { .api }
317
class LogSchedulePolicy:
318
def __init__(
319
self,
320
schedule_frequency_in_mins: Optional[int] = None,
321
**kwargs
322
):
323
"""
324
Log backup schedule policy.
325
326
Parameters:
327
- schedule_frequency_in_mins: Frequency in minutes (15, 30, 60, 120, 240, 480, 720, 1440)
328
"""
329
330
schedule_frequency_in_mins: Optional[int]
331
```
332
333
## Retention Policies
334
335
### Long Term Retention Policy
336
337
Comprehensive retention policy supporting daily, weekly, monthly, and yearly retention cycles.
338
339
```python { .api }
340
class LongTermRetentionPolicy:
341
def __init__(
342
self,
343
daily_schedule: Optional[DailyRetentionSchedule] = None,
344
weekly_schedule: Optional[WeeklyRetentionSchedule] = None,
345
monthly_schedule: Optional[MonthlyRetentionSchedule] = None,
346
yearly_schedule: Optional[YearlyRetentionSchedule] = None,
347
**kwargs
348
):
349
"""
350
Long-term retention policy configuration.
351
352
Parameters:
353
- daily_schedule: Daily retention settings
354
- weekly_schedule: Weekly retention settings
355
- monthly_schedule: Monthly retention settings
356
- yearly_schedule: Yearly retention settings
357
"""
358
359
daily_schedule: Optional[DailyRetentionSchedule]
360
weekly_schedule: Optional[WeeklyRetentionSchedule]
361
monthly_schedule: Optional[MonthlyRetentionSchedule]
362
yearly_schedule: Optional[YearlyRetentionSchedule]
363
364
class DailyRetentionSchedule:
365
retention_times: Optional[List[str]]
366
retention_duration: Optional[RetentionDuration]
367
368
class WeeklyRetentionSchedule:
369
days_of_the_week: Optional[List[str]]
370
retention_times: Optional[List[str]]
371
retention_duration: Optional[RetentionDuration]
372
373
class MonthlyRetentionSchedule:
374
retention_schedule_format_type: Optional[str] # "Daily" or "Weekly"
375
retention_schedule_daily: Optional[DailyRetentionFormat]
376
retention_schedule_weekly: Optional[WeeklyRetentionFormat]
377
retention_times: Optional[List[str]]
378
retention_duration: Optional[RetentionDuration]
379
380
class YearlyRetentionSchedule:
381
retention_schedule_format_type: Optional[str] # "Daily" or "Weekly"
382
months_of_year: Optional[List[str]]
383
retention_schedule_daily: Optional[DailyRetentionFormat]
384
retention_schedule_weekly: Optional[WeeklyRetentionFormat]
385
retention_times: Optional[List[str]]
386
retention_duration: Optional[RetentionDuration]
387
388
class RetentionDuration:
389
count: Optional[int]
390
duration_type: Optional[str] # "Days", "Weeks", "Months", "Years"
391
```
392
393
### Simple Retention Policy
394
395
Basic retention policy for straightforward backup retention requirements.
396
397
```python { .api }
398
class SimpleRetentionPolicy:
399
def __init__(
400
self,
401
retention_duration: Optional[RetentionDuration] = None,
402
**kwargs
403
):
404
"""Simple retention policy with single duration."""
405
406
retention_duration: Optional[RetentionDuration]
407
```
408
409
## Usage Examples
410
411
### Create VM Backup Policy
412
413
```python
414
from azure.mgmt.recoveryservicesbackup.activestamp.models import (
415
ProtectionPolicyResource,
416
AzureIaaSVMProtectionPolicy,
417
SimpleSchedulePolicy,
418
LongTermRetentionPolicy,
419
DailyRetentionSchedule,
420
WeeklyRetentionSchedule,
421
RetentionDuration
422
)
423
424
# Define retention schedules
425
daily_retention = DailyRetentionSchedule(
426
retention_times=["02:00"],
427
retention_duration=RetentionDuration(count=30, duration_type="Days")
428
)
429
430
weekly_retention = WeeklyRetentionSchedule(
431
days_of_the_week=["Sunday"],
432
retention_times=["02:00"],
433
retention_duration=RetentionDuration(count=12, duration_type="Weeks")
434
)
435
436
# Create VM policy
437
vm_policy = ProtectionPolicyResource(
438
properties=AzureIaaSVMProtectionPolicy(
439
backup_management_type="AzureIaasVM",
440
schedule_policy=SimpleSchedulePolicy(
441
schedule_run_frequency="Daily",
442
schedule_run_times=["02:00"]
443
),
444
retention_policy=LongTermRetentionPolicy(
445
daily_schedule=daily_retention,
446
weekly_schedule=weekly_retention
447
),
448
instant_rp_retention_range_in_days=2,
449
time_zone="UTC"
450
)
451
)
452
453
# Create the policy
454
result = client.protection_policies.create_or_update(
455
"my-rg", "my-vault", "VMDailyPolicy", vm_policy
456
)
457
```
458
459
### Create SQL Database Policy
460
461
```python
462
from azure.mgmt.recoveryservicesbackup.activestamp.models import (
463
AzureVmWorkloadProtectionPolicy,
464
SubProtectionPolicy,
465
LogSchedulePolicy,
466
SimpleRetentionPolicy
467
)
468
469
# SQL database workload policy
470
sql_policy = ProtectionPolicyResource(
471
properties=AzureVmWorkloadProtectionPolicy(
472
backup_management_type="AzureWorkload",
473
work_load_type="SQLDataBase",
474
sub_protection_policy=[
475
SubProtectionPolicy(
476
policy_type="Full",
477
schedule_policy=SimpleSchedulePolicy(
478
schedule_run_frequency="Weekly",
479
schedule_run_times=["02:00"],
480
schedule_run_days=["Sunday"]
481
),
482
retention_policy=LongTermRetentionPolicy(
483
weekly_schedule=WeeklyRetentionSchedule(
484
days_of_the_week=["Sunday"],
485
retention_times=["02:00"],
486
retention_duration=RetentionDuration(count=52, duration_type="Weeks")
487
)
488
)
489
),
490
SubProtectionPolicy(
491
policy_type="Log",
492
schedule_policy=LogSchedulePolicy(
493
schedule_frequency_in_mins=15
494
),
495
retention_policy=SimpleRetentionPolicy(
496
retention_duration=RetentionDuration(count=7, duration_type="Days")
497
)
498
)
499
]
500
)
501
)
502
503
result = client.protection_policies.create_or_update(
504
"my-rg", "my-vault", "SQLDatabasePolicy", sql_policy
505
)
506
```