Updated on 2022-05-18 GMT+08:00

Copying an Object

Function

You can use this command to copy a single object or copy objects in batches by a specified object name prefix.

  • Do not change the source objects in the OBS bucket when copying a single object or objects in batches. Otherwise, the operation may fail or data may be inconsistent.
  • To copy objects, you must have the read permission on the objects to be copied and the write permission on the destination bucket.
  • If the client-side cross-region replication function is not enabled, ensure that the source bucket and destination bucket are in the same region.
  • If the source bucket is a parallel file system (supporting POSIX), the destination bucket must also be a parallel file system.

Command Line Structure

  • In Windows
    • Copying a single object
      obsutil cp obs://srcbucket/key obs://dstbucket/[dest] [-dryRun][-u] [-crr] [-vlength] [-vmd5] [-p=1] [-threshold=52428800] [-versionId=xxx] [-acl=xxx] [-sc=xxx] [-meta=aaa:bbb#ccc:ddd] [-ps=auto] [-cpd=xxx] [-fr] [-o=xxx] [-config=xxx] 
    • Copying objects in batches
      obsutil cp obs://srcbucket[/key] obs://dstbucket[/dest] -r [-dryRun][-f] [-flat] [-u] [-crr] [-vlength] [-vmd5] [-j=1] [-p=1] [-threshold=52428800] [-acl=xxx] [-sc=xxx] [-meta=aaa:bbb#ccc:ddd] [-ps=auto] [-include=*.xxx] [-exclude=*.xxx] [-timeRange=time1-time2] [-mf] [-o=xxx] [-cpd=xxx] [-config=xxx] 
  • In Linux or macOS
    • Copying a single object
      ./obsutil cp obs://srcbucket/key obs://dstbucket/[dest] [-dryRun] [-u] [-crr] [-vlength] [-vmd5] [-p=1] [-threshold=52428800] [-versionId=xxx] [-acl=xxx] [-sc=xxx] [-meta=aaa:bbb#ccc:ddd] [-ps=auto] [-cpd=xxx] [-fr] [-o=xxx] [-config=xxx] 
    • Copying objects in batches
      ./obsutil cp obs://srcbucket[/key] obs://dstbucket[/dest] -r [-dryRun] [-f] [-flat] [-u] [-crr] [-vlength] [-vmd5] [-j=1] [-p=1] [-threshold=52428800] [-acl=xxx] [-sc=xxx] [-meta=aaa:bbb#ccc:ddd] [-ps=auto] [-include=*.xxx] [-exclude=*.xxx] [-timeRange=time1-time2] [-mf] [-o=xxx] [-cpd=xxx] [-config=xxx] 
  • The source path and destination path cannot be the same.
  • The source path and destination path cannot be partly overlapped either. If the source path overlaps with the prefix of the destination path, recursive replication applies. If the destination path overlaps with the prefix of the source path, the replication may overwrite objects in the source path.

Examples

  • Take the Windows OS as an example. Run the obsutil cp obs://bucket-test/key obs://bucket-test2 command to copy a single object.
    obsutil cp obs://bucket-test/key obs://bucket-test2
    
    Parallel:      3                   Jobs:          3
    Threshold:     524288000           PartSize:      5242880
    Exclude:                           Include:
    VerifyLength:  false               VerifyMd5:     false
    CheckpointDir: xxxx
    
    [=====================================================] 100.00% 6/s 0s
    Copy successfully, 19B, obs://bucket-test/key --> obs://bucket-test2/key
    ext.txt
  • Take the Windows OS as an example. Run the obsutil cp obs://bucket-test/temp/ obs://bucket-test2 -f -r command to copy objects in batches.
    obsutil cp obs://bucket-test/temp/ obs://bucket-test2 -r -f
    
    Parallel:      3                   Jobs:          3
    Threshold:     524288000           PartSize:      5242880
    Exclude:                           Include:
    VerifyLength:  false               VerifyMd5:     false
    CheckpointDir: xxxx
    OutputDir: xxxx
    
    
    [=============================================================] 100.00% 10/s 0s
    Succeed count is:   5         Failed count is:    0
    Metrics [max cost:298 ms, min cost:192 ms, average cost:238.00 ms, average tps:9.71]
    Task id is: 0476929d-9d23-4dc5-b2f8-0a0493f027c5
  • For more examples, see Copy.

Parameter Description

Parameter

Optional or Mandatory

Description

srcbucket

Mandatory

Source bucket name

dstbucket

Mandatory

Destination bucket name

dest

Optional

Indicates the destination object name when copying an object, or the name prefix of destination objects when copying objects in batches.

key

Mandatory for copying an object.

Optional for copying objects in batches.

Indicates the source object name when copying an object, or the name prefix of source objects when copying objects in batches.

