All Products
Search
Document Center

Object Storage Service:replication

Last Updated:Nov 15, 2024

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.

Usage notes

  • To create a data replication rule or enable Replication Time Control (RTC) for a bucket, you must have the oss:PutBucketReplication permission. To query data replication rules of a bucket, you must have the oss:GetBucketReplication permission. To delete data replication rules of a bucket, you must have the oss:DeleteBucketReplication permission. To query data replication progress of a data replication task performed on a bucket, you must have the oss:GetBucketReplicationProgress permission. To query the regions of the buckets to which data can be replicated, you must have the oss:GetBucketReplicationLocation permission. For more information, see Attach a custom policy to a RAM user.

  • For ossutil 1.6.16 and later, you can directly use ossutil as the binary name in the command line. You do not need to update the binary name based on the operating system. For ossutil earlier than 1.6.16, you need to update the binary name based on the operating system. For more information, see ossutil command reference.

Add a data replication rule

Data replication rules allow you to replicate data from a source bucket to one or more destination buckets. You can configure up to 100 data replication rules for a bucket. For more information about data replication, see CRR overview.

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

    ossutil 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 for which you want to create data replication rules.

    local_xml_file

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

    For more information, see PutBucketReplication.

  • Examples

    1. Create a file named localfile.xml on your local computer and configure 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 and modify operations performed on objects whose names contain the srcdir prefix in the source bucket to a destination bucket named destbucket that is located in the China (Hangzhou) region. In addition, this rule also specifies that 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>PUT</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 a source bucket named srcbucket:

      ossutil replication --method put oss://srcbucket localfile.xml
  • Sample output

    The following output indicates that the data replication rule is created for 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

    ossutil 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 stores the RTC configurations. Example: localfile.xml.

    For more information, 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 a source bucket named srcbucket:

      ossutil replication --method put --item rtc oss://srcbucket local.xml
  • Sample output

    0.856895(s) elapsed

Query the data replication rules of a bucket

  • Command syntax

    ossutil replication --method get oss://bucketname
  • Examples

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

    ossutil replication --method get oss://srcbucket

    The following sample output indicates that the data replication rules of the srcbucket bucket are queried:

    <?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

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

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

    ossutil replication --method get --item location oss://srcbucket

    The following sample output indicates the regions of the buckets to which data can be replicated are queried:

    <?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

    ossutil 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 for which you want to query data replication progress.

    ruleID

    The ID of the data replication rule. After you specify the rule ID, the replication progress associated with the rule is queried. If you do not specify a rule ID, the replication progress associated with all data replication rules for the bucket is queried. The replication progress can only be displayed on the screen.

  • Examples

    You can run the following command to query the data replication progress associated with a specific data replication rule for the srcbucket bucket:

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

    You can run the following command to query the data replication progress associated with all data replication rules for the srcbucket bucket:

    ossutil replication --method get --item progress oss://srcbucket

    If the following output is displayed, the progress of replicating historical data from the srcbucket bucket to the destbucket 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

    ossutil replication --method delete oss://bucketname ruleID
  • Examples

    You can run the following command to delete a specific data replication rule that is configured for the srcbucket bucket:

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

    The following sample output indicates that the specified data replication rule is deleted.

    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 specify the endpoint of the region in which the bucket is located. If you use ossutil to switch to a bucket that belongs to another Alibaba Cloud account, add the -i option to specify the AccessKey ID of the specified account, and add the -k option to specify the AccessKey secret of the specified account.

For example, you can run the following command to create a data replication rule in the localfile.txt file for the testbucket bucket that is located in the China (Shanghai) region and owned by another Alibaba Cloud account: Example:

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

For more information about common options, see Common options.