All Products
Search
Document Center

Object Storage Service:Copy objects

Last Updated:Oct 14, 2024

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. In ossutil, you can use the cp command to copy objects.

Usage notes

  • To copy an object, you must have the oss:GetObject, oss:ListObjects, and oss:PutObject permissions. For more information, see Attach a custom policy 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 objects across Alibaba Cloud accounts or regions, use ossimport or Data Online Migration.

Command syntax

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

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 destination bucket.

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 destination object. Valid values:

  • private: private

  • public-read: public-read

  • public-read-write: public-read-write

  • default: inherited from the bucket

--bigfile-threshold

int

The object size threshold for multipart copy. Default value: 104857600.

--cache-control

string

The caching behavior of the web page 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 file of the multipart copy task is stored. Default value: .ossutil_checkpoint/.

--checksum

/

Specifies that only when one of the following conditions are 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 method is only used for copying objects from one bucket to another.

--content-disposition

string

The display form of the destination object.

--content-encoding

string

The encoding method used to encode the destination object.

--content-type

string

The content type of the destination object.

--copy-props

string

Specifies whether to copy the attributes and tags when the source object is copied. Valid values:

  • default: copies the object attributes and tags. This is the default value. The object attributes include content-type, content-language, content-encoding, content-disposition, cache-control, expires, and metadata (user metadata).

  • metadata: copies only the object attributes.

  • none: copies only data and does not copy the object attributes or tags.

-d, --dirs

string

Specifies that the objects and subdirectories in the current directory are returned.

--encoding-type

string

The encoding method used to encode the destination object name. Valid value: url.

--end-with

string

Specifies that objects whose names are alphabetically before or the same as the value of the --end-with parameter are returned.

--exclude

stringArray

The exclusion rule for the path or object name.

--exclude-from

stringArray

Specifies that the exclusion rule is read from the rules file.

--expires

stringArray

The absolute expiration time of the cached content.

--files-from

stringArray

Specifies that the object names are read from the rules file, and empty lines or comment lines are ignored.

--files-from-raw

stringArray

Specifies that the object names are read from the rules file.

--filter

stringArray

The filter rule for the path or object name.

--filter-from

stringArray

Specifies that the filter rule for the path or object name is read from the rules file.

-f, --force

/

Specifies that the command is forcibly run without a prompt for confirmation.

--include

stringArray

The inclusion rule for the path or object name.

--include-from

stringArray

Specifies that the inclusion rule is read from the rules file.

-j, --job

int

The number of concurrent tasks that can be performed on multiple objects. Default value: 3.

--list-objects

/

Specifies that the ListObjects operation is called to list objects.

--max-age

Duration

Specifies that the objects whose last modified time is earlier than the value of the --max-age parameter are not transferred. The default unit is seconds. The unit can be milliseconds, seconds, minutes, hours, days, weeks, months, or years. By default, this parameter is left empty.

--max-mtime

Time

Specifies that the objects whose last modified time is later than the value of the --max-mtime parameter are not transferred. The value is in UTC. By default, this parameter is left empty.

--max-size

SizeSuffix

Specifies the maximum size of the object that can be transferred. The default unit is bytes. The unit of object size can be bytes, KiB, MiB, GiB, TiB, or PiB. Note: 1 KiB = 1024 bytes.

--metadata

strings

The user metadata of the destination object in the key=value format.

--metadata-directive

string

The method used to configure the metadata of the destination object. Valid values:

  • COPY

  • REPLACE

--metadata-exclude

stringArray

The exclusion rule for object metadata.

--metadata-filter

stringArray

The filter rule for object metadata.

--metadata-filter-from

stringArray

Specifies that the filter rule for object metadata is read from the rules file.

--metadata-include

stringArray

The inclusion rule for object metadata.

--min-age

Duration

Excludes objects whose last modified time is later than the value of this option. The default unit is s (seconds). You can suffix the numerical value with a unit: ms for milliseconds, s for seconds, m for minutes, h for hours, d for days, w for weeks, M for months, or y for years. By default, this parameter is left empty.

--min-mtime

Time

Specifies that the objects whose last modified time is earlier than the value of the --min-mtime parameter are not transferred. The value is in UTC. By default, this parameter is left empty.

--min-size

SizeSuffix

Specifies the minimum size of the object that can be transferred. The default unit is bytes. The unit of object size can be bytes, KiB, MiB, GiB, TiB, or PiB. Note: 1 KiB = 1024 bytes.

--no-progress

/

Specifies that the progress bar is not displayed.

--page-size

int

The maximum number of objects that can be returned. 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. Valid values: 100 KiB to 5 GiB.

-r, --recursive

/

Specifies that the command is recursively run on objects. If this parameter is specified, the command takes effect on all objects that meet the conditions in the bucket. Otherwise, the command takes effect on only the objects in the specified path.

--request-payer

string

Specifies the payer of the request. If pay-by-requester is enabled for the bucket, set this parameter to requester.

--size-only

/

Specifies that only when the size of the source object is different from that of the destination object, the source object is copied.

--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 destination object. Valid values:

  • Standard

  • IA

  • Archive

  • ColdArchive

  • DeepColdArchive

--tagging

strings

The tags of the destination object in the key=value format.

--tagging-directive

string

The method used to configure the tags of the destination object. Valid values:

  • COPY

  • REPLACE

-u, --update

/

Specifies that only when the last modified time of the source object is later than that of the destination object, the source object is copied.

--ignore-existing

/

Skips objects that already exist.

Note

For more information, see Command-line options.

The naming rules for the destination object:

  • 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

    If you specify the --update parameter when you copy multiple source objects, ossutil copies the source objects only when the destination objects do not exist or the last modified time of the source objects is later than that of the destination objects. Sample command:

    ossutil cp oss://examplebucket1/srcfolder1/ oss://examplebucket1/desfolder/ -r --update

    This parameter can be used to skip copied objects and copy only objects that fail to be copied.

  • Rename an object

    ossutil cp oss://examplebucket1/examplefile.txt oss://examplebucket1/example.txt 

    When you run the cp command to rename an object, the original object still exists. You can delete the original object after you rename the object.

  • Modify the tags of an object

    ossutil cp oss://examplebucket1/examplefile.txt oss://examplebucket1/ --tagging "abc=1&bcd=2&……"