You can copy objects to another directory in the same Object Storage Service (OSS) bucket or to another bucket that is located in the same region as the source bucket without changing the object content. You can use the cp command of ossutil to copy objects.
Considerations
To copy objects, you must have the
oss:GetObject
,oss:ListObjects
, andoss:PutObject
permissions. For more information, see Grant custom permissions to a RAM user.You can use the cp command to copy objects, but not parts.
By default, both tags and object attributes are copied. You can use the --copy-props option to specify copy rules for attributes and tags.
You cannot use the cp command to copy objects across Alibaba Cloud accounts or regions. If you want to copy (migrate) objects across Alibaba Cloud accounts or regions, use ossimport or Data Online Migration.
Syntax
ossutil cp oss://src_bucket[/src_prefix] oss://dest_bucket[/dest_prefix] [flags]
Parameter | Type | Description |
src_bucket | string | The name of the bucket in which the resources that you want to list are stored. |
src_prefix | string | The directory in which the source object is stored or the prefix contained in the name of the source object. |
dest_bucket | string | The name of the bucket in which the resources that you want to list are stored. |
dest_prefix | string | The directory in which you want to store the destination object or the prefix contained in the name of the destination object. |
--acl | string | The access control list (ACL) of the object. Valid values:
|
--bigfile-threshold | int | The object size threshold for multipart upload, download, and copy. Default value: 104857600. |
--cache-control | string | The caching behavior in web browsers when the object is downloaded. |
--checkers | int | The number of checkers that you want to run in parallel. Default value: 16. |
--checkpoint-dir | string | The directory in which the checkpoint information is stored. Default value: |
--checksum | / | Specifies that only when one of the following conditions is met, the source object is copied: a. the size of the source object is different from that of the destination object; b. the CRC-64 of the source object is different from that of the destination object, but the size of the source object is the same as that of the destination object. This parameter takes effect only for object copy operations. |
--content-disposition | string | The display form of the object. |
--content-encoding | string | The encoding method of the object. |
--content-type | string | The content type of the object. |
--copy-props | string | Specifies whether to copy the attributes and tags when the source object is copied. Valid values:
|
-d, --dirs | string | Lists objects and subdirectories in the current directory, instead of recursively displaying all objects in all subdirectories. |
--encoding-type | string | The encoding method used to encode the object name. Valid value: url. |
--end-with | string | Matches objects whose names are lexicographically before the specified value (inclusive). |
--exclude | stringArray | Specifies an exclusion rule for paths or object names. |
--exclude-from | stringArray | Reads the exclusion rule from a file. |
--expires | stringArray | The absolute expiration time of the cached content. |
--files-from | stringArray | Reads a list of source objects from a file, with empty lines and comment lines ignored. |
--files-from-raw | stringArray | Reads a list of source objects from a file. |
--filter | stringArray | Specifies a filter rule for paths or object names. |
--filter-from | stringArray | Reads the filter rule for the path or object name from a file. |
-f, --force | / | Forces the operation without requiring user confirmation. |
--include | stringArray | Specifies an inclusion rule for paths or object names. |
--include-from | stringArray | Reads the inclusion rule from a file. |
-j, --job | int | The number of concurrent tasks that can be performed across multiple objects. Default value: 3. |
--list-objects | / | Specifies that the ListObjects operation is called to list objects. |
--max-size | SizeSuffix | The maximum size of a file or object that can be transferred. By default, the size is in bytes (B). You can suffix the numerical value with a 1024-based unit: B for byte, K for Kibibyte, M for Mebibyte, G for Gibibyte, T for Tebibyte, or P for Pebibyte. |
--metadata | strings | The user metadata of the object in the key=value format. |
--metadata-directive | string | The method used to configure the metadata of the destination object. Valid values:
|
--metadata-exclude | stringArray | The exclusion rule for object metadata. |
--metadata-filter | stringArray | The filter rule for object metadata. |
--metadata-filter-from | stringArray | Reads the metadata filter rule from a file. |
--metadata-include | stringArray | The inclusion rule for object metadata. |
--min-age | Duration | Copies only files that were modified before the specified time interval. The default unit is seconds. You can use a unit suffix. For example, 1h indicates one hour. Note
|
--max-age | Duration | Copies only files that were modified within the specified time interval. The default unit is seconds. You can use a unit suffix. For example, 1h indicates one hour. Note
|
--min-mtime | Time | Copies only files that were modified after the specified time. The time format is UTC. For example, 2006-01-02T15:04:05. Note
|
--max-mtime | Time | Copies only files that were modified before the specified time. The time format is UTC. For example, 2006-01-02T15:04:05. |
--min-size | SizeSuffix | The minimum size of a file or object that can be transferred. By default, the size is in bytes (B). You can suffix the numerical value with a 1024-based unit: B for byte, K for Kibibyte, M for Mebibyte, G for Gibibyte, T for Tebibyte, or P for Pebibyte. |
--no-progress | / | Does not display the progress bar. |
--page-size | int | The maximum number of objects that can be returned per page. Default value: 1000. Valid values: 1 to 1000. |
--parallel | int | The number of concurrent tasks for internal operations on a single object. |
--part-size | SizeSuffix | The part size. By default, ossutil calculates the appropriate part size based on the object size. The part size ranges from 100 KiB to 5 GiB. |
-r, --recursive | / | If this parameter is specified, the cp command takes effect on all objects that meet the conditions in the bucket. Otherwise, the cp command takes effect only on the objects in the specified path. |
--request-payer | string | The payer of the request. If pay-by-requester is enabled, set this parameter to requester. |
--size-only | / | Copies a source object only if it has a different size from the destination object. |
--start-after | string | Specifies that objects whose names are alphabetically after the value of the --start-after parameter are returned. |
--storage-class | string | The storage class of the object. Valid values:
|
--tagging | strings | The object tags in key=value pairs. |
--tagging-directive | string | The method used to set tags for the destination object. Valid values:
|
-u, --update | / | Copies a source object only if its last modified time is later than that of its destination object. |
--ignore-existing | / | Ignores existing destination objects. |
For more information, see Command-line options.
The name of a destination object follows these rules:
If a source object is copied and the dest_prefix parameter is not specified, the name of the destination object is the relative path of the source object.
If a source object is copied and the value of the dest_prefix parameter ends with a forward slash (/), the name of the destination object is in the following format: the value of the dest_prefix parameter + the relative path of the source object.
If a source object is copied and the value of the dest_prefix parameter does not end with a forward slash (/), the name of the destination object is the value of the dest_prefix parameter.
If multiple source objects are copied and the value of the dest_prefix parameter ends with a forward slash (/), the names of the destination objects are in the following format: the value of the dest_prefix parameter + the relative paths of the source objects.
If multiple source objects are copied and the value of the dest_prefix parameter does not end with a forward slash (/), the names of the destination objects are in the following format: the value of the dest_prefix parameter + / + the relative paths of the source objects.
Examples
Copy a single object
ossutil cp oss://examplebucket1/examplefile.txt oss://examplebucket1/desfolder/
Copy incremental objects
When you copy multiple objects, if you specify the --update option, ossutil copies a source object only if the destination object does not exist or the last modified time of the source object is later than that of the destination object. You can run the following command to copy incremental objects:
ossutil cp oss://examplebucket1/srcfolder1/ oss://examplebucket1/desfolder/ -r --update
This option can be used to skip copied objects and copy only objects that fail to be copied.
Rename objects
ossutil cp oss://examplebucket1/examplefile.txt oss://examplebucket1/example.txt
When you use the cp command to rename an object, the original object still exists. You can delete the original object after you rename it.
Modify the tags of an object
ossutil cp oss://examplebucket1/examplefile.txt oss://examplebucket1/ --tagging "abc=1&bcd=2&……"