Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI for business
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex Managed Service for PostgreSQL
  • Getting started
    • All guides
      • Getting information on existing clusters
      • Creating a cluster
      • Updating cluster settings
      • Stopping and starting a cluster
      • Managing PostgreSQL hosts
      • Migrating hosts to a different availability zone
      • Managing replication slots
      • Managing backups
      • Managing backup policies
      • Managing disk space
      • Maintenance
      • Updating the PostgreSQL version
      • Deleting a cluster
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes

In this article:

  • Creating a backup policy
  • Getting a list of backup policies
  • Deleting a backup policy
  1. Step-by-step guides
  2. Clusters
  3. Managing backup policies

Managing backup policies in Managed Service for PostgreSQL

Written by
Yandex Cloud
Updated at June 20, 2025
  • Creating a backup policy
  • Getting a list of backup policies
  • Deleting a backup policy

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 policyCreating a backup policy

CLI
REST API
gRPC API

If you do not have the Yandex Cloud CLI installed yet, install and initialize it.

By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.

  1. See the description of the CLI command to create a policy:

    yc managed-postgresql backup-retention-policy create --help
    
  2. 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 is 1–31.

    • month: Month. The possible values are 1–12 or JAN–DEC.

    • day-of-week: Day of week. The possible values are 0–6 or SUN–SAT.

    • retain-for-days: Backup retention period in days. The minimum value is 7.

      The day-of-month, month, and day-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 the day-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 each Sunday and on January 31.
      • * * WED: Backup is created every Wednesday.

      You can test 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"
    
  1. Get an IAM token for API authentication and put it into the environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Use the BackupRetentionPolicy.Create method and send the following request, e.g., via cURL:

    curl \
      --request POST \
      --header "Authorization: Bearer $IAM_TOKEN" \
      --header "Content-Type: application/json" \
      --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>/retention_policies' \
      --data '{
                 "cron": {
                   "dayOfMonth": "<day_of_month>",
                   "month": "<month>",
                   "dayOfWeek": "<day_of_week>"
                 },
                 "retainForDays": "<retention_period_in_days>",
                 "description": "<policy_description>",
                 "policyName": "<policy_name>"
             }'
    

    Where:

    • dayOfMonth: Day of month. The possible value is 1-31.

    • month: Month. The possible values are 1-12 or JAN-DEC.

    • dayOfWeek: Day of week. The possible values are 0-6 or SUN-SAT.

    • retainForDays: Backup retention period in days. The minimum value is 7.

      The dayOfMonth, month, and dayOfWeek 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 the dayOfMonth 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 each Sunday and on January 31.
      • * * WED: Backup is created every Wednesday.

      You can test a cron expression in the editor.

    You can request the cluster ID with a list of clusters.

  3. View the server response to make sure the request was successful.

  1. Get an IAM token for API authentication and put it into the environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Clone the cloudapi repository:

    cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
    

    Below, we assume the repository contents are stored in the ~/cloudapi/ directory.

  3. To create a policy:

    1. Use the BackupRetentionPolicyService.Create method and send the following request, e.g., via gRPCurl:

      grpcurl \
          -format json \
          -import-path ~/cloudapi/ \
          -import-path ~/cloudapi/third_party/googleapis/ \
          -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/backup_retention_policy_service.proto \
          -rpc-header "Authorization: Bearer $IAM_TOKEN" \
          -d '{
                "cluster_id": "<cluster_ID>",
                "cron": {
                   "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>",
                "policy_name": "<policy_name>"
              }' \
          mdb.api.cloud.yandex.net:443 \
          yandex.cloud.mdb.postgresql.v1.BackupRetentionPolicyService.Create
      

      Where:

      • day_of_month: Day of month. The possible value is 1–31.

      • month: Month. The possible values are 1–12 or JAN–DEC.

      • day_of_week: Day of week. The possible values are 0–6 or SUN–SAT.

      • retain_for_days: Backup retention period in days. The minimum value is 7.

        The day_of_month, month, and day_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 the day_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 each Sunday and on January 31.
        • * * WED: Backup is created every Wednesday.

        You can test a cron expression in the editor.

      You can get the cluster ID with a list of clusters.

    2. View the server response to make sure the request was successful.

