Managing backups

You can create backups and restore clusters from existing backups.

Restoring clusters from backups

When you restore a cluster from a backup, you create a new cluster with the data from the backup. If the folder has insufficient resources to create such a cluster, you will not be able to restore from the backup.

For a new cluster, you should set all the parameters that are required at creation.

  1. Go to the folder page and select Managed Service for PostgreSQL.

  2. Click on the name of the cluster you need and select the tab Backup copies.

  3. Click image for the required backup and then click Restore cluster.

  4. Set up the new cluster. You can select a folder for the new cluster from the Folder list.

  5. Click Restore cluster.

Managed Service for PostgreSQL runs cluster restore from backup.

If you don't have the Yandex.Cloud command line interface yet, install it.

The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id parameter.

To restore a cluster from a backup:

  1. View the description of the CLI's restore cluster command PostgreSQL:

    $ yc managed-postgresql cluster restore --help
    
  2. Getting a list of available PostgreSQL cluster backups:

    $ yc managed-postgresql backup list
    
    +--------------------------+----------------------+----------------------+----------------------+
    |            ID            |      CREATED AT      |  SOURCE CLUSTER ID   |      STARTED AT      |
    +--------------------------+----------------------+----------------------+----------------------+
    | c9qlk4v13uq79r9cgcku:... | 2018-11-02T10:08:38Z | c9qlk4v13uq79r9cgcku | 2018-11-02T10:08:37Z |
    | ...                                                                                           |                          |
    +--------------------------+----------------------+----------------------+----------------------+
    

    You can restore a PostgreSQL cluster at any time after creating a backup (time in the CREATED AT column).

  3. Request creation of a cluster from a backup:

    $ yc managed-postgresql cluster restore \
           --backup-id c9qlk4v13uq79r9cgcku:base_000000010000000000000002 \
           --time 2018-11-02T10:09:38Z \
           --name mynewpg \
           --environment=PRODUCTION \
           --network-name default \
           --host zone-id=ru-central1-c,subnet-id=b0rcctk2rvtr8efcch63 \
           --disk-size 20 \
           --disk-type network-ssd \
           --resource-preset s1.nano
    

    This results in a new PostgreSQL cluster with the following characteristics:

    • Named mynewpg.
    • In the PRODUCTION environment.
    • В сети default.
    • With one s1.nano class host в подсети b0rcctk2rvtr8efcch63 in the ru-central1-c availability zone.
    • With the databases and users from the backup.
    • With SSD network storage of 20 GB.

Creating backups

  1. Go to the folder page and select Managed Service for PostgreSQL.
  2. Click on the name of the cluster you need and select the tab Backup copies.
  3. Click Create a backup.

If you don't have the Yandex.Cloud command line interface yet, install it.

The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id parameter.

To create a cluster backup:

  1. View a description of the CLI create PostgreSQL backup command:

    $ yc managed-postgresql cluster backup --help
    
  2. Request creation of a backup specifying the cluster name or ID:

    $ yc managed-postgresql cluster backup my-pg-cluster
    

    The cluster name and ID can be retrieved with the list of clusters.

Getting a list of backups

  1. Go to the folder page and select Managed Service for PostgreSQL.
  2. Click on the name of the cluster you need and select the tab Backup copies.

If you don't have the Yandex.Cloud command line interface yet, install it.

The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id parameter.

To get a list of PostgreSQL cluster backups available in the default folder, run the command:

$ yc managed-postgresql backup list

+----------+----------------------+----------------------+----------------------+
|    ID    |      CREATED AT      |  SOURCE CLUSTER ID   |      STARTED AT      |
+----------+----------------------+----------------------+----------------------+
| c9qv4... | 2018-10-31T22:01:07Z | c9qv4ql6bd4hfo1cgc3o | 2018-10-31T22:01:03Z |
| c9qpm... | 2018-10-31T22:01:04Z | c9qpm90p3pcg71jm7tqf | 2018-10-31T22:01:04Z |
+----------+----------------------+----------------------+----------------------+

Getting information about backups

  1. Go to the folder page and select Managed Service for PostgreSQL.
  2. Click on the name of the cluster you need and select the tab Backup copies.

If you don't have the Yandex.Cloud command line interface yet, install it.

The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name or --folder-id parameter.

To get information about a PostgreSQL cluster backup, run the command:

$ yc managed-postgresql backup get <backup ID>

The backup ID can be retrieved with the list of backups .

Set the backup start time

In the management console, you can only set the start time for creating backups by editing the cluster.

To set the backup start time, use the --backup-window-start flag. Time is set in the format HH:MM:SS.

$ yc managed-postgresql cluster create \
   --name <cluster name> \
   --environment <prestable or production> \
   --network-name <network name> \
   --host zone-id=<availability zone>,subnet-id=<subnet ID> \
   --resource-preset <host class> \
   --user name=<username>,password=<user password> \
   --database name=<database name>,owner=<database owner name> \
   --disk-size <storage size in GB>
   --backup-window-start 10:00:00

To change the backup start time in an existing cluster, use the update command:

$ yc yc managed-postgresql cluster update \
   --name <cluster name> \
   --backup-window-start 11:25:00