All Products
Search
Document Center

Object Storage Service:replication

Last Updated:Sep 11, 2023

You can manage the data replication rules by running the replication command. Data replication rules are classified into cross-region replication (CRR) and same-region replication (SRR) rules. After you configure a data replication rule, Object Storage Service (OSS) replicates the objects in the source bucket to the destination bucket located in the same region or a different region based on the data replication rule.

Note

This topic provides sample command lines that are based on the 64-bit Linux system. For other systems, replace ./ossutil64 in the commands with the specific binary name. For more information, see ossutil.

Add a data replication rule

Data replication rules allow you to replicate data from a source bucket to multiple destination buckets. You can configure up to 100 data replication rules for a bucket.

To add a data replication rule, you must first create a local file and specify the data replication rule that you want to add in the file. Then, add the data replication rule to the source bucket.

  • Command syntax

    ./ossutil64 replication --method put oss://bucketname local_xml_file

    The following table describes the parameters in the preceding command.

    Parameter

    Description

    bucketname

    The name of the bucket to which you want to add data replication rules.

    local_xml_file

    The name of the local file in which the data replication rules are specified. Example: localfile.txt.

    For more information about parameters, see PutBucketReplication.

  • Examples

    1. Create a local file named localfile.txt and specify a data replication rule in the file based on your business requirements.

      The following code provides an example on how to configure a data replication rule. This rule allows you to replicate the create, delete, and modify operations performed on objects whose names contain the srcdir prefix in the source bucket to the destination bucket named destbucket that is located in the China (Hangzhou) region. In addition, transfer acceleration is enabled, and historical data is replicated to the destination bucket.

       <?xml version="1.0" encoding="UTF-8"?>
       <ReplicationConfiguration>
          <Rule>
               <PrefixSet>
                   <Prefix>srcdir</Prefix>             
               </PrefixSet>
               <Action>ALL</Action>
               <Destination>
                   <Bucket>destbucket</Bucket>
                   <Location>oss-cn-hangzhou</Location>
                   <TransferType>oss_acc</TransferType>
               </Destination>
               <HistoricalObjectReplication>enabled</HistoricalObjectReplication>
          </Rule>
       </ReplicationConfiguration>
    2. Add the data replication rule to the source bucket named srcbucket.

      ./ossutil64 replication --method put oss://srcbucket localfile.txt
  • Sample response

    If the following output is displayed, the data replication rule is added to the srcbucket bucket.

    0.856895(s) elapsed

Enable or disable RTC

Note

You can enable Replication Time Control (RTC) when you configure a CRR task. You can also enable RTC for existing CRR tasks. You can enable RTC for CRR tasks to replicate all objects in a bucket, or to replicate objects with specific tags or whose names contain specific prefixes in a bucket.

  • Command syntax

    ./ossutil64 replication --method put --item rtc oss://bucketname local_xml_file

    The following table describes the parameters in the preceding command.

    Parameter

    Description

    bucketname

    The name of the source bucket for which you want to enable or disable RTC.

    local_xml_file

    The name of the local file that is used to enable or disable RTC. Example: localfile.xml.

    For more information about parameters, see PutBucketReplication.

  • Examples

    1. Configure the local file.

      • Enable RTC

        <?xml version="1.0" encoding="UTF-8"?>
        <ReplicationRule>
            <RTC>
                <Status>enabled</Status>
            </RTC>
            <ID>test-replication-id</ID>
        </ReplicationRule>
      • Disable RTC

        <?xml version="1.0" encoding="UTF-8"?>
        <ReplicationRule>
            <RTC>
                <Status>disabled</Status>
            </RTC>
            <ID>test-replication-id</ID>
        </ReplicationRule>
    2. Enable or disable RTC for the source bucket named srcbucket.

      ./ossutil64 replication --method put --item rtc oss://srcbucket local.xml
  • Sample response

    0.856895(s) elapsed

Query the data replication rules of a bucket

  • Command syntax

    ./ossutil64 replication --method get oss://bucketname
  • Examples

    You can run the following command to query and display the data replication rules of the srcbucket bucket:

    ./ossutil64 replication --method get oss://srcbucket

    If the following output is displayed, the data replication rules of the srcbucket bucket are obtained.

    <?xml version="1.0" encoding="UTF-8"?>
    <ReplicationConfiguration>
      <Rule>
        <ID>37417af4-f2dc-4b24-92d3-82092af6****</ID>
        <Action>ALL</Action>
        <Destination>
          <Bucket>destbucket</Bucket>
          <Location>oss-cn-beijing</Location>
        </Destination>
        <Status>doing</Status>
        <HistoricalObjectReplication>enabled</HistoricalObjectReplication>
      </Rule>
    </ReplicationConfiguration>
    
    
    0.069195(s) elapsed

