All Products
Search
Document Center

Object Storage Service:put-bucket-replication

Last Updated:Apr 18, 2025

Configures data replication rules for a bucket. Object Storage Service (OSS) provides two data replication features: cross-region replication (CRR) and same-region replication (SRR).

Usage notes

For more information about data replication, see CRR and SRR.

Permissions

By default, an Alibaba Cloud account has full permissions on resources in the account. In contrast, RAM users and RAM roles associated with an Alibaba Cloud account initially have no permissions. To manage resources by using a RAM user or role, you must grant the required permissions via RAM policies or Bucket policies.

API

Action

Description

PutBucketReplication

oss:PutBucketReplication

Configures data replication rules for a bucket.

oss:ReplicateGet

If the replication is cross-account or a RAM role is specified for replication, you must have the required permission for this operation on both the source bucket and the target bucket.

Command syntax

ossutil api put-bucket-replication --bucket value --replication-configuration value [flags]

Parameter

Type

Description

--bucket

string

The name of the bucket.

--replication-configuration

string

The data replication configurations.

Note

The put-bucket-replication command corresponds to the PutBucketReplication operation. For more information about the parameters in the PutBucketReplication operation, see PutBucketReplication.

--replication-configuration

The --replication-configuration configuration option supports both XML and JSON formats.

  • XML format:

    <ReplicationConfiguration>
        <Rule>
            <PrefixSet>
                <Prefix>string</Prefix>
                <Prefix>string</Prefix>
            </PrefixSet>
            <Action>string</Action>
            <Destination>
                <Bucket>string</Bucket>
                <Location>string</Location>
                <TransferType>string</TransferType>
            </Destination>
            <HistoricalObjectReplication>string</HistoricalObjectReplication>
        </Rule>
    </ReplicationConfiguration>
  • JSON format:

    {
        "Rule": {
            "PrefixSet": {
                "Prefix": [
                    "string",
                    "string"
                ]
            },
            "Action": "string",
            "Destination": {
                "Bucket": "string",
                "Location": "string",
                "TransferType": "string"
            },
            "HistoricalObjectReplication": "enabled"
        }
    }
Note

For more information, see Command-line options.

Examples

The following examples show how to configure data replication rules for a bucket named examplebucket.

  • Create a configuration file named replication-configuration.xml and add the following code to the configuration file:

    <?xml version="1.0" encoding="UTF-8"?>
    <ReplicationConfiguration>
        <Rule>     
            <PrefixSet>
                <Prefix>prefix_1</Prefix>
                <Prefix>prefix_2</Prefix>
            </PrefixSet>
            <Action>PUT</Action>
            <Destination>
                <Bucket>destBucket</Bucket>
                <Location>oss-cn-hangzhou</Location>
                <TransferType>oss_acc</TransferType>
            </Destination>
            <HistoricalObjectReplication>enabled</HistoricalObjectReplication>
        </Rule>
    </ReplicationConfiguration>
    ossutil api put-bucket-replication --bucket examplebucket --replication-configuration file://replication-configuration.xml
  • Create a configuration file named replication-configuration.json and add the following code to the configuration file:

    {
        "Rule": {
            "PrefixSet": {
                "Prefix": [
                    "prefix_1",
                    "prefix_2"
                ]
            },
            "Action": "PUT",
            "Destination": {
                "Bucket": "destBucket",
                "Location": "oss-cn-hangzhou",
                "TransferType": "oss_acc"
            },
            "HistoricalObjectReplication": "enabled"
        }
    }
    
    ossutil api put-bucket-replication --bucket examplebucket --replication-configuration file://replication-configuration.json
  • Configure parameters in the following command in the JSON format:

    ossutil api put-bucket-replication --bucket examplebucket --replication-configuration "{\"Rule\":{\"PrefixSet\":{\"Prefix\":[\"prefix_1\",\"prefix_2\"]},\"Action\":\"PUT\",\"Destination\":{\"Bucket\":\"destBucket\",\"Location\":\"oss-cn-hangzhou\",\"TransferType\":\"oss_acc\"},\"HistoricalObjectReplication\":\"enabled\"}}"