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. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM policies or Bucket Policy.
|
API |
Action |
Description |
|
PutBucketReplication |
|
Configures data replication rules for a bucket. |
|
|
If cross-account replication is used, or if replication with a specified RAM role is used, both the source bucket and the destination bucket require this permission. |
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. |
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" } }
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\"}}"