Bucket数据同步
更新时间:2022-09-14
若用户需要开启Bucket之间的数据同步,则如下代码可以做到:
参数 | 是否必须 | 描述 |
---|---|---|
id | 是 | replication规则名,id 由数字字母 - _ 组成,不得超过20个字符 |
status | 是 | 是否生效,生效为enabled |
resource | 是 | replication生效前缀,resource的配置形式为{$bucket_name/<生效的对象前缀>},必须要以$bucket_name +/ 开头 |
destination | 是 | 复制的目的端配置 |
+bucket | 是 | 目的Bucket name |
+storageClass | 否 | 目的Object的存储类型。如果保持和源Bucket的存储类型一致,则该参数不需要配置;如果需要单独指定存储类型可以为STANDARD ,STANDARD_IA ,COLD 。 |
replicateHistory | 否 | 历史文件复制,有该项则认为是开启。开启历史文件复制后,存量的全部Object都同步复制到目的Bucket,复制范围共用resource。 |
+storageClass | 否 | 目的Object的存储类型。如果保持和源Bucket的存储类型一致,则该参数不需要配置;如果需要单独指定存储类型可以为STANDARD ,STANDARD_IA ,COLD 。 |
replicateDeletes | 是 | 是否开启删除同步,可以为enabled ,disabled 。 |
public void PutBucketReplicationByReplication(BosClient client, String bucketName, String replicationId, String dstBucketName) {
SetBucketReplicationRequest request = new SetBucketReplicationRequest(bucketName);
request.setId(replicationId);
request.setStatus("enabled");
String[] resource = {bucketName + "/abc"};
request.setResource(resource);
Destination destination = new Destination();
destination.setBucket(dstBucketName);
request.setDestination(destination);
request.setReplicateDeletes("enabled");
client.setBucketReplication(request);
}
若用户想获取bucket指定id的数据同步信息,包括源Bucket名称、目的Bucket名称、存储类型、是否进行历史复制,数据同步策略,目的region等。如下代码可以做到:
public void GetBucketReplication(BosClient client, String bucketName, String replicationId) {
GetBucketReplicationRequest grequest = new GetBucketReplicationRequest(bucketName);
grequest.setId(replicationId);
GetBucketReplicationResponse response = client.getBucketReplication(grequest);
}
若用户想删除bucket指定id的数据同步,则如下代码可以做到:
public void DeleteBucketReplication(BosClient client, String bucketName, String replicationId) {
DeleteBucketReplicationRequest drequest = new DeleteBucketReplicationRequest();
drequest.setBucketName(this.bucketName);
drequest.setId(this.replicationId);
client.deleteBucketReplication(drequest);
}
若用户想获取bucket所有的replication同步规则,则如下代码可以做到:
public void ListBucketReplication(BosClient client, String bucketName) {
ListBucketReplicationResponse replicationResponse;
ListBucketReplicationRequest listreq = new ListBucketReplicationRequest(this.bucketName);
replicationResponse = client.listBucketReplication(listreq);
}
若用户想获取指定id的数据同步复制的进程状态,则如下代码可以做到:
public void GetBucketReplicationProgress(BosClient client, String bucketName,String replicationId) {
GetBucketReplicationProgressRequest proreq = new GetBucketReplicationProgressRequest(this.bucketName);
proreq.setId(this.replicationId);
BucketReplicationProgress progress = client.getBucketReplicationProgress(proreq);
}