Skip to content

Commit a03fb9b

Browse files
authored
Merge pull request #294038 from AbhishekMallick01/Feb-4-2025-PSQLF
Azure Database for PSQL - Flexible Server backup - PLR PR
2 parents 535f03e + 62025d6 commit a03fb9b

30 files changed

+654
-618
lines changed
Lines changed: 16 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
title: Back up Azure Database for PostgreSQL - flexible Server using Azure CLI
3-
description: Learn how to back up Azure Database for PostgreSQL - flexible Server using Azure CLI.
2+
title: Back up Azure Database for PostgreSQL - Flexible Server using Azure CLI
3+
description: Learn how to back up Azure Database for PostgreSQL - Flexible Server using Azure CLI.
44
ms.topic: how-to
5-
ms.date: 02/17/2025
5+
ms.date: 02/28/2025
66
ms.custom: devx-track-azurecli, ignite-2024
77
ms.service: azure-backup
88
author: jyothisuri
@@ -11,8 +11,11 @@ ms.author: jsuri
1111

1212
# Back up Azure Database for PostgreSQL - Flexible Server using Azure CLI
1313

14-
This article describes how to back up **Azure Database for PostgreSQL - Flexible Server** using Azure CLI.
15-
Learn about the [supported scenarios and limitations for Azure Database for PostgreSQL - Flexible Server backup](backup-azure-database-postgresql-flex-support-matrix.md).
14+
This article describes how to back up Azure Database for PostgreSQL - Flexible Server using Azure CLI.
15+
16+
## Prerequisites
17+
18+
Before you back up Azure Database for PostgreSQL - Flexible Server, review the [supported scenarios and limitations for backing up Azure Database for PostgreSQL - Flexible Servers](backup-azure-database-postgresql-flex-support-matrix.md).
1619

1720
## Create a Backup vault
1821

