All Products
Search
Document Center

Object Storage Service:put-bucket-replication

Last Updated:Nov 10, 2024

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

  • By default, an Alibaba Cloud account has the permissions to configure data replication rules for a bucket. To configure data replication rules for a bucket by using a RAM user or Security Token Service (STS), you must have the oss:PutBucketReplication permission. For more information, see Attach a custom policy to a RAM user.

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

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\"}}"