The rules are as follows:

  • This parameter cannot be left blank when copying an object. If dest is left blank, the source object is copied to the root directory of the destination bucket. If the value of dest ends with a slash (/), the destination object name is the value of dest plus the source object name. Otherwise, the destination object name is the value of dest.
  • If this parameter is left blank when copying objects in batches, all objects in the source bucket are copied. If not, objects whose name prefix is the set value in the source bucket are copied. The rules for confirming the name of the destination object are as follows:
    • If the value of dest ends with a slash (/), the destination object name is the value of dest plus the source object name.
    • If the value of dest does not end with a slash (/), the destination object name is the value of dest/source object name.
NOTE:
  • If this parameter is configured but the flat parameter is not when copying objects in batches, the name of the source object contains the name prefix of the parent object. If flat is configured, then the name of the source object does not contain the name prefix of the parent object.
  • For details about how to use this parameter, see Copy.

fr

Optional for copying an object (additional parameter)

Generates an operation result list when copying an object.

flat

Optional for copying objects in batches (additional parameter)

The name prefix of the parent object is excluded when copying objects in batches.

dryRun

Optional (additional parameter)

Conducts a dry run.

crr

Optional (additional parameter)

Enables the client-side cross-region replication function. In this mode, data is directly copied to the destination bucket from the source bucket through data stream. The buckets can by any two OBS buckets.

NOTE:
  • If this parameter is configured, ensure that the configuration of client-side cross-region replication is updated in the configuration file. For details, see Updating a Configuration File.
  • The configurations of the source bucket and destination bucket are respectively akCrr/skCrr/tokenCrr/endpointCrr and ak/sk/token/endpoint in the configuration file.
NOTICE:

After this function is enabled, both upload and download bandwidth are occupied.

vlength

Optional (additional parameter)

Verifies whether the object size in the destination bucket is the same as that in the source bucket after the copy task completes.

NOTE:

This parameter must be used together with crr.

vmd5

Optional (additional parameter)

Verifies whether the MD5 value of the destination bucket is the same as that of the source bucket after the copy task completes.

NOTE:
  • This parameter must be used together with crr.
  • Objects in the source bucket must contain metadata x-obs-md5chksum. Otherwise, MD5 verification will be skipped.

    After the MD5 value verification is successful, the parameter value is set to the destination object metadata x-obs-md5chksum, which is used for later MD5 verification during download or copy.

u

Optional (additional parameter)

Indicates incremental copy. If this parameter is set, each object can be copied only when it does not exist in the destination bucket, its size is different from the namesake one in the destination bucket, or it has the latest modification time.

p

Optional (additional parameter)

Indicates the maximum number of concurrent multipart copy tasks when copying an object. The default value is the value of defaultParallels in the configuration file.

threshold

Optional (additional parameter)

Indicates the threshold for enabling multipart copy, in bytes. The default value is the value of defaultBigfileThreshold in the configuration file.

NOTE:
  • If the size of the object to be copied is smaller than the threshold, copy the object directly. If not, a multipart copy is required.
  • If you copy an object directly, no part record is generated, and resumable transmission is not supported.
  • This value can contain a capacity unit. For example, 1 MB indicates 1048576 bytes.

versionId

Optional for copying an object (additional parameter)

Source object version ID that can be specified when copying an object

acl

Optional (additional parameter)

Access control policies for destination objects that can be specified when copying objects. Possible values are:

  • private
  • public-read
  • public-read-write
  • bucket-owner-full-control
NOTE:

The preceding four values indicate private read and write, public read, public read and write, and bucket owner full control.

sc

Optional (additional parameter)

Storage classes of the destination objects that can be specified when copying objects. Possible values are:

  • standard: OBS Standard, which features low access latency and high throughput, and is applicable to storing frequently accessed data (multiple accesses per month) or data that is smaller than 1 MB
  • warm: It is applicable to storing infrequently accessed (less than 12 times a year) data that requires quick response.
  • cold: It is secure, durable, and inexpensive, and applicable to archiving rarely-accessed (once a year) data.

meta

Optional (additional parameter)

Metadata of destination objects that can be specified when copying objects. The format is key1:value1#key2:value2#key3:value3.

NOTE:

The preceding value indicates that the destination objects in the bucket contain three groups of customized metadata after objects are copied: key1:value1, key2:value2, and key3:value3.

ps

Optional (additional parameter)

Indicates the size of each part in a multipart copy task, in bytes. The value ranges from 100 KB to 5 GB. The default value is the value of defaultPartSize in the configuration file.

NOTE:
  • This value can contain a capacity unit. For example, 1 MB indicates 1048576 bytes.
  • The parameter can be set to auto. In this case, obsutil automatically sets the part size for each multipart task based on the source object size.

cpd

Optional (additional parameter)

Indicates the folder where the part records reside. The default value is .obsutil_checkpoint, the subfolder in the home directory of the user who executes obsutil commands.