@@ -53,211 +56,15 @@ az dataprotection backup-vault create -g testBkpVaultRG --vault-name TestBkpVaul
5356
5457
```
5558

56-
## Create a Backup policy
57-
58-
After the vault is created, let's create a Backup policy to protect Azure PostgreSQL – Flexible Server.
59-
60-
### Understand PostGreSQL backup policy
61-
62-
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.
63-
64-
- PolicyRule
65-
- BackupRule
66-
- BackupParameter
67-
- BackupType (A full database backup in this scenario)
68-
- Initial Datastore (Where the backups should land initially)
69-
- Trigger (How the backup is triggered)
70-
- Schedule based
71-
- Default tagging criteria (a default 'tag' for all the scheduled backups. This tag links the backups to the retention rule)
72-
- Default Retention Rule (A rule that is applied to all backups, by default, on the initial datastore)
73-
74-
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**.
75-
76-
### Retrieve the policy template
77-
78-
To understand the inner components of a Backup policy for Azure PostgreSQL – Flexible Server database backup, retrieve the policy template using the [`az dataprotection backup-policy get-default-policy-template`](/cli/azure/dataprotection/backup-policy?view=azure-cli-latest&preserve-view=true#az-dataprotection-backup-policy-get-default-policy-template) command. This command returns a default policy template for a given datasource type. Use this policy template to create a new policy.
79-
80-
```azurecli
81-
az dataprotection backup-policy get-default-policy-template --datasource-type AzureDatabaseForPostgreSQLFlexibleServer
82-
83-
{
84-
"datasourceTypes": [
85-
"Microsoft.DBforPostgreSQL/flexibleServers"
86-
],
87-
"name": "OssFlexiblePolicy1",
88-
"objectType": "BackupPolicy",
89-
"policyRules": [
90-
{
91-
"backupParameters": {
92-
"backupType": "Full",
93-
"objectType": "AzureBackupParams"
94-
},
95-
"dataStore": {
96-
"dataStoreType": "VaultStore",
97-
"objectType": "DataStoreInfoBase"
98-
},
99-
"name": "BackupWeekly",
100-
"objectType": "AzureBackupRule",
101-
"trigger": {
102-
"objectType": "ScheduleBasedTriggerContext",
103-
"schedule": {
104-
"repeatingTimeIntervals": [
105-
"R/2021-08-15T06:30:00+00:00/P1W"
106-
],
107-
"timeZone": "UTC"
108-
},
109-
"taggingCriteria": [
110-
{
111-
"isDefault": true,
112-
"tagInfo": {
113-
"id": "Default_",
114-
"tagName": "Default"
115-
},
116-
"taggingPriority": 99
117-
}
118-
]
119-
}
120-
},
121-
{
122-
"isDefault": true,
123-
"lifecycles": [
124-
{
125-
"deleteAfter": {
126-
"duration": "P3M",
127-
"objectType": "AbsoluteDeleteOption"
128-
},
129-
"sourceDataStore": {
130-
"dataStoreType": "VaultStore",
131-
"objectType": "DataStoreInfoBase"
132-
},
133-
"targetDataStoreCopySettings": []
134-
}
135-
],
136-
"name": "Default",
137-
"objectType": "AzureRetentionRule"
138-
}
139-
]
140-
}
141-
142-
```
143-
144-
The policy template consists of a trigger (decides what triggers the backup) and a lifecycle (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**.
145-
146-
**Scheduled trigger:**
147-
148-
```json
149-
"trigger": {
150-
"objectType": "ScheduleBasedTriggerContext",
151-
"schedule": {
152-
"repeatingTimeIntervals": [
153-
"R/2021-08-15T06:30:00+00:00/P1W"
154-
],
155-
"timeZone": "UTC"
156-
}
157-
158-
```
159-
160-
**Default retention rule lifecycle:**
161-
162-
```json
163-
164-
{
165-
"isDefault": true,
166-
"lifecycles": [
167-
{
168-
"deleteAfter": {
169-
"duration": "P3M",
170-
"objectType": "AbsoluteDeleteOption"
171-
},
172-
"sourceDataStore": {
173-
"dataStoreType": "VaultStore",
174-
"objectType": "DataStoreInfoBase"
175-
},
176-
"targetDataStoreCopySettings": []
177-
}
178-
],
179-
"name": "Default",
180-
"objectType": "AzureRetentionRule"
181-
}
182-
183-
```
184-
185-
### Modify the policy template
186-
187-
> [!IMPORTANT]
188-
>In Azure PowerShell, Objects can be used as staging locations to perform all modifications. In Azure CLI, we have to use files, as there's no notion of Objects. Each **edit** operation should be redirected to a new file, where content is read from the *input* file and redirected to the *output* file. You can later rename the file as required while using in a script.
189-
190-
#### Modify the schedule
191-
192-
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 [`az dataprotection backup-policy trigger set`](/cli/azure/dataprotection/backup-policy/trigger?view=azure-cli-latest&preserve-view=true#az-dataprotection-backup-policy-trigger-set) command.
193-
194-
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*.
195-
196-
```azurecli
197-
az dataprotection backup-policy trigger create-schedule --interval-type Weekly --interval-count 1 --schedule-days 2021-08-15T22:00:00 2021-08-18T22:00:00 2021-08-20T22:00:00
198-
[
199-
"R/2021-08-15T22:00:00+00:00/P1W",
200-
"R/2021-08-18T22:00:00+00:00/P1W",
201-
"R/2021-08-20T22:00:00+00:00/P1W"
202-
]
203-
204-
az dataprotection backup-policy trigger set --policy .\OSSPolicy.json --schedule R/2021-08-15T22:00:00+00:00/P1W R/2021-08-18T22:00:00+00:00/P1W R/2021-08-20T22:00:00+00:00/P1W > EditedOSSPolicy.json
205-
206-
```
207-
208-
#### Add a new retention rule
209-
210-
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 [`az dataprotection backup-policy retention-rule create-lifecycle`](/cli/azure/dataprotection/backup-policy/retention-rule?view=azure-cli-latest&preserve-view=true#az-dataprotection-backup-policy-retention-rule-create-lifecycle) command to create new lifecycles and use the [`az dataprotection backup-policy retention-rule set`](/cli/azure/dataprotection/backup-policy/retention-rule?view=azure-cli-latest&preserve-view=true#az-dataprotection-backup-policy-retention-rule-set) command to associate them with the new rules or to the existing rules.
211-
212-
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*.
213-
214-
```azurecli
215-
az dataprotection backup-policy retention-rule create-lifecycle --retention-duration-count 6 --retention-duration-type Months --source-datastore VaultStore > VaultLifeCycle.JSON
216-
217-
az dataprotection backup-policy retention-rule set --lifecycles .\VaultLifeCycle.JSON --name Monthly --policy .\EditedOSSPolicy.json > AddedRetentionRulePolicy.JSON
218-
219-
```
220-
221-
#### Add a tag and the relevant criteria
222-
223-
Once a retention rule is created, you have to create a corresponding tag in the **Trigger** property of the Backup policy. Use the [`az dataprotection backup-policy tag create-absolute-criteria`](/cli/azure/dataprotection/backup-policy/tag?view=azure-cli-latest&preserve-view=true#az-dataprotection-backup-policy-tag-create-absolute-criteria) command to create a new tagging criteria and use the [`az dataprotection backup-policy tag set`](/cli/azure/dataprotection/backup-policy/tag?view=azure-cli-latest&preserve-view=true#az-dataprotection-backup-policy-tag-set) command to update the existing tag or create a new tag.
224-
225-
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.
226-
227-
In this example, the tag criteria should be named *Monthly*.
228-
229-
```azurecli
230-
az dataprotection backup-policy tag create-absolute-criteria --absolute-criteria FirstOfMonth > tagCriteria.JSON
231-
az dataprotection backup-policy tag set --criteria .\tagCriteria.JSON --name Monthly --policy .\AddedRetentionRulePolicy.JSON > AddedRetentionRuleAndTag.JSON
232-
233-
```
234-
235-
For example, 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 [`az dataprotection backup-policy tag create-generic-criteria`](/cli/azure/dataprotection/backup-policy/tag?view=azure-cli-latest&preserve-view=true#az-dataprotection-backup-policy-tag-create-generic-criteria) command.
236-
237-
```azurecli
238-
az dataprotection backup-policy tag create-generic-criteria --days-of-week Sunday Friday > tagCriteria.JSON
239-
az dataprotection backup-policy tag set --criteria .\tagCriteria.JSON --name Monthly --policy .\AddedRetentionRulePolicy.JSON > AddedRetentionRuleAndTag.JSON
240-
241-
```
242-
243-
### Create a new PostgreSQL - flexible Server backup policy
244-
245-
Once the template is modified as per the requirements, use the [`az dataprotection backup-policy create`](/cli/azure/dataprotection/backup-policy?view=azure-cli-latest&preserve-view=true#az-dataprotection-backup-policy-create) command to create a policy using the modified template.
246-
247-
```azurecli
248-
az dataprotection backup-policy create --backup-policy-name FinalOSSPolicy --policy AddedRetentionRuleAndTag.JSON --resource-group testBkpVaultRG --vault-name TestBkpVault
249-
250-
```
251-
25259
## Configure backup
25360

254-
Once the vault and policy are created, consider the following critical points to protect an Azure PostgreSQL Flexible Server database:
61+
Before you configure protection for the database, ensure that you [create a Backup policy](quick-backup-postgresql-flexible-server-cli.md#create-a-backup-policy). Once the vault and policy are created, protect the Azure Database for PostgreSQL - Flexible Server by following these steps:
25562

256-
- PostgreSQL Flexible Server database for protection
257-
- Backup vault to store the backup data
258-
- Request for backup configuration
63+
- Fetch the ARM ID of the PostgreSQL - Flexible Server to be protected
64+
- Grant access to the Backup vault
65+
- Prepare the backup configuration request
25966

260-
### Fetch the ID of the PostgreSQL - Flexible Server to be protected
67+
### Fetch the ARM ID of the PostgreSQL - Flexible Server to be protected
26168

26269
Fetch the Azure Resource Manager ID (ARM ID) of PostgreSQL – Flexible Server to be protected. This ID serves as the identifier of the database. Let's use an example of a database named `empdb11` under a PostgreSQL - Flexible Server `testposgresql`, which is present in the resource group `ossrg` under a different subscription.
26370

@@ -270,9 +77,9 @@ ossId="/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourcegroups/ossrg/
27077

27178
### Grant access to the Backup vault
27279

273-
Backup vault has to connect to the PostgreSQL – Flexible Server, and then access the database via the keys present in the key vault. So, it requires access to the PostgreSQL – Flexible server and the key vault. Grant access to the Backup vault's Managed Service Identity (MSI).
80+
Backup vault has to connect to the PostgreSQL – Flexible Server, and then access the database via the keys present in the key vault. So, it requires access to the PostgreSQL – Flexible server and the key vault. Grant access to the Backup vault's Managed-Service Identity (MSI).
27481

275-
Check the [permissions](backup-azure-database-postgresql-flex-overview.md#permissions-for-backup) required for the Backup vault's Managed Service Identity (MSI) on the PostgreSQL – Flexible Server and Azure Key vault that stores keys to the database.
82+
Check the [permissions](backup-azure-database-postgresql-flex-overview.md#permissions-for-backup) required for the Backup vault's Managed-Service Identity (MSI) on the PostgreSQL – Flexible Server and Azure Key vault that stores keys to the database.
27683

27784
### Prepare the backup configuration request
27885

@@ -425,4 +232,4 @@ az dataprotection job list-from-resourcegraph --datasource-type AzureDatabaseFor
425232

426233
## Next steps
427234

428-
- [Restore Azure Database for PostgreSQL - flexible server using Azure CLI](backup-azure-database-postgresql-flex-restore-cli.md)
235+
- [Restore Azure Database for PostgreSQL - Flexible Server using Azure CLI](backup-azure-database-postgresql-flex-restore-cli.md).

0 commit comments

Comments
 (0)