|
2 | 2 | title: Back up Azure Database for PostgreSQL - flexible server using Azure PowerShell
|
3 | 3 | description: Learn how to back up Azure Database for PostgreSQL - flexible server using Azure PowerShell.
|
4 | 4 | ms.topic: how-to
|
5 |
| -ms.date: 02/18/2025 |
| 5 | +ms.date: 02/28/2025 |
6 | 6 | ms.custom: devx-track-azurepowershell, ignite-2024
|
7 | 7 | ms.service: azure-backup
|
8 | 8 | author: jyothisuri
|
@@ -44,154 +44,9 @@ Type : Microsoft.DataProtection/backupVaults
|
44 | 44 |
|
45 | 45 | ```
|
46 | 46 |
|
47 |
| -## Create a backup policy |
48 |
| - |
49 |
| -After the vault is created, let's create a Backup policy to protect Azure PostgreSQL – Flexible Server databases. |
50 |
| - |
51 |
| -### Understand PostgreSQL – Flexible server backup policy |
52 |
| - |
53 |
| -Disk backup offers multiple backups per day, and blob backup is a continuous backup with no trigger. Now, let's understand the backup policy object for PostgreSQL – Flexible Server. |
54 |
| - |
55 |
| -- PolicyRule |
56 |
| - - BackupRule |
57 |
| - - BackupParameter |
58 |
| - - BackupType (A full database backup in this scenario) |
59 |
| - - Initial Datastore (Where the backups land initially) |
60 |
| - - Trigger (How the backup is triggered) |
61 |
| - - Schedule based |
62 |
| - - Default tagging criteria (a default 'tag' for all the scheduled backups. This tag links the backups to the retention rule) |
63 |
| - - Default Retention Rule (A rule that is applied to all backups, by default, on the initial datastore) |
64 |
| - |
65 |
| -So, this object defines what type of backups are triggered, how they're triggered (via a schedule), what they're tagged with, where they land (a datastore), and the life cycle of the backup data in a datastore. The default PowerShell object for PostgreSQL – Flexible Server triggers a full backup every week and they reach the vault, where they're stored for *3 months*. |
66 |
| - |
67 |
| -### Retrieve the Policy template |
68 |
| - |
69 |
| -To understand the inner components of a backup policy for Azure PostgreSQL – Flexible server database backup, retrieve the policy template using the [Get-AzDataProtectionPolicyTemplate](/powershell/module/az.dataprotection/get-azdataprotectionpolicytemplate) cmdlet. This cmdlet returns a default policy template for a given datasource type. Use this policy template to create a new policy. |
70 |
| - |
71 |
| -```azurepowershell |
72 |
| -$policyDefn = Get-AzDataProtectionPolicyTemplate -DatasourceType AzureDatabaseForPGFlexServer |
73 |
| -$policyDefn | fl |
74 |
| -
|
75 |
| -DatasourceType : {Microsoft.DBforPostgreSQL/flexibleServers/databases} |
76 |
| -ObjectType : BackupPolicy |
77 |
| -PolicyRule : {BackupWeekly, Default} |
78 |
| -
|
79 |
| -$policyDefn.PolicyRule | fl |
80 |
| -
|
81 |
| -BackupParameter : Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20210701.AzureBackupParams |
82 |
| -BackupParameterObjectType : AzureBackupParams |
83 |
| -DataStoreObjectType : DataStoreInfoBase |
84 |
| -DataStoreType : VaultStore |
85 |
| -Name : BackupWeekly |
86 |
| -ObjectType : AzureBackupRule |
87 |
| -Trigger : Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20210701.ScheduleBasedTriggerCo |
88 |
| - ntext |
89 |
| -TriggerObjectType : ScheduleBasedTriggerContext |
90 |
| -
|
91 |
| -IsDefault : True |
92 |
| -Lifecycle : {Microsoft.Azure.PowerShell.Cmdlets.DataProtection.Models.Api20210701.SourceLifeCycle} |
93 |
| -Name : Default |
94 |
| -ObjectType : AzureRetentionRule |
95 |
| -
|
96 |
| -``` |
97 |
| - |
98 |
| -The policy template consists of a trigger (which decides what triggers the backup) and a lifecycle (which decides when to delete, copy, move the backup). In Azure PostgreSQL – Flexible Server database backup, the default value for trigger is a scheduled **Weekly** trigger (one backup every 7 days) and to retain each backup for **3 months**. |
99 |
| - |
100 |
| -```azurepowershell |
101 |
| -JSON |
102 |
| -$policyDefn.PolicyRule[0].Trigger | fl |
103 |
| -
|
104 |
| -ObjectType : ScheduleBasedTriggerContext |
105 |
| -ScheduleRepeatingTimeInterval : {R/2021-08-22T02:00:00+00:00/P1W} |
106 |
| -ScheduleTimeZone : UTC |
107 |
| -TaggingCriterion : {Default} |
108 |
| -
|
109 |
| -``` |
110 |
| - |
111 |
| -**Default retention rule lifecycle:**: |
112 |
| - |
113 |
| -```json |
114 |
| -$policyDefn.PolicyRule[1].Lifecycle | fl |
115 |
| - |
116 |
| -DeleteAfterDuration : P3M |
117 |
| -DeleteAfterObjectType : AbsoluteDeleteOption |
118 |
| -SourceDataStoreObjectType : DataStoreInfoBase |
119 |
| -SourceDataStoreType : VaultStore |
120 |
| -TargetDataStoreCopySetting : {} |
121 |
| - |
122 |
| -``` |
123 |
| - |
124 |
| -### Modify the policy template |
125 |
| - |
126 |
| -#### Modify the schedule |
127 |
| - |
128 |
| -The default policy template offers a backup once per week. You can modify the schedule for the backup to happen multiple days per week. To modify the schedule, use the [`Edit-AzDataProtectionPolicyTriggerClientObject`](/powershell/module/az.dataprotection/edit-azdataprotectionpolicytriggerclientobject) cmdlet. |
129 |
| - |
130 |
| -The following example modifies the weekly backup to back up happening on every Sunday, Wednesday, and Friday of every week. The schedule date array mentions the dates, and the days of the week of those dates are taken as days of the week. Also, specify that these schedules should repeat every week. So, the schedule interval is *1* and the interval type is *Weekly*. |
131 |
| - |
132 |
| -```azurepowershell |
133 |
| -$schDates = @( |
134 |
| - ( |
135 |
| - (Get-Date -Year 2021 -Month 08 -Day 15 -Hour 22 -Minute 0 -Second 0) |
136 |
| - ), |
137 |
| - ( |
138 |
| - (Get-Date -Year 2021 -Month 08 -Day 18 -Hour 22 -Minute 0 -Second 0) |
139 |
| - ), |
140 |
| - ( |
141 |
| - (Get-Date -Year 2021 -Month 08 -Day 20 -Hour 22 -Minute 0 -Second 0) |
142 |
| - ) |
143 |
| -) |
144 |
| -$trigger = New-AzDataProtectionPolicyTriggerScheduleClientObject -ScheduleDays $schDates -IntervalType Weekly -IntervalCount 1 |
145 |
| -Edit-AzDataProtectionPolicyTriggerClientObject -Schedule $trigger -Policy $policyDefn |
146 |
| -
|
147 |
| -``` |
148 |
| - |
149 |
| -#### Add a new retention rule |
150 |
| - |
151 |
| -The default template has a lifecycle for the initial datastore under the default retention rule. In this scenario, the rule deletes the backup data after *3 months*. Use the [`New-AzDataProtectionRetentionLifeCycleClientObject`](/powershell/module/az.dataprotection/new-azdataprotectionretentionlifecycleclientobject) cmdlet to create new lifecycles and use the [`Edit-AzDataProtectionPolicyRetentionRuleClientObject`](/powershell/module/az.dataprotection/edit-azdataprotectionpolicyretentionruleclientobject) cmdlet to associate them with the new rules or to the existing rules. |
152 |
| - |
153 |
| -The following example creates a new retention rule named *Monthly*, where the first successful backup of every month should be retained in vault for *6 months*. |
154 |
| - |
155 |
| -```azurepowershell |
156 |
| -$VaultLifeCycle = New-AzDataProtectionRetentionLifeCycleClientObject -SourceDataStore VaultStore -SourceRetentionDurationType Months -SourceRetentionDurationCount 6 |
157 |
| -
|
158 |
| -Edit-AzDataProtectionPolicyRetentionRuleClientObject -Policy $policyDefn -Name Monthly -LifeCycles $VaultLifeCycle -IsDefault $false |
159 |
| -
|
160 |
| -``` |
161 |
| - |
162 |
| -#### Add a tag and the relevant criteria |
163 |
| - |
164 |
| -Once a retention rule is created, you've to create a corresponding *tag* in the *Trigger* property of the backup policy. Use the [New-AzDataProtectionPolicyTagCriteriaClientObject](/powershell/module/az.dataprotection/new-azdataprotectionpolicytagcriteriaclientobject) cmdlet to create a new tagging criteria and use the [Edit-AzDataProtectionPolicyTagClientObject](/powershell/module/az.dataprotection/edit-azdataprotectionpolicytagclientobject) cmdlet to update the existing tag or create a new tag. |
165 |
| - |
166 |
| -The following example creates a new tag along with the criteria, the first successful backup of the month. The tag has the same name as the corresponding retention rule to be applied. |
167 |
| - |
168 |
| -In this example, the tag criteria should be named *Monthly*. |
169 |
| - |
170 |
| -```azurepowershell |
171 |
| -$tagCriteria = New-AzDataProtectionPolicyTagCriteriaClientObject -AbsoluteCriteria FirstOfMonth |
172 |
| -Edit-AzDataProtectionPolicyTagClientObject -Policy $policyDefn -Name Monthly -Criteria $tagCriteria |
173 |
| -
|
174 |
| -``` |
175 |
| - |
176 |
| -If the schedule is multiple backups per week (every Sunday, Wednesday, Thursday as specified in the example) and you want to archive the Sunday and Friday backups, then the tagging criteria can be changed as follows, using the [`New-AzDataProtectionPolicyTagCriteriaClientObject`](/powershell/module/az.dataprotection/new-azdataprotectionpolicytagcriteriaclientobject?view=azps-12.3.0&preserve-view=true) cmdlet. |
177 |
| -```azurepowershell |
178 |
| -$tagCriteria = New-AzDataProtectionPolicyTagCriteriaClientObject -DaysOfWeek @("Sunday", "Friday") |
179 |
| -Edit-AzDataProtectionPolicyTagClientObject -Policy $policyDefn -Name Monthly -Criteria $tagCriteria |
180 |
| -
|
181 |
| -``` |
182 |
| - |
183 |
| -### Create a new PostgreSQL - flexible server backup policy |
184 |
| - |
185 |
| -Once the template is modified as per the requirements, use the [New-AzDataProtectionBackupPolicy](/powershell/module/az.dataprotection/new-azdataprotectionbackuppolicy) cmdlet to create a policy using the modified template. |
186 |
| - |
187 |
| -```azurepowershell |
188 |
| -az dataprotection backup-policy create --backup-policy-name FinalOSSPolicy --policy AddedRetentionRuleAndTag.JSON --resource-group testBkpVaultRG --vault-name TestBkpVault |
189 |
| -
|
190 |
| -``` |
191 |
| - |
192 | 47 | ## Configure backup
|
193 | 48 |
|
194 |
| -Once the vault and policy are created, consider the following critical points to protect an Azure PostgreSQL - Flexible Server database: |
| 49 | +Before you configure protection for the database, ensure that you [create a Backup policy](quick-backup-postgresql-flexible-server-powershell.md#create-a-backup-policy). Once the vault and policy are created, consider the following critical points to protect an Azure PostgreSQL - Flexible Server database: |
195 | 50 |
|
196 | 51 | - PostgreSQL – Flexible Server database for protection
|
197 | 52 | - Backup vault to store the backup data
|
|
0 commit comments