NOTE:

A part record is generated during a multipart copy and saved to the copy subfolder. After the copy succeeds, its part record is deleted automatically. If the copy fails or is suspended, the system attempts to resume the task according to its part record when you perform the copy the next time.

r

Mandatory for copying objects in batches (additional parameter)

Copies objects in batches based on a specified name prefix of objects in the source bucket.

f

Optional for copying objects in batches (additional parameter)

Runs in force mode.

j

Optional for copying objects in batches (additional parameter)

Indicates the maximum number of concurrent tasks for copying objects in batches. The default value is the value of defaultJobs in the configuration file.

NOTE:

The value is ensured to be greater than or equal to 1.

exclude

Optional for copying objects in batches (additional parameter)

Indicates the matching patterns of source objects that are excluded, for example: *.txt.

NOTE:
  • The asterisk (*) represents any group of characters, and the question mark (?) represents any single character. For instance, abc*.txt indicates any file whose name starts with abc and ends with .txt.
  • You can use \* to represent * and \? to represent ?.
  • If the name of the object to be copied matches the value of this parameter, the object is skipped.
NOTICE:
  • You are advised to use quotation marks for the matching pattern to prevent special characters from being escaped by the OS and leading to unexpected results. Use single quotation marks for Linux or macOS and quotation marks for Windows.
  • The matching pattern applies to the absolute path of an object, including the object name prefix and object name starting from the root directory. For example, if the path of an object in the bucket is obs://bucket/src1/src2/test.txt, then the absolute path of the object is src1/src2/test.txt.
  • This matching pattern applies only to objects whose names do not end with a slash (/).
  • Multiple exclude parameters can be specified, for example, -exclude=*.xxx -exclude=*.xxx.

include

Optional for copying objects in batches (additional parameter)

Indicates the matching patterns of source objects that are included, for example: *.jpg.

NOTE:
  • The asterisk (*) represents any group of characters, and the question mark (?) represents any single character.
  • You can use \* to represent * and \? to represent ?.
  • Only after identifying that the name of the file to be copied does not match the value of exclude, the system checks whether the file name matches the value of this parameter. If yes, the file is copied. If not, the file is skipped.
NOTICE:
  • You are advised to use quotation marks for the matching pattern to prevent special characters from being escaped by the OS and leading to unexpected results. Use single quotation marks for Linux or macOS and quotation marks for Windows.
  • The matching pattern applies to the absolute path of an object, including the object name prefix and object name starting from the root directory. For example, if the path of an object in the bucket is obs://bucket/src1/src2/test.txt, then the absolute path of the object is src1/src2/test.txt.
  • This matching pattern applies only to objects whose names do not end with a slash (/).
  • Multiple include parameters can be specified, for example, -include=*.xxx -include=*.xxx.

timeRange

Optional for copying objects in batches (additional parameter)

Indicates the time range matching pattern when copying objects. Only objects whose latest modification time is within the configured time range are copied.

This pattern has a lower priority than the object matching patterns (exclude/include). That is, the time range matching pattern is executed after the configured object matching patterns.

NOTE:
  • The matching time range is represented in time1-time2, where time1 must be earlier than or the same as time2. The time format is yyyyMMddHHmmss.
  • Automatic formatting is supported. For example, yyyyMMdd is equivalent to yyyyMMdd000000, and yyyyMM is equivalent to yyyyMM01000000.
  • If this parameter is set to *-time2, all files whose latest modification time is earlier than time2 are matched. If it is set to time1-*, all files whose latest modification time is later than time1 are matched.
NOTICE:
  • Time in the matching pattern is the UTC time.
  • This matching pattern applies only to objects whose names do not end with a slash (/).

mf

Optional (additional parameter)

Indicates that the name matching pattern (include or exclude) and the time matching pattern (timeRange) also take effect on objects whose names end with a slash (/).

o

Optional (additional parameter)

Indicates the folder where operation result lists reside. After the command is executed, result lists (possibly including success, failure, and warning files) are generated in the folder. The default value is .obsutil_output, the subfolder in the home directory of the user who executes obsutil commands.

NOTE:
  • The naming rule for result lists is as follows: cp_{succeed | failed | warning}_report_time_TaskId.txt
  • By default, the maximum size of a single result list is 30 MB and the maximum number of result lists that can be retained is 1024. You can set the maximum size and number by configuring recordMaxLogSize and recordBackups in the configuration file.
  • If there are multiple folders and files and you need to confirm the detailed error information about a failed task, refer to the failure list cp_failed_report_time_TaskId.txt in the result list folder and the log files in the log path.

config

Optional (additional parameter)

User-defined configuration file for executing a command. For details about parameters that can be configured, see Parameter Description.

Response

Refer to Response for uploading an object.