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. To do this:
If you no longer need the resources you created, delete them.
Getting started
Prepare the infrastructure:
-
Create a Managed Service for YDB database in any suitable configuration.
-
Create a service account with the
storage.editor
andydb.editor
roles. 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.editor
andydb.editor
roles. - Object Storage target bucket.
- Endpoints.
- Transfer.
-
Specify the following in the
ydb-to-object-storage.tf
file:folder_id
: Folder ID.bucket_name
: Bucket name consistent with the naming conventions.
-
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
-
Create the
seasons
table in 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 Storage
type 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
.
- Bucket:
-
Create a source endpoint of the
YDB
type and specify the DB connection parameters in it:- Database: Select the YDB database from the list.
- Service account ID: Select the service account you previously created.
-
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
ydb-to-object-storage.tf
file, specify these variables:target_endpoint_id
: ID of the target endpoint.source_endpoint_id
: ID of the source endpoint.transfer_enabled
: Put1
to create a 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.
-
-
-
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.
- Go to the Objects tab.
- Check that the Object Storage bucket contains the
from_YDB
folder with the<seasons.csv>
object with test data.
Delete the resources you created
Some resources are not free of charge. To avoid paying for them, delete the resources you no longer need:
Delete the other resources depending on how they were created:
- Delete the Object Storage bucket.
- Delete the Managed Service for YDB database.
- If you created a service account, delete it.
-
In the terminal window, go to the directory containing the infrastructure plan.
-
Delete the
ydb-to-object-storage.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.
-
All the resources described in the
ydb-to-object-storage.tf
configuration file will be deleted. -