Managing backup policies in Managed Service for PostgreSQL
Backup policies allow you to flexibly manage the creation and storage of cluster backups. You can configure a schedule to create full backups and specify their retention period.
Creating a backup policy
If you do not have the Yandex Cloud (CLI) command line interface yet, install and initialize it.
The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID>
command. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command to create a policy:
yc managed-postgresql backup-retention-policy create --help
-
Create a policy:
yc managed-postgresql backup-retention-policy create \ --cluster-id <cluster_ID> \ --policy-name <policy_name> \ --day-of-month <day_of_month> \ --month <month> \ --day-of-week <day_of_week> \ --retain-for-days <backup_retention_period_in_days> \ --description <policy_description>
Where:
-
day-of-month
: Day of month. The possible value is1–31
. -
month
: Month. The possible values are1–12
orJAN–DEC
. -
day-of-week
: Day of week. The possible values are0–6
orSUN–SAT
. -
retain-for-days
: Backup retention period in days. The minimum value is7
.The
day-of-month
,month
, andday-of-week
parameters are used to schedule backups. The schedule is set as a cron expression, but hours and minutes are not specified.The cron expression also supports special characters:
*
: Selecting all possible values. A backup will be taken on every possible opportunity (every day or month) provided there is no conflict with other parameters. This option is used by default if the parameter value is not specified.,
: Listing multiple values.–
: Specifying a range of values./
: Specifying a range interval. For example,*/3
for theday-of-month
parameter means that a backup will be created every three days.
If none of the schedule parameters is set, backups are taken based on the
* * *
cron expression, i.e., every day.Examples of cron expressions:
1 */6 *
: Backup is created on the first day of month every six month.31 jan SUN
: Backup is created in January on Sundays and on January 31.* * WED
: Backup is created every Wednesday.
You can try creating a cron expression in the editor
.
You can get the cluster ID with a list of clusters.
Result:
policy_id: mdbt553glp51******** cluster_id: c9q5le6h1a4k******** policy_name: test-policy created_at: "2025-03-25T15:55:50.393000450Z" cron: day_of_month: "25" month: mar day_of_week: TUE retain_for_days: "300"
-
Getting a list of backup policies
If you do not have the Yandex Cloud (CLI) command line interface yet, install and initialize it.
The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID>
command. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command to get a list of policies:
yc managed-postgresql backup-retention-policy list --help
-
Get a list of policies for a Managed Service for PostgreSQL cluster:
yc managed-postgresql backup-retention-policy list \ --cluster-id <cluster_ID>
You can get the cluster ID with a list of clusters.
Result:
+----------------------+-------------+--------------------+------------+-------------------+ | ID | NAME | CLUSTER ID | CRONTAB | RETENTION PERIOD | +----------------------+-------------+--------------------+------------+-------------------+ | mdbt553glp51******** | test-policy | c9q5le6h1a4******* | 31 JAN SUN | 50 | +----------------------+-------------+--------------------+------------+-------------------+
Order of parameters in the
CRONTAB
column:day_of_month
,month
,day_of_week
.
Deleting a backup policy
If you do not have the Yandex Cloud (CLI) command line interface yet, install and initialize it.
The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID>
command. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command to delete a policy:
yc managed-postgresql backup-retention-policy delete --help
-
Delete a policy:
yc managed-postgresql backup-retention-policy delete <policy_ID> \ --cluster-id <cluster_ID>
You can get the cluster ID with a list of clusters.