Getting a list of backup policiesGetting a list of backup policies

CLI
REST API
gRPC API

If you do not have the Yandex Cloud CLI installed yet, install and initialize it.

By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.

  1. See the description of the CLI command to get a list of policies:

    yc managed-postgresql backup-retention-policy list --help
    
  2. 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.

  1. Get an IAM token for API authentication and put it into the environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Use the BackupRetentionPolicy.List method and send the following request, e.g., via cURL:

    curl \
      --request GET \
      --header "Authorization: Bearer $IAM_TOKEN" \
      --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>/retention_policies?pageSize=<number_of_results>'
    

    Where page_size is the number of request results returned per page. Specify a number larger than zero.

    You can request the cluster ID with a list of clusters.

  3. View the server response to make sure the request was successful.

  1. Get an IAM token for API authentication and put it into the environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Clone the cloudapi repository:

    cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
    

    Below, we assume the repository contents are stored in the ~/cloudapi/ directory.

  3. To get a list of policies for a cluster:

    1. Use the BackupRetentionPolicyService.List method and send the following request, e.g., via gRPCurl:

      grpcurl \
        -format json \
        -import-path ~/cloudapi/ \
        -import-path ~/cloudapi/third_party/googleapis/ \
        -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/backup_retention_policy_service.proto \
        -rpc-header "Authorization: Bearer $IAM_TOKEN" \
        -d '{
              "cluster_id": "<cluster_ID>",
              "page_size": "<number_of_results>"
            }' \
        mdb.api.cloud.yandex.net:443 \
        yandex.cloud.mdb.postgresql.v1.BackupRetentionPolicyService.List
      

      Where page_size is the number of request results returned per page. Specify a number larger than zero.

      You can request the cluster ID with a list of clusters.

    2. View the server response to make sure the request was successful.

Deleting a backup policyDeleting a backup policy

CLI
REST API
gRPC API

If you do not have the Yandex Cloud CLI installed yet, install and initialize it.

By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.

  1. See the description of the CLI command to delete a policy:

    yc managed-postgresql backup-retention-policy delete --help
    
  2. Delete a policy:

    yc managed-postgresql backup-retention-policy delete <policy_ID> \
       --cluster-id <cluster_ID>
    

    You can get the cluster ID with the list of clusters, and the policy ID, with the list of policies.

  1. Get an IAM token for API authentication and put it into the environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Use the BackupRetentionPolicy.Delete method and send the following request, e.g., via cURL:

    curl \
      --request DELETE \
      --header "Authorization: Bearer $IAM_TOKEN" \
      --url 'https://mdb.api.cloud.yandex.net/managed-postgresql/v1/clusters/<cluster_ID>/retention_policies/<policy_ID>'
    

    You can request the cluster ID with the list of clusters, and the policy ID, with the list of policies.

  3. View the server response to make sure the request was successful.

  1. Get an IAM token for API authentication and put it into the environment variable:

    export IAM_TOKEN="<IAM_token>"
    
  2. Clone the cloudapi repository:

    cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
    

    Below, we assume the repository contents are stored in the ~/cloudapi/ directory.

  3. To delete a policy:

    1. Use the BackupRetentionPolicyService.Delete method and send the following request, e.g., via gRPCurl:

      grpcurl \
        -format json \
        -import-path ~/cloudapi/ \
        -import-path ~/cloudapi/third_party/googleapis/ \
        -proto ~/cloudapi/yandex/cloud/mdb/postgresql/v1/backup_retention_policy_service.proto \
        -rpc-header "Authorization: Bearer $IAM_TOKEN" \
        -d '{
              "policy_id": "<policy_ID>",
              "cluster_id": "<cluster_ID>"
            }' \
        mdb.api.cloud.yandex.net:443 \
        yandex.cloud.mdb.postgresql.v1.BackupRetentionPolicyService.Delete
      

      You can request the cluster ID with the list of clusters, and the policy ID, with the list of policies.

    2. View the server response to make sure the request was successful.

Was the article helpful?

Previous
Managing backups
Next
Managing disk space
© 2025 Direct Cursus Technology L.L.C.