Copying objects
Object Storage supports server-side object copy.
If encryption in a bucket is disabled, objects will be copied to server-side buckets. The host on which the copy operation is run and Object Storage exchange nothing but object keys. No fee is charged for the copying traffic in this case because the traffic is internal for the object storage. However, you are charged for copy requests.
If bucket objects are encrypted, first they will be copied to the host that executes the command and then uploaded to the target bucket.
Large objects uploaded using multipart uploads are stored in the bucket in parts. They are copied by invoking copyPart for each part. Therefore, multipart objects cost more to copy than regular ones.
You can copy either the entire bucket contents or an individual bucket object.
To work with objects in an encrypted bucket, a user or service account must have the following roles for the encryption key in addition to the storage.configurer
role:
kms.keys.encrypter
: To read the key, encrypt, and upload objects.kms.keys.decrypter
: To read the key, decrypt, and download objects.kms.keys.encrypterDecrypter
: Includes thekms.keys.encrypter
andkms.keys.decrypter
permissions.
For more information, see Key Management Service service roles.
Copying a single object
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
View the description of the CLI command to upload an object to a bucket:
yc storage s3api copy-object --help
-
Get a list of buckets in the default folder:
yc storage bucket list
Result:
+------------------+----------------------+-------------+-----------------------+---------------------+ | NAME | FOLDER ID | MAX SIZE | DEFAULT STORAGE CLASS | CREATED AT | +------------------+----------------------+-------------+-----------------------+---------------------+ | first-bucket | b1gmit33ngp6******** | 53687091200 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+-------------+-----------------------+---------------------+
-
Run this command:
yc storage s3api copy-object \ --copy-source <source_bucket>/<object_key> \ --bucket <target_bucket> \ --key <object_key>
Where:
--copy-source
: Name of the source bucket and object key you need to copy.--bucket
: Name of the bucket to copy the object to.--key
: Key to use for storing the object in the bucket.
Result:
copy_object_result: etag: '"d41d8cd98f00b204e9800998********"' last_modified_at: "2024-10-08T14:21:41.628Z" request_id: 61523025******** copy_source_version_id: "null"
-
If you do not have the AWS CLI yet, install and configure it.
-
Run this command:
aws --endpoint-url=https://storage.yandexcloud.net/ \ s3 cp s3://<source_bucket>/<object_key> s3://<target_bucket>/<object_key>
Where:
--endpoint-url
: Object Storage endpoint.s3 cp
: Copy object command.
Result:
copy: s3://<source_bucket>/<object_key> to s3://<target_bucket>/<object_key>
For more information about the
aws s3 cp
command, see the AWS CLI Command Reference .
Copying all bucket objects to another bucket
-
If you do not have the AWS CLI yet, install and configure it.
-
Run this command:
aws --endpoint-url=https://storage.yandexcloud.net/ \ s3 cp --recursive s3:<source_bucket>/ s3:<target_bucket>/
Where:
--endpoint-url
: Object Storage endpoint.s3 cp
: Copy object command.--recursive
: Parameter for copying all objects from the source bucket.
For more information about the
aws s3 cp
command, see the AWS CLI Command Reference .
All objects from the source bucket will be copied to the target bucket.
Note
You can copy objects between buckets either within a single cloud or between different clouds. To do this, make sure your service account has write permissions for both buckets.