All Products
Search
Document Center

Object Storage Service:Synchronize OSS objects to your local computer

Last Updated:Aug 19, 2024

You can run the sync command to synchronize objects that are stored in Object Storage Service (OSS) to your computer.

Usage notes

  • 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 the sync and cp commands

    • The sync command recursively synchronizes all objects and subdirectories in a specific directory. The cp command recursively synchronizes objects only if the -r option is specified.

    • The sync command supports the --backup-dir option. When you run the sync command to synchronize data to OSS, you can specify this option in the command to specify a directory in OSS to store objects that exist in the destination but do not exist in the source. The cp command does not support the --backup-dir option.

    • The sync command does not support the --version-id option. Therefore, the sync command cannot be used to synchronize previous versions of objects in versioned buckets. 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 Download objects.

Command syntax

ossutil sync cloud_url  file_url
[-f --force]
[-u --update]
[--maxdownspeed <value>]
[--delete]
[--backup-dir <value>]
[--enable-symlink-dir]
[--disable-all-symlink]
[--disable-ignore-error]
[--only-current-dir]
[--output-dir <value>]
[--bigfile-threshold <value>]
[--part-size <value>]
[--checkpoint-dir <value>]
[--range <value>]
[--encoding-type <value>]
[--snapshot-path <value>]
[--include <value>]
[--exclude <value>]
[--disable-crc64]
[--payer <value>]
[-j, --job <value>]
[--parallel <value>]
[--retry-times <value>]

The following table describes the parameters and options in the command syntax.

Parameter/Option

Description

cloud_url

The path to the directory in which the objects that you want to synchronize are stored. The path is in the oss://bucketname/path/ format. Example: oss://examplebucket/exampledir/. If the value of cloud_url does not end with a forward slash (/), ossutil automatically adds one to the end of the value.

file_url

The path to the local directory to which you want to synchronize objects. Examples: /localfolder/ in Linux and D:\localfolder\ in Windows.

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

--maxdownspeed

Specifies the maximum download speed. Unit: KB/s. Default value: 0, which specifies that the download speed is unlimited.

--delete

Specifies that only the synchronized objects are retained in the destination path. Other objects in the destination path are deleted.

Warning

To specify the --delete option in the command, we recommend that you enable versioning for the bucket to prevent data from being accidentally deleted. For more information about versioning, see Overview.

--backup-dir

Specifies the directory used to store objects that exist in the destination path but do not exist in the source.

--enable-symlink-dir

Specifies that subdirectories to which symbolic links point are synchronized.

--disable-all-symlink

Specifies that all files 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

Specifies the directory in which output files are stored. The output files are the reports generated when an error occurs in a batch synchronization task.

If you do not specify a directory for the output files, the output files are stored in the ossutil_output subdirectory of the current directory.

--bigfile-threshold

The object size threshold for using resumable download. If the size of an object exceeds the specified object size threshold, the object is downloaded by using resumable download. 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 of the resumable download task is stored. If the task fails, ossutil automatically creates a directory named .ossutil_checkpoint and saves the checkpoint information in the directory. If the task is successful, ossutil deletes the directory. If you specify a checkpoint directory, make sure that the directory can be deleted.

--range

Specifies that a specific range of the object content is downloaded and stored as a new file in the destination path. The minimum start value of the range is 0, which indicates the byte 0 of the content of the object. You can specify a value for this option in one of the following formats:

  • Data range with the specified start value and end value

    For example, a value of 3-9 indicates a range from byte 3 to byte 9.

  • Start value

    For example, a value of 3- indicates a range from byte 3 to the end of the object.

  • End value

    For example, the value of -9 indicates a range from byte 0 to byte 9.

--encoding-type

The method that you want to use to encode the names of objects. Set the value to url. If you do not specify this option, the names of the objects are not encoded.

--snapshot-path

Specifies the directory in which the snapshots of synchronized objects are stored. In the next synchronization task, ossutil reads the snapshots in this directory for incremental synchronization.

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

--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. Default value: 10. Valid values: 1 to 500.

Examples

The localdir directory of a bucket named examplebucket contains objects a.txt and b.txt and a subdirectory named C. A local file named d.txt is stored in the destdir directory of the local root directory. The following structure shows the files and directories in your computer and OSS before synchronization:

examplebucket           Local root directory
└── localdir/             └── destdir/
       ├── a.txt                └── d.txt
       ├── b.txt
       └── C/
  • Synchronize the localdir directory from examplebucket to your computer.

    ossutil sync  oss://examplebucket/localdir/  destdir/ 

    After you run the preceding command, the a.txt and b.txt objects and the C directory are added to the destfolder directory of your computer. The following structure shows the files and directories in your computer and OSS after synchronization:

    examplebucket           Local root directory
    └── localdir/             └── destdir/
           ├── a.txt                ├── a.txt 
           ├── b.txt                ├── b.txt
           └── C/                   ├── d.txt
                                       └── C/
  • Synchronize the localdir directory of the examplebucket bucket to a local directory named destdir. The --backup-dir option is set to a directory named backup in the command to store objects that exist in the destdir directory but do not exist in the localdir directory. These objects are deleted from the destdir directory.

    ossutil sync oss://examplebucket/localdir/  destdir/  --delete  --backup-dir backup/

    After you run the command, the localdir directory of the examplebucket bucket is synchronized to the destdir directory in your computer. Objects that exist in the destdir directory and do not exist in the localdir directory are moved to the backup directory. Only the synchronized objects named a.txt and b.txt and the subdirectory named C are stored in the destdir directory after synchronization. The d.txt object that exists in the destdir directory before synchronization is moved to the backup directory. The following structure shows the files and directories in your computer and OSS after synchronization by specifying the backup directory:

    examplebucket              Local root directory
    └── localdir/               ├── destdir/
           ├── a.txt            │     ├── a.txt 
           ├── b.txt            │     ├── b.txt
           └── C/               │     └── C/                             
                                   └── backup/
                                          └──d.txt
  • If 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 a directory named srcfolder from a bucket named examplebucket that is located in the China (Shanghai) region and owned by another Alibaba Cloud account, to a local directory named examplefolder:

ossutil sync oss://examplebucket/srcfolder/  examplefolder/ -e oss-cn-shanghai.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA****  -k 67DLVBkH7EamOjy2W5RVAHUY9H****

For more information about common options, see Common options.