You can copy an object from a source bucket to a destination bucket in the same region, or to a different folder within the same bucket, without changing its content. Use the ossutil cp command to copy objects.
Precautions
To copy objects, you must have the
oss:GetObject,oss:ListObjects, andoss:PutObjectpermissions. For more information, see Grant custom permissions to a RAM user.Only objects can be copied. Unmerged parts cannot be copied.
By default, the tags and object attributes are copied. You can use the --copy-props option to set rules for copying properties and tags.
Cross-account and cross-region copy operations are not supported. To copy or migrate objects across accounts or regions, use ossimport or Data Online Migration.
Command format
ossutil cp oss://src_bucket[/src_prefix] oss://dest_bucket[/dest_prefix] [flags]Parameter | Type | Description |
src_bucket | string | The name of the source bucket. |
src_prefix | string | A folder or a specified prefix in the source bucket. |
dest_bucket | string | The name of the destination bucket. |
dest_prefix | string | A folder or a specified prefix in the destination bucket. |
--acl | string | The access control list (ACL) of the object. Valid values:
|
--bandwidth-limit | SizeSuffix | Limits the network bandwidth to control the data transfer rate. The minimum value is 1024 B/s. The default unit is B/s. When you configure this parameter, you can specify a unit for the bandwidth value, such as B (byte), K (kilobyte), M (megabyte), or G (gigabyte). For example, 50 M specifies a bandwidth limit of 50 MB/s. |
--bigfile-threshold | SizeSuffix | The threshold to enable multipart upload, download, or copy for large files. The default value is 104857600. |
--cache-control | string | Specifies the web page caching behavior when the object is downloaded. |
--checkers | int | The number of checkers that run in parallel. The default value is 16. |
--checkpoint-dir | string | The directory that stores checkpoint information for resumable transfers. The default value is |
--checksum | / | Copies only source objects whose size or checksum (if one exists) is different from the destination object. This option is valid only for object-to-object copy operations. |
--content-disposition | string | Specifies how the object is displayed. |
--content-encoding | string | Specifies the codec of the object. |
--content-type | string | The content type of the object. |
--copy-props | string | Sets the rules for copying properties and tags during object-to-object copy operations. The following settings are supported:
|
-d, --dirs | string | Processes files and subdirectories in the current directory, but does not recursively process all files in all subdirectories. |
--encoding-type | string | The encoding type of the input object name or file name. Valid value: url. |
--end-with | string | Returns objects that are alphabetically before or the same as the specified value. |
--exclude | stringArray | The exclusion rules for paths or file names. |
--exclude-from | stringArray | Reads exclusion rules from a rule file. |
--expires | string | Specifies the absolute expiration time for the cached content. |
--files-from | stringArray | Reads the list of source file names from a file. Empty lines or comment lines are ignored. |
--files-from-raw | stringArray | Reads the list of source file names from a file. |
--filter | stringArray | The filtering rules for paths or file names. |
--filter-from | stringArray | Reads filtering rules from a rule file. |
-f, --force | / | Forces the operation without a confirmation prompt. |
--ignore-existing | / | Skips existing destination objects. |
--include | stringArray | The inclusion rules for paths or file names. |
--include-from | stringArray | Reads inclusion rules from a rule file. |
-j, --job | int | The number of concurrent tasks. The default value is 3. Note This option takes effect only when you specify the |
--list-objects | / | Uses the ListObjects API operation to list objects. |
--max-size | SizeSuffix | Limits the maximum size of the object to transfer. The default unit is byte. You can also use a unit suffix, such as B, K, M, G, T, or P. 1 K (KiB) = 1024 B. |
--metadata | strings | Specifies the user metadata of the object in the key=value format. |
--metadata-directive | string | Specifies how to set the metadata of the destination object. Valid values:
|
--metadata-exclude | stringArray | The exclusion rules for object metadata. |
--metadata-filter | stringArray | The filtering rules for object metadata. |
--metadata-filter-from | stringArray | Reads object metadata filtering rules from a rule file. |
--metadata-include | stringArray | The inclusion rules for object metadata. |
--min-age | Duration | Copies only objects that were modified before the specified time interval. The default unit is second. You can use a unit suffix. For example, 1h specifies 1 hour. Note
|
--max-age | Duration | Copies only objects that were modified within the specified time interval. The default unit is second. You can use a unit suffix. For example, 1h specifies 1 hour. Note
|
--min-mtime | Time | Copies only objects that were modified after the specified time. The time must be in UTC format, such as 2006-01-02T15:04:05. Note
|
--max-mtime | Time | Copies only objects that were modified before the specified time. The time must be in UTC format, such as 2006-01-02T15:04:05. |
--min-size | SizeSuffix | Limits the minimum size of the object to transfer. The default unit is byte. You can also use a unit suffix, such as B, K, M, G, T, or P. 1 K (KiB) = 1024 B. |
--no-progress | / | Does not display the progress bar chart. |
--no-error-report | / | Does not generate an error report file during batch processing. |
--output-dir | string | Specifies the directory where the error report file generated during batch processing is stored. The default value is |
--page-size | int | The maximum number of objects to list per page during a batch copy operation. The default value is 1000. The value must be between 1 and 1000. |
--parallel | int | The number of concurrent tasks for operations on a single object. |
--part-size | SizeSuffix | The part size. By default, ossutil calculates an appropriate part size based on the object size. The value must be between 100 KiB and 5 GiB. |
-r, --recursive | / | Performs the operation recursively. When you specify this option, the command is applied to all matching objects in the bucket. Otherwise, the command is applied only to the object specified by the path. |
--request-payer | string | The payment method for the request. Set this parameter to `requester` if you use the pay-by-requester mode. |
--size-only | / | Copies only source objects whose size is different from the destination object. |
--start-after | string | Returns objects that are alphabetically after the specified value. |
--storage-class | string | The storage class of the object. Valid values:
|
--tagging | string | Specifies the tags of the object in the key=value format. |
--tagging-directive | string | Specifies how to set the tags of the destination object. Valid values:
|
-u, --update | / | Copies only source objects that are newer than the destination objects. |
For more information, see Command-line options.
The naming of the destination object is determined by the following rules:
If `dest_prefix` is empty when you copy a single file, the object name is the relative path of the source file.
When you copy a single file, if `dest_prefix` ends with a `/`, the object name is formed by appending the relative path of the source file to `dest_prefix`.
When you copy a single file, if `dest_prefix` does not end with a forward slash (/), the destination is named `dest_prefix`.
For batch copy operations, if `dest_prefix` ends with a forward slash (/), the object name is `dest_prefix` followed by the relative path of the source file.
In a batch copy operation, if `dest_prefix` does not end with a forward slash (/), the object name is `dest_prefix` + "/" + the relative path of the source file.
Usage examples
Copy a single object
ossutil cp oss://examplebucket1/examplefile.txt oss://examplebucket1/desfolder/Copy objects incrementally
During a batch copy operation, if you specify the --update option, ossutil copies an object only if the destination object does not exist or if the source object was modified more recently than the destination object. The command is as follows:
ossutil cp oss://examplebucket1/srcfolder1/ oss://examplebucket1/desfolder/ -r --updateThis option lets you skip successfully copied objects and perform an incremental copy when you retry a failed batch copy operation.
Rename an object
ossutil cp oss://examplebucket1/examplefile.txt oss://examplebucket1/example.txtWhen you use the cp command to rename an object, the source object is not deleted. You must manually delete the source object if it is no longer needed.
Modify the tags of an object
ossutil cp oss://examplebucket1/examplefile.txt oss://examplebucket1/ --tagging "abc=1&bcd=2&..."