All Products
Search
Document Center

Object Storage Service:replication

Last Updated:Apr 03, 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), you must have the oss:PutBucketReplication permission. To query data replication rules, you must have the oss:GetBucketReplication permission. To delete data replication rules, you must have the oss:DeleteBucketReplication permission. To query data replication progress, you must have the oss:GetBucketReplicationProgress permission. To query regions 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.

  • 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 corresponding binary name. 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

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

    The following table describes the parameters in the syntax.

    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 specified. 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 data replication rule synchronizes 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. The rule also specifies that transfer acceleration is enabled to accelerate data transfers for data replication and that replication of historical data is enabled.

       <?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.xml
  • 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

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

    The following table describes the parameters in the syntax.

    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 configuration. 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 the source bucket named srcbucket.

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

    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

    The following sample output indicates that 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

    The following sample output indicates the regions to which data 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 and options in the syntax.

    Parameter/Option

    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 be displayed only to 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:

    ./ossutil64 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:

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

    The following sample output indicates that the progress of replicating historical data (data that already exists before data replication is enabled) from the srcbucket bucket to the destination bucket is 100%. After data replication is enabled, data written to the srcbucket bucket before the time point 2021-08-09T06:00:59.000Z is replicated to the destination bucket.

    <?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 specific data replication rule that is configured for the srcbucket bucket:

    ./ossutil64 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 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, 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 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:

./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.