You can run the sync command to synchronize multiple objects at the same time between Object Storage Service (OSS) buckets that reside in the same region or between directories of the same bucket.
Usage notes
To synchronize objects between OSS directories, you must have the
oss:GetObject,oss:ListObjects,oss:PutObject, andoss:DeleteObjectpermissions. For more information, see Attach a custom policy to a RAM user.
Binary name
For ossutil 1.6.16 and later, you can directly use ossutil as the binary name in the command line. You do not need to update the binary name based on the operating system. For ossutil earlier than 1.6.16, you need to update the binary name based on the operating system. For more information, see ossutil command reference.
Number of local files to synchronize
When you run the sync command without including the --delete option, no limit is imposed on the number of local files that you can synchronize at a time. If you include the --delete option when you run the sync command, you can synchronize up to 1 million local files at a time. If the number of local files that you want to synchronize exceeds 1 million, the over max sync numbers 1000000. error message is returned.
Differences between sync and cp
The sync command recursively synchronizes all objects and subdirectories in the specified directory. The cp command recursively synchronizes objects only when the -r option is specified.
If you run the sync command to synchronize data to an OSS bucket, you can add the --delete option to the command to delete the following objects from the destination bucket: objects that exist in the destination bucket but do not exist in the source bucket. This way, only the synchronized objects are retained in the destination bucket. The cp command does not support the --delete option.
The sync command does not support the --version-id option. You cannot use the sync command to synchronize previous versions of objects in buckets for which versioning is enabled. The cp command supports the --version-id option.
Except for the preceding differences, you can use the sync and cp commands in a similar manner. For more information about how to run the cp command, see Copy objects.
Limits
You cannot synchronize Cold Archive or Deep Cold Archive objects from a source bucket to a destination bucket.
Command syntax
ossutil sync cloud_url cloud_url
[-f --force]
[-u --update]
[--delete]
[--enable-symlink-dir]
[--disable-all-symlink]
[--disable-ignore-error]
[--only-current-dir]
[--output-dir <value>]
[--bigfile-threshold <value>]
[--part-size <value>]
[--checkpoint-dir <value>]
[--encoding-type <value>]
[--include <value>]
[--exclude <value>]
[--meta <value>]
[--acl <value>]
[--maxupspeed <value>]
[--disable-crc64]
[--payer <value>]
[-j, --job <value>]
[--parallel <value>]
[--retry-times <value>]
[--tagging <value>]The following table describes the parameters and options in the command syntax.
Parameter/Option | Description |
cloud_url | The source path and destination path. The paths are in the Important If the value of |
-f --force | Forces the operation without requiring confirmation. |
-u, --update | Specifies that ossutil synchronizes an object from the source only when the object does not exist in the destination or when the last modified time of the object in the source is later than that of the object in the destination. |
--delete | Specifies that only the synchronized objects are retained in the specified path of the destination bucket. Other objects in the path are deleted. Warning To specify the --delete option in the command, we recommend that you enable versioning to prevent data from being accidentally deleted. For more information about versioning, see Overview. |
--enable-symlink-dir | Specifies whether to synchronize subdirectories to which symbolic links point. |
--disable-all-symlink | Specifies that all objects and subdirectories to which symbolic links in the directory point are not synchronized. |
--disable-ignore-error | Specifies that errors are not ignored during batch operations. |
--only-current-dir | Specifies that only objects in the current directory are synchronized. Subdirectories in the current directory and objects in these subdirectories are not synchronized. |
--output-dir | The directory in which output files are stored. The output files are the reports generated when an error occurs in a batch synchronization task. By default, these reports are stored in the ossutil_output directory of the current directory. |
-bigfile-threshold | The object size threshold for using resumable upload. Unit: bytes. The default object size threshold is 100 MB. Valid values: 0 to 9223372036854775807. |
--part-size | The part size. Unit: bytes. By default, ossutil determines the part size based on the object size. Valid values: 1 to 9223372036854775807. |
--checkpoint-dir | The directory in which the checkpoint information about resumable upload tasks is stored. If the task fails, ossutil automatically creates a directory named |
--encoding-type | The encoding of object names. Set the value to url. If you do not set this parameter, the names of objects are not encoded. |
--include | Includes all objects that meet the specified conditions. For more information, see Options --include and --exclude. |
--exclude | Excludes all objects that meet the specified conditions. For more information, see Options --include and --exclude. |
--meta | Sets object metadata. The value is in the |
--acl | The access control list (ACL) of the destination object. Valid values:
|
--maxupspeed | The maximum upload speed. Unit: KB/s. Default value: 0. The value 0 specifies that the upload speed is unlimited. |
--disable-crc64 | Disables CRC-64 verification. |
--payer | The payer of the fees that are generated by the operation. If you want the requester who accesses the resources in the specified path to pay the fees that are generated by the operation, set this option to requester. |
-j, --job | The number of concurrent tasks that can be performed in a multi-object operation. Valid values: 1 to 10000. Default value: 3. |
--parallel | The number of concurrent tasks that can be performed in a single-object operation. Valid values: 1 to 10000. If you do not specify this option, ossutil specifies the value of this option based on the operation type and the object size. |
--retry-times | The number of retries in case of an error. Valid values: 1 to 500. Default value: 10. |
--tagging | The tags of objects in the |
Examples
Consider two buckets in your Alibaba Cloud account: examplebucket1 and examplebucket2. The examplebucket1 bucket contains two directories: exampledir and srcdir. The examplebucket2 bucket contains a directory named destdir. The following structure shows the objects and directories in examplebucket1 and examplebucket2 before synchronization:
examplebucket1 examplebucket2
├── exampledir/ └── destdir/
│ ├── a.txt ├── c.txt
│ └── b.txt └── e.txt
└── srcdir/
└── d.txt The following examples show how to run the sync command to synchronize objects between OSS paths in different scenarios.
Synchronize the exampledir directory of examplebucket1 to the srcdir directory of the same bucket.
ossutil sync oss://examplebucket1/exampledir/ oss://examplebucket1/srcdir/After you run the preceding command, all objects in the exampledir directory are synchronized to the srcdir directory. The following structure shows the objects and directories in examplebucket1 after synchronization:
examplebucket1 examplebucket1 ├── exampledir/ ├── exampledir/ │ ├── a.txt │ ├── a.txt │ └── b.txt │ └── b.txt └── srcdir/ └── srcdir/ └── d.txt ├── a.txt ├── b.txt └── d.txtSynchronize the exampledir directory of examplebucket1 to the destdir directory of examplebucket2.
ossutil sync oss://examplebucket1/exampledir/ oss://examplebucket2/destdir/After you run the preceding command, all objects in the exampledir directory of examplebucket1 are synchronized to the destdir directory of examplebucket2. The following structure shows the objects and directories in examplebucket1 and examplebucket2 after synchronization:
examplebucket1 examplebucket2 ├── exampledir/ └── destdir/ │ ├── a.txt ├── a.txt │ └── b.txt ├── b.txt └── srcdir/ ├── c.txt └── d.txt └── e.txtSynchronize all objects from examplebucket1 to examplebucket2 and use the --delete option to delete the objects that exist in examplebucket2 but do not exist in examplebucket1.
ossutil sync oss://examplebucket1 oss://examplebucket2 --deleteAfter you run the preceding command, the objects in examplebucket1 is synchronized to examplebucket2. The c.txt and e.txt objects that exist in examplebucket2 before synchronization are deleted when synchronization is complete.
examplebucket1 examplebucket2 ├── exampledir/ ├── exampledir/ │ ├── a.txt │ ├── a.txt │ └── b.txt │ └── b.txt └── srcdir/ └── srcdir/ └── d.txt └── d.txtIf the preceding commands are run successfully, output similar to the following content is returned to indicate the number of synchronized objects, the sizes of synchronized objects, and the time consumed by the synchronization:
Succeed: Total num: 2, size: 750,081. OK num: 2(upload 2 files). average speed 1641000(byte/s)
Common options
If you use ossutil to switch to a bucket that is located in another region, add the -e option to specify the endpoint of the region in which the bucket is located. If you use ossutil to switch to a bucket that belongs to another Alibaba Cloud account, add the -i option to specify the AccessKey ID of the specified account, and add the -k option to specify the AccessKey secret of the specified account.
For example, you can run the following command to synchronize the srcfolder directory from the examplebucket bucket to the examplefolder directory in the testbucket bucket. The examplebucket bucket is located in the China (Shanghai) region and is owned by another Alibaba Cloud account.
ossutil sync oss://examplebucket/srcfolder/ oss://testbucket/examplefolder/ -e oss-cn-shanghai.aliyuncs.com -i yourAccessKeyID -k yourAccessKeySecretFor more information about common options, see Common options.