Configures data replication rules for a bucket. OSS supports two replication modes: cross-region replication (CRR) and same-region replication (SRR).
For background on both modes, see CRR and SRR.
Permissions
By default, an Alibaba Cloud account has full permissions on its resources. RAM users and RAM roles start with no permissions and must be granted access via RAM policies or bucket policies.
| API | Action | Condition |
|---|---|---|
PutBucketReplication | oss:PutBucketReplication | Required on the source bucket |
oss:ReplicateGet | Required on both the source and destination buckets when replication is cross-account or a RAM role is specified |
Syntax
ossutil api put-bucket-replication --bucket <value> [required]
--replication-configuration <value> [required]
[flags]Required parameters
| Parameter | Type | Description |
|---|---|---|
--bucket | string | The name of the source bucket |
--replication-configuration | string | The replication rule in XML or JSON format. Pass inline JSON, a JSON file (file://config.json), or an XML file (file://config.xml) |
For global flags, see Command-line options.
This command maps to the PutBucketReplication API operation.
Replication configuration
The --replication-configuration value defines a single replication rule. Both XML and JSON formats are supported.
Fields
| Field | Type | Description |
|---|---|---|
PrefixSet.Prefix | string (repeatable) | Limits replication to objects whose keys start with the specified prefix. You can specify multiple prefixes. |
Action | string | The operation types to replicate. Example value: PUT. |
Destination.Bucket | string | The name of the destination bucket |
Destination.Location | string | The region of the destination bucket, for example, oss-cn-hangzhou |
Destination.TransferType | string | The network path for replication traffic. Use oss_acc to route through OSS transfer acceleration. |
HistoricalObjectReplication | string | Whether to replicate objects that existed in the bucket before the rule was created. Example value: enabled. |
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": "string"
}
}Examples
Configure data replication rules with a prefix filter
This example configures data replication from examplebucket to destBucket in oss-cn-hangzhou. Only objects with the key prefix prefix_1 or prefix_2 are replicated. Historical objects are included, and traffic routes through OSS transfer acceleration.
Create a file named
replication-configuration.xml:<?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>Apply the rule:
ossutil api put-bucket-replication --bucket examplebucket --replication-configuration file://replication-configuration.xml
Use a JSON configuration file
The same rule expressed in JSON:
Create a file named
replication-configuration.json:{ "Rule": { "PrefixSet": { "Prefix": [ "prefix_1", "prefix_2" ] }, "Action": "PUT", "Destination": { "Bucket": "destBucket", "Location": "oss-cn-hangzhou", "TransferType": "oss_acc" }, "HistoricalObjectReplication": "enabled" } }Apply the rule:
ossutil api put-bucket-replication --bucket examplebucket --replication-configuration file://replication-configuration.json
Pass configuration inline
Pass the JSON directly in the command without a file:
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\"}}"What's next
PutBucketReplication API reference — full parameter reference for the underlying API operation
CRR overview — cross-region replication use cases and limits
SRR overview — same-region replication use cases and limits