Data synchronization
Updated at:2025-11-03
Set data synchronization rules
| 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 | Is it 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 the storage class is to be consistent with that of 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; if it is a multi-AZ type bucket, the available values are MAZ_STANDARD_IA and MAZ_STANDARD. |
| 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 the storage class is to be consistent with that of 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; if it is a multi-AZ type bucket, the available values are MAZ_STANDARD_IA and MAZ_STANDARD. |
| replicateDeletes | Yes | It indicates whether Delete synchronization function is enabled. It is enabled,disabled. |
If users need to enable data synchronization between buckets, the following code can achieve this:
Python
1bucket_name = "<YOUR_BUCKET_NAME>"
2rule_id = "sample-rep-config"
3dst_bucket_name = "<DESTINATION_BUCKET_NAME>"
4replication = {
5 "status":"enabled",
6 "resource":[
7 bucket_name + "/*"
8 ],
9 "destination":
10 {
11 "bucket": dst_bucket_name,
12 "storageClass":"COLD"
13 },
14 "replicateHistory":
15 {
16 "bucket": dst_bucket_name,
17 "storageClass":"COLD"
18 },
19 "replicateDeletes":"enabled",
20 "id": rule_id
21 }
22# test put bucket replication
23bos_client.put_bucket_replication(bucket_name, replication)
Get specified data synchronization rules
Users can retrieve synchronization details for a specific bucket ID, such as the source and destination bucket names, storage class, whether historical replication is enabled, synchronization policies, destination region, and more. As demonstrated in the example code below:
Python
1response = bos_client.get_bucket_replication(bucket_name, id=rule_id)
2print("id:{}, status:{}, resource:{}, destination:{}, replicateDeletes:{}, replicateHistory:{}".format(response.id, response.status, response.resource, response.destination, response.replicate_deletes, response.replicate_history))
Delete specified data synchronization rule
If users want to delete the data synchronization with a specified ID in the bucket, the following code can achieve this:
Python
1bos_client.delete_bucket_replication(bucket_name ,id=rule_id)
List data synchronization rules
If users want to get all replication synchronization rules of the bucket, the following code can achieve this:
Python
1response = bos_client.list_bucket_replication(bucket_name)
2print(response.rules)
Get the process status of specified data synchronization rules
If users want to get the progress status of data synchronization replication with a specified ID, the following code can achieve this:
Python
1response = bos_client.get_bucket_replication_progress(bucket_name, id=rule_id)
2print("status:{}, historyReplicationPercent:{}, latestReplicationTime:{}".format(response.status, response.history_replication_percent, response.latest_replication_time))
