Cross-region replication

Last Updated: Jun 01, 2017

Bucket Cross-region replication automatically and asynchronously copies objects in buckets across different OSS data centers. It will synchronize changes to objects in the source bucket (create, overwrite, and delete) to the target bucket. This feature provides ideal cross-region disaster recovery for buckets or meets users’ needs for copying data. Objects in the target bucket are precise copies of objects in the source bucket, with the same object names, metadata and content (for example, create time, owner, user-defined metadata, object ACL and object content).

For more content on cross-region replication, refer to Cross-region replication.

Enable cross-region replication

You can use ‘OSSClient.addBucketReplication’ to enable cross-region replication:

  1. AddBucketReplicationRequest request = new AddBucketReplicationRequest("bucketName");
  2. request.setReplicationRuleID("ruleId");
  3. request.setTargetBucketName("targetBucketName");
  4. request.setTargetBucketLocation("oss-cn-qingdao");
  5. ossClient.addBucketReplication(request);

Tips:

  • When cross-region replication is enabled, the history data will be synchronized by default. If you do not need to synchronize the history data,useAddBucketReplicationRequest.setEnableHistoricalObjectReplication(false)to disable history data synchronization.

View cross-region replication

You can use ‘OSSClient.getBucketReplication’ to view the cross-region replication enabled on the bucket:

  1. List<ReplicationRule> rules = ossClient.getBucketReplication("bucketName");
  2. for (ReplicationRule rule : rules) {
  3. System.out.println(rule.getReplicationRuleID());
  4. System.out.println(rule.getTargetBucketLocation());
  5. System.out.println(rule.getTargetBucketName());
  6. }

Delete the cross-region replication feature

You can use ‘OSSClient.deleteBucketReplication’ to delete the enabled cross-region replication feature. After the deletion, the target buckets and objects will remain:

  1. ossClient.deleteBucketReplication("bucketName", "ruleId");

View cross-region replication progress

The replication progress is divided into the synchronization progress of the history data and the synchronization progress of the real-time data. The synchronization of the history data is represented by percentages. For example, 0.80 represents that 80% has been completed. This is only valid for buckets with the history data synchronization enabled. The real-time data synchronization is represented by the time points of the newly written data, indicating that the data before the specified time point has been synchronized.

You can use ‘OSSClient.deleteBucketReplication’ to view the cross-region replication progress:

  1. BucketReplicationProgress process = ossClient.getBucketReplicationProgress("bucketName", "repRuleID");
  2. System.out.println(process.getReplicationRuleID());
  3. // Whether the history data synchronization has been enabled
  4. System.out.println(process.isEnableHistoricalObjectReplication());
  5. // History data synchronization progress
  6. System.out.println(process.getHistoricalObjectProgress());
  7. // Real-time data synchronization progress
  8. System.out.println(process.getNewObjectProgress());

View the target data center

You can use ‘OSSClient.getBucketReplicationLocation’ to get the data center that the data of the bucket data center can be synchronized to:

  1. List<String> locations = ossClient.getBucketReplicationLocation("bucketName");
  2. for (String loc : locations) {
  3. System.out.println(loc);
  4. }
Thank you! We've received your feedback.