Managing backups in Managed Service for MongoDB
You can create backups and restore clusters from existing backups.
Managed Service for MongoDB also creates automatic daily backups. You can set the backup start time and retention period.
Restoring clusters from backups
The Point-in-Time Recovery (PITR) technology allows you to restore your cluster to any state in the time interval between the oldest backup and the archiving of the most recent oplog
For example, if the backup operation ended on August 10, 2020 at 12:00:00 UTC, the current date is August 15, 2020, 19:00:00 UTC, and the most recent oplog collection was saved on August 15, 2020, 18:50:00 UTC, the cluster can be restored to any state between August 10, 2020, 12:00:01 UTC and August 15, 2020, 18:50:00 UTC, inclusive.
Warning
PITR is not supported for clusters with sharding enabled. Such clusters can only be restored to the time point of the selected backup.
When you restore a cluster from a backup, you create a new cluster with the backup data. If the folder has insufficient resources to create such a cluster, you will not be able to restore from the backup. The average backup recovery speed is 10 MBps.
For a new cluster, you should set all the parameters required during creation, except for cluster type (a MongoDB backup cannot be restored as a PostgreSQL cluster).
When restored to the current state, the new cluster will match the state of:
- Existing cluster at the time of recovery.
- Deleted cluster at the time of archiving the last oplog.
To restore an existing cluster from a backup:
-
Go to the folder page
and select Managed Service for MongoDB. -
Click the name of the cluster you need and select the
Backups tab. -
Click
for the backup you need and then click Restore cluster. -
Set up the new cluster. You can select a folder for the new cluster from the Folder list.
-
To restore the cluster to a particular point in time after creating this backup, configure Date and time of recovery (UTC) accordingly. You can enter the date manually or select it from the drop-down calendar.
If you do not change the setting, the cluster will be restored to the state when the backup was completed.
-
Click Restore cluster.
To restore a previously deleted cluster from a backup:
-
Go to the folder page
and select Managed Service for MongoDB. -
In the left-hand panel, select
Backups. -
Find the backup you need using the backup creation time and cluster ID. The ID column contains IDs formatted as
<cluster_ID>:<backup_ID>
. -
Click
for the backup you need and then click Restore cluster. -
Set up the new cluster. You can select a folder for the new cluster from the Folder list.
-
To restore the cluster to a particular point in time after creating this backup, configure Date and time of recovery (UTC) accordingly. You can enter the date manually or select it from the drop-down calendar.
If you do not change the setting, the cluster will be restored to the state when the backup was completed.
-
Click Restore cluster.
Managed Service for MongoDB will launch the operation to create a cluster from the backup.
If you do not have the Yandex Cloud command line interface yet, install and initialize 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:
-
View a description of the CLI restore MongoDB cluster command:
yc managed-mongodb cluster restore --help
-
Getting a list of available MongoDB cluster backups:
yc managed-mongodb backup list
Result:
+--------------------------+---------------------+----------------------+---------------------+--------+-----------+ | ID | CREATED AT | SOURCE CLUSTER ID | STARTED AT | SIZE | TYPE | +--------------------------+---------------------+----------------------+---------------------+--------+-----------+ | c9qlk4v13uq7********:... | 2020-08-10 12:00:00 | c9qlk4v13uq7******** | 2020-08-10 11:55:17 | 3.3 KB | AUTOMATED | | ... | | +--------------------------+---------------------+----------------------+---------------------+--------+-----------+
The backup completion time is shown in the
CREATED AT
column of the list of available backups, inyyyy-mm-dd hh:mm:ss
format (2020-08-10 12:00:00
in the example above). You can restore a cluster to any point in time starting with the point when the backup is created. -
Run the command to create a new cluster from a backup (the example shows only some parameters):
yc managed-mongodb cluster restore \ --backup-id <backup_ID> \ --recovery-target-timestamp <time_point> \ --mongodb-version <MongoDB_version> \ --name <new_cluster_name> \ --environment <environment> \ --network-name <network_name> \ --host zone-id=<availability_zone>,` `subnet-id=<subnet_ID> \ --mongod-resource-preset <host_class> \ --mongod-disk-size <storage_size_in_GB> \ --mongod-disk-type <disk_type> \ --performance-diagnostics=<enable_diagnostics>
Where:
-
--recovery-target-timestamp
: Time point to restore the MongoDB cluster to, in UNIX time format. If you do not specify the parameter, the cluster will be restored to when the backup was completed. -
--environment
: Environment,PRESTABLE
orPRODUCTION
. -
--mongod-disk-type
: Disk type,network-hdd
ornetwork-ssd
. -
--performance-diagnostics
: Enables cluster performance diagnostics,true
orfalse
.
-
To restore an existing cluster from a backup, use the restore REST API method for the Cluster resource or the ClusterService/Restore gRPC API call and provide the following in the request:
- ID of the backup you need, in the
backupId
parameter. To find out the ID, get a list of cluster backups. - Name of the new cluster that will contain the data recovered from the backup, in the
name
parameter. It must be unique within the folder.
In the recoveryTargetSpec.timestamp
parameter, specify the time point to restore the MongoDB cluster to, in UNIX time
Creating a backup
- Go to the folder page
and select Managed Service for MongoDB. - Click the name of the cluster you need and select the
Backups tab. - Click Create backup.
The service will start creating a backup without an additional confirmation.
If you do not have the Yandex Cloud command line interface yet, install and initialize 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:
-
View a description of the CLI create MongoDB backup command:
yc managed-mongodb cluster backup --help
-
Request a backup to be created by specifying the cluster name or ID:
yc managed-mongodb cluster backup <cluster_name_or_ID>
You can get the cluster ID and name with a list of clusters.
To create a backup, use the backup REST API method for the Cluster resource or the ClusterService/Backup gRPC API call and provide the cluster ID in the clusterId
parameter of your request.
You can get the cluster ID with a list of clusters in the folder.
Warning
While you are creating your backup, the cluster performance might degrade.
Getting a list of backups
To get a list of cluster backups:
- Go to the folder page
and select Managed Service for MongoDB. - Click the name of the cluster you need and select the
Backups tab.
To get a list of all backups in a folder:
- Go to the folder page
and select Managed Service for MongoDB. - In the left-hand panel, select
Backups.
These lists contain the following information:
- Backup name.
- Source shard.
- Backup size.
- Backup type: Automatic (
Automated
) or manual (Manual
). - Start time of backup creation in UTC (Coordinated Universal Time).
- End time of backup creation in UTC.
If you do not have the Yandex Cloud command line interface yet, install and initialize 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 MongoDB cluster backups available in the default folder, run the command:
yc managed-mongodb backup list
Result:
+--------------------------+---------------------+----------------------+---------------------+--------+-----------+
| ID | CREATED AT | SOURCE CLUSTER ID | STARTED AT | SIZE | TYPE |
+--------------------------+---------------------+----------------------+---------------------+--------+-----------+
| c9qlk4v13uq7********:... | 2020-08-10 12:00:00 | c9qlk4v13uq7******** | 2020-08-10 11:55:17 | 3.3 KB | AUTOMATED |
| c9qpm90p3pcg********:... | 2020-08-09 22:01:04 | c9qpm90p3pcg******** | 2020-08-09 21:30:00 | 30 KB | MANUAL |
+--------------------------+---------------------+----------------------+---------------------+--------+-----------+
The resulting table contains the following information:
- ID of the backup.
- End time of backup creation in UTC (Coordinated Universal Time).
- ID of the cluster that the backup was created for.
- Start time of backup creation in UTC.
- Backup size.
- Backup type: Automatic (
AUTOMATED
) or manual (MANUAL
).
To get a list of cluster backups, use the listBackups REST API method for the Cluster resource or the ClusterService/ListBackups gRPC API call and provide the cluster ID in the clusterId
parameter of your request.
You can get the cluster ID with a list of clusters in the folder.
To get a list of backups for all the Managed Service for MongoDB clusters in the folder, use the list REST API method for the Backup resource or the BackupService/List gRPC API call and provide the folder ID in the folderId
parameter of your request.
Getting information about backups
To get information about the backup of an existing cluster:
- Go to the folder page
and select Managed Service for MongoDB. - Click the name of the cluster you need and select the
Backups tab.
To get information about the backup of a previously deleted cluster:
- Go to the folder page
and select Managed Service for MongoDB. - In the left-hand panel, select
Backups.
If you do not have the Yandex Cloud command line interface yet, install and initialize 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 MongoDB cluster backup, run the command:
yc managed-mongodb backup get <backup_ID>
You can retrieve the backup ID with a list of backups.
To get information about a backup, use the get REST API method for the Backup resource or the BackupService/Get gRPC API call and provide the backup ID in the backupId
parameter of your request.
To find out the ID, retrieve a list of backups.
Setting a retention period for automatic backups
In the management console
If you do not have the Yandex Cloud command line interface yet, install and initialize 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 set a retention period for automatic backups, provide the required value in the --backup-retain-period-days
argument of the cluster update
command:
yc managed-mongodb cluster update <cluster_name_or_ID> \
--backup-retain-period-days=<retention_period_in_days>
The possible values range from 7
to 35
. The default value is 7
.
You can request the cluster ID and name with a list of clusters in the folder.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
For a complete list of available MongoDB cluster configuration fields, see the Terraform provider documentation
. -
Add a
backup_retain_period_days
block in thecluster_config
section to the MongoDB cluster description.resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { ... cluster_config { ... backup_retain_period_days = <retention_period_in_days> } ... } ...
Where
backup_retain_period_days
is the automatic backup retention period.The possible values range from
7
to35
. The default value is7
. -
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
Timeouts
The Terraform provider sets the following timeouts for Managed Service for MongoDB cluster operations:
- Creating a cluster, including by restoring one from a backup: 30 minutes.
- Editing a cluster: 60 minutes.
Operations exceeding the set timeout are interrupted.
How do I change these limits?
Add the
timeouts
block to the cluster description, for example:resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { ... timeouts { create = "1h30m" # An hour and a half update = "2h" # Two hours } }
-
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Cluster.update method and make a request, e.g., via cURL
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
updateMask
parameter as a single comma-separated string.curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>' \ --data '{ "updateMask": "configSpec.backupRetainPeriodDays", "configSpec": { "backupRetainPeriodDays": <retention_period_in_days> } }'
Where:
-
updateMask
: List of parameters to update as a single string, separated by commas.In this case, only one parameter is provided.
-
configSpec.backupRetainPeriodDays
: Automatic backup retention period.The values range from
7
to35
. The default value is7
.
You can get the cluster ID with a list of clusters in the folder.
-
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
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. -
Use the ClusterService/Update call and make a request, e.g., via gRPCurl
:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
update_mask
parameter as an array ofpaths[]
strings.Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }
grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mongodb/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "update_mask": { "paths": [ "config_spec.backup_retain_period_days" ] }, "config_spec": { "backup_retain_period_days": <retention_period_in_days> } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.ClusterService.Update
Where:
-
update_mask
: List of parameters to update as an array ofpaths[]
strings.In this case, only one parameter is provided.
-
config_spec.backup_retain_period_days
: Automatic backup retention period.The values range from
7
to35
. The default value is7
.
You can get the cluster ID with a list of clusters in the folder.
-
-
View the server response to make sure the request was successful.
Examples
Create a new Managed Service for MongoDB cluster from a backup with the following test characteristics:
- Recovery backup:
c9qlk4v13uq7********:...
. - Time point to recover to:
1597060810
(2020-08-10 12:00:10
). - Version:
5.0
. - Name of the new cluster:
mynewmg
. - Environment:
PRODUCTION
. - Network:
default
. - One
s2.micro
host in theru-central1-a
availability zone andb0rcctk2rvtr********
subnet. - Network SSD storage (
network-ssd
): 20 GB. - With databases and users that existed in the cluster at the time of recovery.
Run the following command:
yc managed-mongodb cluster restore \
--backup-id c9qlk4v13uq7********:... \
--recovery-target-timestamp 1597060810 \
--mongodb-version 5.0 \
--name mynewmg \
--environment PRODUCTION \
--network-name default \
--host zone-id=ru-central1-a,subnet-id=b0rcctk2rvtr8efcch64 \
--mongod-resource-preset s2.micro \
--mongod-disk-size 20 \
--mongod-disk-type network-ssd