You can use data replication features to automatically synchronize objects and the operations performed on the objects, such as the creation, overwriting, and deletion of objects from a source bucket to a destination bucket. OSS provides two data replication features: cross-region replication (CRR) and same-region replication (SRR).
Notes
The sample code in this topic uses the China (Hangzhou) region ID,
cn-hangzhou. By default, a public endpoint is used to access resources in a bucket. If you want to access resources in the bucket from other Alibaba Cloud services in the same region, use an internal endpoint. For more information about the regions and endpoints that OSS supports, see OSS regions and endpoints.In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.
By default, an Alibaba Cloud account is granted data replication-related permissions. If you want to replicate data as a RAM user or using temporary access credentials provided by Security Token Service (STS), you must have the required permissions. For example:
To enable data replication, you must have the
oss:PutBucketReplicationpermission.To enable or disable replication time control (RTC), you must have the
oss:PutBucketRtcpermission.To view data replication rules, you must have the
oss:GetBucketReplicationpermission.To view the destination regions to which data can be replicated, you must have the
oss:GetBucketReplicationLocationpermission.To view the progress of a data replication task, you must have the
oss:GetBucketReplicationProgresspermission.To disable data replication, you must have the
oss:DeleteBucketReplicationpermission.
Sample code
References
For more information about the API operation that you can call to enable data replication, see PutBucketReplication.
For more information about the API operation for enabling or disabling the RTC feature for existing CRR rules, see PutBucketRTC.
For more information about the API operation for querying data replication rules, see GetBucketReplication.
For more information about the API operation for querying regions to which data can be replicated, see GetBucketReplicationLocation.
For more information about the API operation for querying the progress of a data replication task, see GetBucketReplicationProgress.
For more information about the API operation for disabling data replication, see DeleteBucketReplication.