All Products
Search
Document Center

Object Storage Service:sync (Synchronize OSS files to a local computer)

Last Updated:Feb 27, 2026

You can run the sync command in ossutil to synchronize objects stored in Object Storage Service (OSS) to a local directory on your computer.

Prerequisites

Before you synchronize objects from OSS to your computer, make sure the following requirements are met:

  • Permissions: You have the oss:GetObject and oss:ListObjects permissions on the source bucket. For more information, see Attach a custom policy to a RAM user.

  • ossutil version: For ossutil 1.6.16 and later, you can use ossutil directly as the binary name on all operating systems. For earlier versions, you need to use the binary name specific to your operating system. For more information, see ossutil command reference.

How sync works

When you run the sync command, ossutil scans the source directory and compares it against the destination directory. For each object in the source:

  • If the object does not exist in the destination, it is downloaded.

  • If the object already exists in the destination, ossutil prompts you to confirm whether to overwrite it.

To control overwrite behavior, use the following options:

  • -f, --force: Overwrites existing files without prompting.

  • -u, --update: Downloads an object only when it does not exist in the destination or when the source object's last modified time is later than the destination file's. This provides efficient incremental synchronization.

File count limits

When you run the sync command without the --delete option, no limit is imposed on the number of files you can synchronize. If you include --delete, you can synchronize up to 1 million files at a time. Exceeding this limit returns the error: over max sync numbers 1000000.

Differences between sync and cp

Behaviorsynccp
Recursive by defaultYes. Automatically includes all objects and subdirectories.No. Requires the -r option for recursive operations.
Backup directorySupports the --backup-dir option to back up destination-only files before deleting them.Not supported.
Version-specific downloadDoes not support --version-id. Cannot synchronize previous versions of objects in versioned buckets.Supports --version-id.

Except for these differences, the sync and cp commands work in a similar way. For more information about cp, 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>]

Parameters

ParameterDescription
cloud_urlThe URL of the source directory in OSS. Format: oss://bucketname/path/. Example: oss://examplebucket/exampledir/. If the value does not end with a forward slash (/), ossutil adds one automatically.
file_urlThe path to the local destination directory. Examples: /localfolder/ on Linux, D:\localfolder\ on Windows.

Options

Sync behavior

OptionDescription
-f, --forceForces the operation without requiring confirmation. By default, ossutil prompts for confirmation before overwriting existing files.
-u, --updateSynchronizes an object only when it does not exist in the destination or when the source object's last modified time is later than the destination file's. Use this option to perform incremental synchronization and skip files that are already up to date.
--deleteRemoves files from the destination that do not exist in the source, so the destination mirrors the source exactly. Warning: To prevent accidental data loss, we recommend that you enable versioning for the bucket before using this option. When --delete is specified, you can synchronize a maximum of 1 million files at a time.
--backup-dir \Specifies a directory to back up files that exist in the destination but not in the source. Instead of permanently deleting these files, ossutil moves them to the backup directory. Use this option with --delete as a safer alternative to bare deletion.
--only-current-dirSynchronizes only the objects in the specified OSS directory. Subdirectories and their contents are skipped.

File filtering

OptionDescription
--include \Includes only objects whose names match the specified condition. You can specify this option multiple times to define multiple inclusion rules. For more information, see Options --include and --exclude.
--exclude \Excludes objects whose names match the specified condition. You can specify this option multiple times to define multiple exclusion rules. For more information, see Options --include and --exclude.

Performance and concurrency

OptionDescription
-j, --job \The number of concurrent tasks for multi-object operations. Valid values: 1 to 10000. Default value: 3. Increase this value when synchronizing a large number of small files to improve throughput.
--parallel \The number of concurrent tasks for single-object operations (such as multipart download of a large file). Valid values: 1 to 10000. If you do not specify this option, ossutil determines the value automatically based on the operation type and object size. Increase this value when downloading a small number of large files.
--maxdownspeed \The maximum download speed. Unit: KB/s. Default value: 0, which means the download speed is not limited.
--snapshot-path \Specifies a directory to store snapshots of synchronized objects. During the next synchronization, ossutil reads the snapshots to identify which objects have changed and synchronizes only those objects. This can significantly speed up repeated synchronization of the same directory.

Resumable download

OptionDescription
--bigfile-threshold \The object size threshold above which ossutil uses resumable download. If an object exceeds this size, it is downloaded in multiple parts so that the download can resume from where it left off after a failure. Unit: bytes. Default value: 100 MB. Valid values: 0 to 9223372036854775807.
--part-size \The size of each part in a resumable download. Unit: bytes. By default, ossutil determines the part size based on the object size. Valid values: 1 to 9223372036854775807.
--checkpoint-dir \The directory where ossutil stores checkpoint file information for resumable downloads. If a download fails, ossutil uses the checkpoint data to resume the download. Default directory: .ossutil_checkpoint in the current working directory. If the download completes successfully, ossutil deletes the checkpoint directory. Make sure the directory you specify can be deleted.

Symbolic link handling

OptionDescription
--enable-symlink-dirFollows symbolic links that point to subdirectories and synchronizes their contents.
--disable-all-symlinkIgnores all symbolic links. Files and subdirectories referenced by symbolic links are not synchronized.

Data integrity and error handling

OptionDescription
--disable-crc64Disables CRC-64 verification. By default, ossutil performs CRC-64 checks to verify data integrity after downloading each object.
--disable-ignore-errorStops the sync operation when an error occurs during batch operations. By default, ossutil ignores errors and continues processing the remaining objects. Error details are written to the output directory.
--retry-times \The number of times ossutil retries a failed operation. Default value: 10. Valid values: 1 to 500.

