Transferring a Yandex Compute Cloud disk image to a third-party provider's S3-compatible storage with an intermediate VM
You can save a byte-for-byte backup of your 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 guide, you will create a disk from a snapshot, connect it to an auxiliary Linux VM, and upload the disk or partition image with the help of s3fs, dd, and gzip. The result will be a compressed image in a .img.gz file. Creating and starting the VM based on a different provider will require a separate recovery.
Note
The example used a private Selectelru-7 region. For a different S3-compatible storage, replace the connection properties and check out the provider's requirements related to access and object sizes.
To transfer a disk image to an S3-compatible storage of a third-party provider:
- Prepare a bucket and access to it.
- Prepare a disk backup and an auxiliary VM.
- Install the utilities and save the key.
- Connect the bucket.
- Select a device and upload the image.
- Check the image in the storage.
- Complete the transfer.
- Restore the image to a separate disk.
If you no longer need the resources you created, delete them.
Prepare a bucket and set up bucket access
-
Create
a bucket in Selectel:-
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 used in the bucket connection command below. -
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. -
Give the service user permissions for the correct project and bucket:
- Object reading and writing.
- Viewing bucket contents.
- Multipart upload operations.
Requirements for roles are detailed in the s3fs connection guide
. -
Save
Access keyandSecret keyto a secure location. You will need them on the auxiliary VM.
Prepare a disk backup and an auxiliary VM
- If you do not yet have a snapshot of the disk you want to transfer to another cloud provider, create one.
- Create an auxiliary Ubuntu or Debian VM or use an existing one. Make sure you have HTTPS access to the Selectel endpoint.
- Create a disk from the snapshot in the same availability zone as the auxiliary VM.
- Connect the new disk to the auxiliary VM as an extra one.
- Connect to the auxiliary VM over SSH.
Warning
s3fs uses temporary files and local cache. Recording via gzip does not guarantee there will be no local buffering. Check for free space in /tmp or in the directory set by the tmpdir parameter of the s3fs utility: allow for a buffer up to the size of the uploaded compressed image.
Install the utilities and save the key
Execute the following commands until the end of the upload on the auxiliary VM in the same Bash session under root.
-
Open the session and install the utilities:
sudo -i apt-get update apt-get install -y s3fs gzip set -o pipefail umask 077pipefailwill allow you to detect thedderror even if the nextgzipcommand ends successfully. -
Enter the access keys for the external bucket:
read -r -p "Access key: " S3_ACCESS_KEY read -r -p "Secret key: " S3_SECRET_KEY printf "\n" printf "%s:%s\n" "$S3_ACCESS_KEY" "$S3_SECRET_KEY" \ > "$HOME/.passwd-s3fs" unset S3_ACCESS_KEY S3_SECRET_KEY chmod 600 "$HOME/.passwd-s3fs"In this session, the
~/.passwd-s3fsfile resides at/root/.passwd-s3fs.
Connect the bucket
-
Create a mount directory:
mkdir -p /dr-s3mount -
Mount the bucket:
s3fs disk-snapshot-dr-bucket /dr-s3mount \ -o passwd_file="$HOME/.passwd-s3fs" \ -o endpoint=ru-7 -o url=https://s3.ru-7.storage.selcloud.ru \ -o use_path_request_style -o max_dirty_data=512 -o ensure_diskfree=2048 mountpoint /dr-s3mountCompare the region (
endpoint) and S3 API endpoint (url) with the parameters on your bucket's connection tab. For a different provider, replace bucket name, region, and endpoint. Other s3fs parameters are described in the project reference.
Continue only after a successful mountpoint check.
Select a device and upload the image
-
View connected devices:
lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,MODEL,SERIALCompare the size and ID with the disk info. The
/dev/vda1device represents only the partition, whereas/dev/vda, the whole disk including the partition table. The connected disk's name may be different on the auxiliary VM. -
Upload the image. The example shows the
/dev/vda1partition: replaceSOURCEwith a tried path to the disk or partition of interest.SOURCE=/dev/vda1 IMAGE="$(hostname).$(basename "$SOURCE").$(date -u +%Y%m%dT%H%M%SZ).img.gz" export IMAGE dd if="$SOURCE" bs=4M status=progress | gzip -c > "/dr-s3mount/$IMAGE"pipefailallows you to detect thedderror even ifgzipends successfully. In the event of a failure, the object may remain incomplete, so do not use it for recovery.hostnamein the file name refers to the auxiliary VM. Write the source disk ID separately.
Check the image in the storage
-
Unmount the bucket:
cd /root umount /dr-s3mountIf unmount ends with an error, fix the error before you continue.
-
Connect the bucket again using the command from Connect the bucket. Reconnecting allows you to check the saved object, not the local cache data from the previous mount.
-
In the Selectel control panel, make sure the object has appeared in the bucket, has a non-zero size, and its storage class is as selected.
-
You can check the downloaded archive for integrity on another target VM:
gzip -t "img_file.gz"Specify the name of the downloaded file instead of
img_file.gz. The command reads the archive as a whole and checks it for integrity. This may take time. Be aware of the external provider's reading and outbound traffic charges.
Complete the transfer
Unmount the bucket on the auxiliary VM:
umount /dr-s3mount
Save the object name, source device, disk size, and backup time. Before you delete the source disk, do a trial recovery to a separate disk: gzip's integrity by itself does not prove that the system is able to load correctly.
Restore the image to a separate disk
This method writes the image content to the target device byte for byte. Restore the whole disk image to a whole disk, and the partition image to a separate partition. The target disk or partition must be at least the size of the source.
Alert
All the target device data will be overwritten. If you are restoring a whole disk image, its partition table will be overwritten as well. A separate partition image does not contain the partition table of the source disk.
-
Download
.img.gzto a Linux VM, connect the target disk and identify its name:lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS,MODEL,SERIALMake sure you selected an extra disk, not the VM's boot disk. The disk and its partitions must not be mounted. Unmount them before writing.
-
Run the commands in Bash. Specify the name of the downloaded archive instead of
IMAGE. Replace/dev/REPLACE_MEwith the target disk, e.g.,/dev/vdc, if using the whole disk image, or with the target partition, e.g.,/dev/vdc1, if using a partition image:set -o pipefail IMAGE="node3.vdb.20261012T082919Z.img.gz" TARGET="/dev/REPLACE_ME" # Checking the archive for integrity before writing. gzip -t "$IMAGE" || exit 1 # Unpacking directly to the disk without an .img in between. if ! gzip -dc "$IMAGE" | sudo dd of="$TARGET" bs=4M iflag=fullblock conv=fsync status=progress then echo "Restoration error. The target disk may be incomplete." exit 1 fi echo "The image has been written to the disk."
How to delete temporary resources
Once the restoration is successfully tested, you can delete the unused resources: