Loading data from Yandex Managed Service for YDB to Yandex Object Storage
You can migrate data from Managed Service for YDB to Object Storage using Data Transfer. Proceed as follows:
If you no longer need the resources you created, delete them.
Required paid resources
-
Managed Service for YDB database (see Managed Service for YDB pricing). Its pricing is based on deployment mode:
- In serverless mode, you pay for data operations and storage volume, including stored backups.
- In dedicated instance mode, you pay for the use of computing resources allocated to the database, storage size, and backups.
-
Object Storage bucket: Use of storage, data operations (see Object Storage pricing).
Getting started
Set up the infrastructure:
-
Create a Managed Service for YDB database with your preferred configuration.
-
Create a service account with the
storage.editorandydb.editorroles. The transfer will use it to access the database and bucket.
-
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 ydb-to-object-storage.tf
configuration file to the same working directory.This file describes:
- Network.
- Subnet.
- Security group.
- Service account with the
storage.editorandydb.editorroles. - Object Storage target bucket.
- Endpoints.
- Transfer.
-
Specify the following in the
ydb-to-object-storage.tffile:folder_id: Folder ID.bucket_name: Bucket name consistent with the naming conventions.
-
Validate your Terraform configuration files using this command:
terraform validateTerraform will display any configuration errors detected in your files.
-
Create the required infrastructure:
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the 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 your test data
-
Create a table named
seasonsin the Managed Service for YDB database:CREATE TABLE seasons ( series_id Uint64, season_id Uint64, title Utf8, first_aired Uint64, last_aired Uint64, PRIMARY KEY (series_id, season_id) ); COMMIT; -
Populate the table with data:
REPLACE INTO seasons (series_id, season_id, title, first_aired, last_aired) VALUES (1, 1, "Season 1", CAST(Date("2006-02-03") AS Uint64), CAST(Date("2006-03-03") AS Uint64)), (1, 2, "Season 2", CAST(Date("2007-08-24") AS Uint64), CAST(Date("2007-09-28") AS Uint64)), (1, 3, "Season 3", CAST(Date("2008-11-21") AS Uint64), CAST(Date("2008-12-26") AS Uint64)), (1, 4, "Season 4", CAST(Date("2010-06-25") AS Uint64), CAST(Date("2010-07-30") AS Uint64)), (2, 1, "Season 1", CAST(Date("2014-04-06") AS Uint64), CAST(Date("2014-06-01") AS Uint64)), (2, 2, "Season 2", CAST(Date("2015-04-12") AS Uint64), CAST(Date("2015-06-14") AS Uint64)), (2, 3, "Season 3", CAST(Date("2016-04-24") AS Uint64), CAST(Date("2016-06-26") AS Uint64)), (2, 4, "Season 4", CAST(Date("2017-04-23") AS Uint64), CAST(Date("2017-06-25") AS Uint64)), (2, 5, "Season 5", CAST(Date("2018-03-25") AS Uint64), CAST(Date("2018-05-13") AS Uint64)); COMMIT;
Prepare and activate the transfer
-
Create a target endpoint of the
Object Storagetype with the following settings:-
Bucket:
<name_of_previously_created_bucket> -
Service account:
<name_of_previously_created_service_account> -
Serialization format:
CSV -
Encoding format:
UNCOMPRESSED -
Folder name:
from_YDB
-
-
Create a source endpoint of the
YDBtype and specify the DB connection settings in it:-
Database: Select the YDB database from the list.
-
Service account ID: Select the service account you created earlier.
-
-
Create a Snapshot-type transfer configured to use the new endpoints.
-
Activate the transfer and wait for its status to change to Completed.
-
In the
ydb-to-object-storage.tffile, specify the following variables:target_endpoint_id: ID of the target endpoint.source_endpoint_id: ID of the source endpoint.transfer_enabled:1to create a transfer.
-
Validate your Terraform configuration files using this command:
terraform validateTerraform will display any configuration errors detected in your files.
-
Create the required infrastructure:
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
-
Activate the transfer and wait for its status to change to Completed.
Test the transfer
Make sure the data has been migrated from Managed Service for YDB to the Object Storage bucket:
- In the management console
, select the folder where the bucket is located. - In the list of services, select Object Storage.
- Select the bucket from the list.
- Navigate to the Objects tab.
- Make sure the Object Storage bucket contains the
from_YDBdirectory with the<seasons.csv>test data object.
Delete the resources you created
To reduce the consumption of resources you do not need, delete them:
-
Delete the other resources depending on how they were created:
ManuallyTerraform-
If you created any service account, delete it.
-
In the terminal window, go to the directory containing the infrastructure plan.
Warning
Make sure the directory has no Terraform manifests with the resources you want to keep. Terraform deletes all resources that were created using the manifests in the current directory.
-
Delete resources:
-
Run this command:
terraform destroy -
Confirm deleting the resources and wait for the operation to complete.
All the resources described in the Terraform manifests will be deleted.
-