Migrating data from Yandex Managed Service for OpenSearch to Yandex Managed Service for YDB using Data Transfer
With Data Transfer, you can transfer data from a Managed Service for OpenSearch cluster to a Managed Service for YDB DB.
To transfer data:
If you no longer need the resources you created, delete them.
Getting started
Prepare the infrastructure:
-
Create a Managed Service for OpenSearch cluster in any suitable configuration with publicly available hosts.
-
If using security groups in your cluster, make sure they are configured correctly and allow connecting to the Managed Service for OpenSearch cluster.
-
Get an SSL certificate to connect to the Managed Service for OpenSearch cluster.
-
Create a Managed Service for YDB database named
ydb1
in any suitable configuration. -
Create a service account named
ydb-account
with theydb.editor
role. The transfer will use it to access the database.
-
If you do not have Terraform yet, install it.
-
Get the authentication credentials. You can add them to environment variables or specify them later in the provider configuration file.
-
Configure and initialize a provider. There is no need to create a provider configuration file manually, you can download it
. -
Place the configuration file in a separate working directory and specify the parameter values. If you did not add the authentication credentials to environment variables, specify them in the configuration file.
-
Download the opensearch-to-ydb.tf
configuration file to the same working directory.This file describes:
- Network..
- Subnet..
- Security group and rules required to connect to the Managed Service for OpenSearch cluster from the internet.
- Managed Service for YDB database.
- Managed Service for OpenSearch target cluster.
- Target endpoint.
- Transfer.
-
In the
opensearch-to-ydb.tf
file, specify the following parameters:mos_version
: OpenSearch version.mos_password
: User password of the OpenSearch database owner.profile_name
: Your YC CLI profile name.
-
Make sure the Terraform configuration files are correct using this command:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
Create the required infrastructure:
-
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.
-
All the required resources will be created in the specified folder. You can check resource availability and their settings in the management console
. -
Prepare the test data
-
Connect to the Managed Service for OpenSearch source cluster.
-
Create a test index named
people
and set its schema:curl --user admin:<password> \ --cacert ~/.opensearch/root.crt \ --header 'Content-Type: application/json' \ --request PUT 'https://<OpenSearch_DATA_host_address>:9200/people' && \ curl --user admin:<password> \ --cacert ~/.opensearch/root.crt \ --header 'Content-Type: application/json' \ --request PUT 'https://<OpenSearch_DATA_host_address>:9200/people/_mapping?pretty' -d' { "properties": { "name": {"type": "text"}, "age": {"type": "integer"} } } '
-
Populate the test index with data:
curl --user admin:<password> \ --cacert ~/.opensearch/root.crt \ --header 'Content-Type: application/json' \ --request POST 'https://<OpenSearch_DATA_host_address>:9200/people/_doc/?pretty' -d' { "name" : "Alice", "age" : "30" } ' && \ curl --user admin:<password> \ --cacert ~/.opensearch/root.crt \ --header 'Content-Type: application/json' \ --request POST 'https://<OpenSearch_DATA_host_address>:9200/people/_doc/?pretty' -d' { "name" : "Robert", "age" : "32" } '
-
(Optional) Check the data in the test index:
curl --user admin:<password> \ --cacert ~/.opensearch/root.crt \ --header 'Content-Type: application/json' \ --request GET 'https://<OpenSearch_DATA_host_address>:9200/people/_search?pretty'
Prepare and activate the transfer
-
Create a source endpoint of the
OpenSearch
type with the following settings:- Connection type:
Managed Service for OpenSearch cluster
. - Managed Service for OpenSearch cluster: Select the Managed Service for OpenSearch cluster from the list.
- User:
admin
. - Password:
<user_password>
.
- Connection type:
-
Create a target endpoint and a transfer:
ManuallyUsing Terraform-
Create a target endpoint of the
YDB
type with the following settings:- Database: Select the
ydb1
database from the list. - Service account ID: Select the
ydb-account
service account from the list.
- Database: Select the
-
Create a transfer of the Snapshot type that will use the created endpoints.
-
Activate the transfer and wait for its status to change to Completed.
-
In the
opensearch-to-ydb.tf
file, specify the values for these parameters:source_endpoint_id
: Source endpoint ID.transfer_enabled
: Set to1
for creating a target endpoint and transfer.
-
Make sure the Terraform configuration files are correct using this command:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
Create the required infrastructure:
-
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.
-
-
-
The transfer will be activated automatically. Wait for its status to change to Completed.
-
Test the transfer
-
Run the following query:
SELECT * FROM people;
Response example
#| _id | age | name --+------------------------+-----+--------- 0 | "5wn5BJEBRVOYnL8d13sP" | 30 | "Alice" 1 | "6An5BJEBRVOYnL8d13uy" | 32 | "Robert"
Delete the resources you created
Note
Before deleting the created resources, deactivate the transfer.
Some resources are not free of charge. To avoid paying for them, delete the resources you no longer need:
-
Delete the resources depending on how they were created:
ManuallyUsing Terraform-
In the terminal window, go to the directory containing the infrastructure plan.
-
Delete the
opensearch-to-ydb.tf
configuration file. -
Make sure the Terraform configuration files are correct using this command:
terraform validate
If there are any errors in the configuration files, Terraform will point them out.
-
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.
-
This will delete all the resources described in the
opensearch-to-ydb.tf
configuration file. -
-