Transferring a Yandex Compute Cloud disk image to an S3-compatible storage of a third-party provider without an auxiliary VM
You can save a backup of your Yandex Compute Cloud disk in another provider's object storage. Such a backup allows you to keep your data outside Yandex Cloud and use it for recovery.
In this tutorial, you will export a disk snapshot or image to an S3-compatible storage without provisioning an auxiliary VM. You will then use the yc-nbs-export-unpack utility to restore the image into a .raw file or onto a block device. To start the VM within another cloud provider’s infrastructure, simply import the image by following the relevant provider guides.
To transfer a disk image to an S3-compatible storage:
- Prepare a bucket and set up bucket access.
- Submit the request and export the snapshot or image.
- Set up the utility.
- Set up storage access.
- Prepare the encryption key if the disk is encrypted.
- Restore the image.
Prepare a bucket and set up bucket access
You can export the snapshot or image to either a third-party provider's S3-compatible storage or to Yandex Object Storage.
To use Yandex Object Storage, create a bucket and generate a static access key for a service account assigned the storage.admin role for this bucket.
To export into a bucket hosted by a third-party provider, e.g., Selectel:
-
Create
a bucket in Selectel:Note
The example used a private Selectel
bucket in theru-7region. For a different S3-compatible storage, replace the connection properties and check out the provider's requirements related to access and object sizes.-
Specify a name, e.g.,
disk-snapshot-dr-bucket. If this name is taken, pick another one and replace it in the commands below. -
Select private access.
-
Select the
Path-Styleaddressing type. -
Select the cold storage class.
Warning
Prior to uploading, read the pricing policy
, including as pertains to data reading and minimum retention period.
-
-
On the Connection tab, create
an S3 key nameddisk-snapshot-bucket-key. In the key owner field, select Me for a one-time transfer or an individual Selectel service user for regular use. -
Grant the service user full access to the bucket, including the following operations:
- Object reading and writing.
- Viewing bucket contents.
- Multipart upload operations.
-
Save
Access keyandSecret keyto a secure location. You will need them to fill out the export form and set up the utility.
Submit the request and export the snapshot or image
- In the management console, open the disk snapshot or image export form
and follow the on-screen instructions. - Wait until the files are exported to the target bucket.
- In the bucket, locate the folder named after your snapshot or image and check that it holds the
manifest.jsonfile. The commands below refer to this folder as<disk_folder>.
If the export fails with an error or the files do not appear in the bucket, contact support
Set up the utility
-
Download the archive here
. -
Unpack the archive and navigate to the
yc-nbs-export-unpack-<version>folder.Here is an example for version 1.0:
tar -xzf yc-nbs-export-tool.1.0.tar.gz cd yc-nbs-export-unpack-0.1.0 -
Select a binary file matching your system architecture. For a list of available platforms, see
BINARIES.json.System
x64 (Intel/AMD)
ARM64
Linux
bin/linux-x64/bin/linux-arm64/macOS
bin/macos-x64/bin/macos-arm64/Windows
bin/windows-x64/—
For example, on Linux x64, run the following command:
./bin/linux-x64/yc-nbs-export-unpack --helpFor Windows, use PowerShell and the relevant
.exefile:.\bin\windows-x64\yc-nbs-export-unpack.exe --helpThe commands below are for Linux x64. If using a different platform, replace
./bin/linux-x64/yc-nbs-export-unpackwith the path to your binary file.If there is no binary for your platform
Set up a Python environment and install the dependencies:
python3 -m venv .venv source .venv/bin/activate python3 -m pip install -r requirements.txtCheck that the utility starts correctly:
python3 yc-nbs-export-unpack --helpIn the commands below, replace
./bin/linux-x64/yc-nbs-export-unpackwithpython3 yc-nbs-export-unpack.
Set up storage access
Set the S3 access keys using the following environment variables:
export AWS_ACCESS_KEY_ID='<key_ID>'
export AWS_SECRET_ACCESS_KEY='<secret_key>'
# For temporary credentials, also set AWS_SESSION_TOKEN
Substitute <key_id> and <secret_key> with the actual ID and secret key used for bucket access.
Other key provisioning methods
You can save the keys to the ~/.aws/credentials file.
[default]
aws_access_key_id = <key_ID>
aws_secret_access_key = <secret_key>
For temporary keys, add aws_session_token to the same section. To select a named profile, you can use the --s3-profile NAME parameter or the AWS_PROFILE environment variable. To specify a different file path, use the AWS_SHARED_CREDENTIALS_FILE variable.
When using these methods, omit --s3-credentials-file. Unless you explicitly specify a profile with --s3-profile, environment variables will override the ~/.aws/credentials file.
Alternatively, you can create a JSON file:
{
"id": "<key_ID>",
"secret": "<secret_key>"
}
Provide the path to this file using --s3-credentials-file. The JSON file takes precedence over environment variables and cannot be used simultaneously with --s3-profile.
Prepare the encryption key
This step is for encrypted disks only.
-
Download the
<disk_directory>/encrypted.dekand<disk_directory>/kek.idfiles from the bucket. They contain the encrypted data encryption key (DEK) and the ID of the key used to encrypt it. -
Decrypt the DEK using the Yandex Cloud CLI. Your user account must have the
kms.keys.decrypterrole assigned for the specified key.yc kms symmetric-crypto decrypt \ --id <kek_id> \ --profile <profile_name> \ --ciphertext-file encrypted.dek \ --plaintext-file decrypted.dekWhere
<kek_id>is the ID from thekek.idfile, and<profile_name>is the name of your CLI profile.
During the image restoration step, provide the Base64-encoded contents of the decrypted.dek file to the --decryption-key parameter. For example, you can encode it with OpenSSLopenssl base64 -A -in decrypted.dek command.
Restore the image
The utility will read the manifest file and the snapshot or image data from your S3 storage, decrypt them if necessary, and restore the disk contents. You can save the output as a .raw disk image file for import, or write it onto a block device.
To save the image to a file using access keys provided via environment variables, run the following command:
AWS_ACCESS_KEY_ID='<key_ID>' \
AWS_SECRET_ACCESS_KEY='<secret_key>' \
./bin/linux-x64/yc-nbs-export-unpack \
--s3-endpoint <S3_endpoint> \
--s3-region <storage_region> \
--s3-bucket <bucket_name> \
--manifest-key <disk_folder>/manifest.json \
--output <image_file_path> \
--workers 10
Where:
-
AWS_ACCESS_KEY_ID: Bucket access key ID. -
AWS_SECRET_ACCESS_KEY: Bucket secret access key. -
--s3-endpoint: S3 storage endpoint, e.g.,https://storage.yandexcloud.netfor Yandex Object Storage orhttps://s3.ru-7.storage.selcloud.rufor a Selectel bucket. -
--s3-region: Storage region, e.g.,ru-central1for Yandex Object Storage orru-7for a Selectel bucket. -
--s3-bucket: Name of the bucket to which the snapshot or image was exported. -
--manifest-key: Path to themanifest.jsonfile relative to the bucket. Replace<disk_folder>with the path to the folder containing the exported files. -
--output: Path to the file to save the image to, e.g.,my_disk.raw. Make sure this file does not already exist.Instead of a file, you can export the image to a block device.
-
--workers: Number of parallel workers.
For temporary keys, also provide AWS_SESSION_TOKEN.
Examples
Saving the image to a file with keys from a JSON file
./bin/linux-x64/yc-nbs-export-unpack \
--s3-endpoint https://s3.ru-7.storage.selcloud.ru \
--s3-region ru-7 \
--s3-credentials-file my_cred.json \
--s3-bucket disk-snapshot-dr-bucket \
--manifest-key my_disk/manifest.json \
--output my_disk.raw \
--workers 10
Where --s3-credentials-file is the path to the JSON file with the access keys.
Saving the image to a file using a named profile
Add a recovery profile to ~/.aws/credentials:
[recovery]
aws_access_key_id = <key_ID>
aws_secret_access_key = <secret_key>
Provide the profile name to the command:
./bin/linux-x64/yc-nbs-export-unpack \
--s3-endpoint https://s3.ru-7.storage.selcloud.ru \
--s3-region ru-7 \
--s3-profile recovery \
--s3-bucket disk-snapshot-dr-bucket \
--manifest-key my_disk/manifest.json \
--output my_disk.raw \
--workers 10
Where --s3-profile is the name of the profile with the access keys in ~/.aws/credentials. Instead of --s3-profile recovery, you can set the AWS_PROFILE=recovery environment variable if neither AWS_ACCESS_KEY_ID nor AWS_SECRET_ACCESS_KEY is defined. Otherwise, the keys from the environment variables will be used.
Restoring the image to a block device
Warning
Restoration to a block device is supported only on Linux. All existing data on the target block device will be overwritten.
Use the recovery profile and run this command, specifying the target device:
./bin/linux-x64/yc-nbs-export-unpack \
--s3-endpoint https://s3.ru-7.storage.selcloud.ru \
--s3-region ru-7 \
--s3-profile recovery \
--s3-bucket disk-snapshot-dr-bucket \
--manifest-key my_disk/manifest.json \
--device /dev/vdc \
--overwrite-device \
--workers 10
Where:
--s3-profile: Name of the profile with the access keys in~/.aws/credentials.--device: Path to the target block device, e.g.,/dev/vdc.--overwrite-device: Permission to overwrite the device data.
Saving an encrypted disk image to a file
Use the recovery profile and prepare the encryption key. Run this command:
./bin/linux-x64/yc-nbs-export-unpack \
--s3-endpoint https://s3.ru-7.storage.selcloud.ru \
--s3-region ru-7 \
--s3-profile recovery \
--s3-bucket disk-snapshot-dr-bucket \
--manifest-key my_disk/manifest.json \
--output my_disk.raw \
--decryption-key "$(openssl base64 -A -in decrypted.dek)" \
--workers 10
Where --decryption-key is the Base64-encoded content of the decrypted.dek file, generated with OpenSSL