Query the regions to which data can be replicated

  • Command syntax

    ./ossutil64 replication --method get --item location oss://bucketname
  • Examples

    You can run the following command to query the regions to which data in the srcbucket bucket can be replicated:

    ./ossutil64 replication --method get --item location oss://srcbucket

    If the following output is displayed, the regions to which data in the srcbucket bucket can be replicated are obtained.

    <?xml version="1.0" ?>
    <ReplicationLocation>
      <Location>oss-cn-beijing</Location>
      <Location>oss-cn-qingdao</Location>
      <Location>oss-cn-shenzhen</Location>
      <Location>oss-cn-hongkong</Location>
      <Location>oss-us-west-1</Location>
      <LocationTransferTypeConstraint>
        <LocationTransferType>
          <Location>oss-cn-hongkong</Location>
            <TransferTypes>
              <Type>oss_acc</Type>          
            </TransferTypes>
          </LocationTransferType>
          <LocationTransferType>
            <Location>oss-us-west-1</Location>
            <TransferTypes>
              <Type>oss_acc</Type>
            </TransferTypes>
          </LocationTransferType>
        </LocationTransferTypeConstraint>
      </ReplicationLocation>
    
    0.226523(s) elapsed

Query the progress of a data replication task performed on a bucket

  • Command syntax

    ./ossutil64 replication --method get --item progress oss://bucketname [ruleID]

    The following table describes the parameters in the preceding command.

    Parameter

    Description

    bucketname

    The name of the bucket on which the data replication task is performed.

    ruleID

    The ID of the data replication rule. After you specify the rule ID, the replication progress of the corresponding data replication task performed on the bucket is queried. If you do not specify the rule ID, the replication progress of all data replication tasks performed on the bucket is queried. The replication progress of the data replication tasks can only be displayed on the screen.

  • Examples

    You can run the following command to query the progress of a specific data replication task performed on the srcbucket bucket by specifying the data replication rule ID:

    ./ossutil64 replication --method get --item progress oss://srcbucket 37417af4-f2dc-4b24-92d3-82092af6****

    You can run the following command to query the progress of all data replication tasks performed on the srcbucket bucket:

    ./ossutil64 replication --method get --item progress oss://srcbucket

    If the following output is displayed, the progress of replicating existing data from the srcbucket bucket to the destination bucket before data replication is enabled is 100%. After data replication is enabled, data written to the srcbucket bucket before 06:00:59 (UTC+8) on August 9, 2021 is replicated to the destination bucket named destbucket.

    <?xml version="1.0" encoding="UTF-8"?>
    <ReplicationProgress>
      <Rule>
        <ID>37417af4-f2dc-4b24-92d3-82092af6****</ID>
        <Action>ALL</Action>
        <Destination>
          <Bucket>destbucket</Bucket>
          <Location>oss-cn-beijing</Location>
        </Destination>
        <Status>doing</Status>
        <HistoricalObjectReplication>enabled</HistoricalObjectReplication>
        <Progress>
          <HistoricalObject>1.00</HistoricalObject>
          <NewObject>2021-08-09T06:00:59.000Z</NewObject>
        </Progress>
      </Rule>
    </ReplicationProgress>
    
    
    0.125002(s) elapsed

Delete a data replication rule

  • Command syntax

    ./ossutil64 replication --method delete oss://bucketname ruleID
  • Examples

    You can run the following command to delete a data replication rule with a specific rule ID from the srcbucket bucket:

    ./ossutil64 replication --method delete oss://srcbucket 37417af4-f2dc-4b24-92d3-82092af6****

    If the following output is displayed, the data replication rule with a specific rule ID is deleted from the srcbucket bucket.

    0.069195(s) elapsed

Common options

If you use ossutil to switch to a bucket that is located in another region, add the -e option to the command to specify the endpoint of the region in which the specified bucket is located. If you use ossutil to switch to a bucket that belongs to another Alibaba Cloud account, you can add the -i option to the command to specify the AccessKey ID of the specified account, and add the -k option to the command to specify the AccessKey secret of the specified account.

For example, you can run the following command to configure data replication rules for a bucket named testbucket. The testbucket bucket is located in the China (Shanghai) region and is owned by another Alibaba Cloud account. The data replication rules are specified in the local file named localfile.txt. Sample command:

./ossutil64 replication --method put oss://testbucket localfile.txt -e oss-cn-shanghai.aliyuncs.com -i LTAI4Fw2NbDUCV8zYUzA****  -k 67DLVBkH7EamOjy2W5RVAHUY9H****

For more information about other common options that you can use for the sync command, see Common options.