Bucket data synchronization
If users need to enable data synchronization between buckets, the following code can achieve this:
| Parameters | Required or not | Description |
|---|---|---|
| id | Yes | Rule name of replication. The ID must consist of numbers, letters, hyphens (-), and underscores (_), and shall not exceed 20 characters. |
| status | Yes | Whether it takes effect; “enabled” means it is effective |
| resource | Yes | Effective prefix of replication. The resource configuration format is {$bucket_name/$bucket_name+/. |
| destination | Yes | Destination location configuration of replication |
| +bucket | Yes | Destination Bucket name |
| +storageClass | No | Storage class of destination object. If you want to keep the same storage class as the source Bucket, this parameter does not need to be configured; if you need to specify a separate storage class, it can be STANDARD,STANDARD_IA and COLD. |
| replicateHistory | No | Historical file replication: When enabled, all existing objects will be synchronously replicated to the destination bucket, sharing the same resource scope. |
| +storageClass | No | Storage class of destination object. If you want to keep the same storage class as the source Bucket, this parameter does not need to be configured; if you need to specify a separate storage class, it can be STANDARD,STANDARD_IA and COLD. |
| replicateDeletes | Yes | It indicates whether Delete synchronization function is enabled. It is enabled,disabled. |
1public void PutBucketReplicationByReplication(BosClient client, String bucketName, String replicationId, String dstBucketName) {
2 SetBucketReplicationRequest request = new SetBucketReplicationRequest(bucketName);
3 request.setId(replicationId);
4 request.setStatus("enabled");
5 String[] resource = {bucketName + "/abc"};
6 request.setResource(resource);
7 Destination destination = new Destination();
8 destination.setBucket(dstBucketName);
9 request.setDestination(destination);
10 request.setReplicateDeletes("enabled");
11 client.setBucketReplication(request);
12 }
Users can obtain data synchronization details for a specified bucket ID, including the source bucket name, destination bucket name, storage class, whether historical replication is enabled, data synchronization policy, destination region, and more. The following code demonstrates this:
1public void GetBucketReplication(BosClient client, String bucketName, String replicationId) {
2 GetBucketReplicationRequest grequest = new GetBucketReplicationRequest(bucketName);
3 grequest.setId(replicationId);
4 GetBucketReplicationResponse response = client.getBucketReplication(grequest);
5 }
If users want to delete the data synchronization with a specified ID in the bucket, the following code can achieve this:
1public void DeleteBucketReplication(BosClient client, String bucketName, String replicationId) {
2 DeleteBucketReplicationRequest drequest = new DeleteBucketReplicationRequest();
3 drequest.setBucketName(this.bucketName);
4 drequest.setId(this.replicationId);
5 client.deleteBucketReplication(drequest);
6}
If users want to get all replication synchronization rules of the bucket, the following code can achieve this:
1public void ListBucketReplication(BosClient client, String bucketName) {
2 ListBucketReplicationResponse replicationResponse;
3 ListBucketReplicationRequest listreq = new ListBucketReplicationRequest(this.bucketName);
4 replicationResponse = client.listBucketReplication(listreq);
5}
If users want to get the progress status of data synchronization replication with a specified ID, the following code can achieve this:
1public void GetBucketReplicationProgress(BosClient client, String bucketName,String replicationId) {
2 GetBucketReplicationProgressRequest proreq = new GetBucketReplicationProgressRequest(this.bucketName);
3 proreq.setId(this.replicationId);
4 BucketReplicationProgress progress = client.getBucketReplicationProgress(proreq);
5}
