put-bucket-replication用于为存储空间(Bucket)指定数据复制规则。OSS支持跨区域复制(Cross-Region Replication)和同区域复制(Same-Region Replication)。
注意事项
阿里云账号默认拥有为Bucket指定数据复制规则的权限。如果您需要通过RAM用户或者STS的方式进行添加修改,您必须拥有
oss:PutBucketReplication
权限。具体操作,请参见为RAM用户授权自定义的权限策略。
命令格式
ossutil api put-bucket-replication --bucket value --replication-configuration value [flags]
参数 | 类型 | 说明 |
--bucket | string | Bucket名称。 |
--replication-configuration | string | 数据复制配置信息。 |
说明
put-bucket-replication命令对应API接口PutBucketReplication。关于API中的具体参数含义,请参见PutBucketReplication。
--replication-configuration
--replication-configuration 配置选项既支持XML语法也支持JSON语法。
XML语法:
<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语法:
{ "Rule": { "PrefixSet": { "Prefix": [ "string", "string" ] }, "Action": "string", "Destination": { "Bucket": "string", "Location": "string", "TransferType": "string" }, "HistoricalObjectReplication": "enabled" } }
说明
关于支持的全局命令行选项,请参见支持的全局命令行选项。
使用示例
为存储空间examplebucket设置数据复制规则。
使用XML配置文件,cors-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>
ossutil api put-bucket-replication --bucket examplebucket --replication-configuration file://replication-configuration.xml
使用JSON配置文件,replication-configuration.json 内容如下:
{ "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
使用JSON配置参数,命令示例如下:
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\"}}"
文档内容是否对您有帮助?