Output and encoding

OptionDescription
--output-dir \The directory where ossutil stores output files, including error reports generated during batch synchronization. Default value: the ossutil_output subdirectory of the current working directory.
--encoding-type \The encoding method for object names. Set the value to url to URL-encode object names. If you do not specify this option, object names are not encoded.
--range \Downloads a specific byte range of each object and saves it as a new file. You can specify a value in one of the following formats: 3-9 (byte 3 to byte 9), 3- (byte 3 to end of object), -9 (byte 0 to byte 9). The minimum start value is 0.

Billing

OptionDescription
--payer \Specifies the payer for request and traffic fees. Set this option to requester if you want the requester to pay the fees instead of the bucket owner. For more information about the pay-by-requester mode, see Pay-by-requester.

Examples

The following examples use a bucket named examplebucket that contains a directory named localdir. The localdir directory contains two objects (a.txt and b.txt) and one subdirectory (C). On your computer, the destdir directory contains a single file named d.txt.

examplebucket           Local root directory
└── localdir/             └── destdir/
       ├── a.txt                └── d.txt
       ├── b.txt
       └── C/

Example 1: Basic synchronization

Synchronize the localdir directory from examplebucket to the local destdir directory:

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

After synchronization, the objects a.txt, b.txt, and subdirectory C are added to destdir. The existing file d.txt is preserved because --delete is not specified.

examplebucket           Local root directory
└── localdir/             └── destdir/
       ├── a.txt                ├── a.txt
       ├── b.txt                ├── b.txt
       └── C/                   ├── d.txt
                                └── C/

Example 2: Synchronize with deletion and backup

Synchronize localdir to destdir and remove files from destdir that do not exist in localdir. Move the removed files to a backup directory instead of permanently deleting them:

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

After synchronization, destdir contains only the objects from localdir. The file d.txt, which existed only in destdir, is moved to the backup directory:

examplebucket              Local root directory
└── localdir/               ├── destdir/
       ├── a.txt            │     ├── a.txt
       ├── b.txt            │     ├── b.txt
       └── C/               │     └── C/
                            └── backup/
                                   └──d.txt

Example 3: Synchronize only specific file types

Synchronize only .txt files from localdir, excluding all other file types:

ossutil sync oss://examplebucket/localdir/ destdir/ --include "*.txt"

Example 4: Exclude specific file types

Synchronize all objects from localdir except .log files:

ossutil sync oss://examplebucket/localdir/ destdir/ --exclude "*.log"

Example 5: Incremental synchronization

Synchronize only objects that are new or have been modified since the last synchronization:

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

With --update (-u), ossutil skips objects whose last modified time in OSS is the same as or earlier than the corresponding local file.

Example 6: Synchronize only the top-level directory

Synchronize only the objects directly in localdir, without recursing into subdirectories:

ossutil sync oss://examplebucket/localdir/ destdir/ --only-current-dir

Example 7: Speed up repeated synchronization with snapshots

Use --snapshot-path to store synchronization state. On subsequent runs, ossutil reads the snapshot to identify changed objects and synchronizes only those, reducing the time needed for repeated synchronization of the same directory:

ossutil sync oss://examplebucket/localdir/ destdir/ --snapshot-path /tmp/oss-sync-snapshot/

Example 8: Tune concurrency for large-scale synchronization

When you synchronize a directory that contains both small and large files, adjust --job and --parallel to optimize throughput:

  • --job controls how many objects are processed at the same time. Increase this value when you need to synchronize many small files.

  • --parallel controls how many parts of a single large object are downloaded at the same time. Increase this value when you need to download a few large files.

ossutil sync oss://examplebucket/data/ /local/data/ --job 10 --parallel 5

To limit download speed to 10,240 KB/s (10 MB/s) and avoid saturating your network bandwidth:

ossutil sync oss://examplebucket/data/ /local/data/ --maxdownspeed 10240

Success output

When the synchronization completes successfully, ossutil returns output similar to the following. Note that the output uses "upload" regardless of the sync direction; this is the standard ossutil output format.

Succeed: Total num: 2, size: 750,081. OK num: 2(upload 2 files).

average speed 1641000(byte/s)

Error handling and recovery

If a synchronization fails partway through, you can rerun the same sync command to resume. ossutil compares the source and destination and synchronizes only the objects that were not successfully downloaded in the previous run.

For large files, ossutil uses resumable download by default (for objects larger than 100 MB). Checkpoint file information is stored in the .ossutil_checkpoint directory, which allows ossutil to resume downloading a large file from the last successfully downloaded part rather than starting over.

To customize error handling behavior:

  • --retry-times: Sets the number of automatic retries for each failed operation. The default is 10 retries.

  • --disable-ignore-error: By default, ossutil ignores errors during batch operations and continues processing the remaining objects. Use this option to stop the operation when an error occurs. Error details are written to the output directory.

Common options

If you need to synchronize objects from a bucket in a different region or owned by a different Alibaba Cloud account, specify the endpoint and credentials directly in the command:

OptionDescription
-eThe endpoint of the region where the bucket is located.
-iThe AccessKey ID of the Alibaba Cloud account that owns the bucket.
-kThe AccessKey secret of the Alibaba Cloud account that owns the bucket.

For example, to synchronize a directory named srcfolder from a bucket named examplebucket in the China (Shanghai) region, owned by a different Alibaba Cloud account:

ossutil sync oss://examplebucket/srcfolder/ examplefolder/ -e oss-cn-shanghai.aliyuncs.com -i yourAccessKeyID -k yourAccessKeySecret

For more information about common options, see Common options.