Quickstart: Create a backup policy for Azure Database for PostgreSQL - Flexible Server using Azure PowerShell
Article
This quickstart describes how to create a backup policy to protect Azure Database for PostgreSQL - Flexible Server using Azure PowerShell.
Azure Backup policy for Azure Database for PostgreSQL - Flexible Server defines how and when backups are created, the retention period for recovery points, and the rules for data protection and recovery. Azure Backup allows you to back up your Azure PostgreSQL - Flexible Server using multiple clients, such as Azure portal, PowerShell, CLI, Azure Resource Manager, Bicep, Terraform, and so on.
Prerequisites
Before you create a backup policy for Azure Database for PostgreSQL Flexible Server, ensure that the following prerequisites are met:
To create a backup policy for PostgreSQL – Flexible Server, follow these steps:
Understand PostgreSQL - Flexible Server backup policy
Retrieve the policy template
Modify the policy template
Create the policy
Understand PostgreSQL – Flexible Server backup policy
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.
PolicyRule
BackupRule
BackupParameter
BackupType (A full database backup in this scenario)
Initial Datastore (Where the backups land initially)
Trigger (How the backup is triggered)
Schedule based
Default tagging criteria (a default 'tag' for all the scheduled backups. This tag links the backups to the retention rule)
Default Retention Rule (A rule that is applied to all backups, by default, on the initial datastore)
So, this object defines:
The type of backups triggered
The way the policy are triggered (via a schedule)
The tags implemented to the Backup policy
The location where the data is stored (a datastore)
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 three months.
Retrieve the Policy template
To understand the inner components of a backup policy for Azure PostgreSQL – Flexible server database backup, retrieve the policy template using the Get-AzDataProtectionPolicyTemplate cmdlet. This cmdlet returns a default policy template for a given datasource type. Use this policy template to create a new policy.
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 three months.
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 cmdlet.
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.
The following example creates a new retention rule named Monthly, where the first successful backup of every month should be retained in vault for six months.
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.
In this example, the tag criteria should be named Monthly.
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 cmdlet.
Administer an SQL Server database infrastructure for cloud, on-premises and hybrid relational databases using the Microsoft PaaS relational database offerings.