×
Community Blog Enable Versioning to Protect Valuable Data in Alibaba Cloud OSS

Enable Versioning to Protect Valuable Data in Alibaba Cloud OSS

This article explains the benefits of the versioning feature of Alibaba Cloud OSS.

1. Background

Alibaba Cloud Object Storage Service (OSS) is a platform that stores massive data and supports a wide range of applications. When you use OSS, you will inevitably encounter problems with accidental and improper operations, program bugs, overwriting, and issues that result in the loss of important data. Data loss can cause emergencies with severe consequences. In serious situations, you could even lose your job. Every year, lots of data is deleted accidentally on OSS. This is why we developed a versioning feature that allows you to retrieve previous data versions to reverse accidental deletion.

2. Introduction to Versioning

When versioning is enabled for a bucket, OSS assigns a unique ID for each version of all objects in the bucket. The content and ACL of existing objects in the bucket remain unchanged. Versioning prevents unintended overwrites and deletions on your data. You can also use versioning to retrieve a previous version of an object and recover the previous version as the current version at any time. For more details about the versioning feature, please see the introduction on the official website.

1

As shown in the preceding figure, when you perform the PutObject operation to upload the same object with the key of example.jpg, OSS assigns a new unique version ID of 222222 to the object and stores this version as the current version in the bucket. In this case, version 111111 becomes a previous version. When you perform the PutObject operation to upload the same object with the key of example.jpg again, OSS assigns a new unique version ID of 333333 to the object and stores this version as the current version in the bucket. Then, versions 111111 and 222222 become previous versions.

3. Prevent Accidental Data Deletion

3.1 Enable Versioning

You can enable versioning in two ways:

  • Activate versioning during bucket creation
  • Enable versioning for an existing bucket

2

By enabling versioning for an existing bucket, you can configure versioning for existing OSS data to protect historical data.

3.2 Upload an Object

When versioning is enabled, you can navigate to the Show Previous Versions of the Files box in the console and select a previous version, as shown in the following figure.

3

In the console, if you upload an object with the same name as an existing object, multiple versions are generated. Among these versions, the one marked (Latest Version) indicates the latest object with the most recent update time.

3.3 Delete an Object

After you enable versioning, deleting an object does not delete the object completely; it inserts a deletion marker, as shown in the following figure.

4

After an object is "deleted" this way, it is not displayed in the console unless you select Show Previous Versions of the Files. The object is not deleted completely and can be restored if necessary.

3.4 Convenient Data Recovery

If versioning is enabled, previous versions of data are not deleted. Therefore, you can restore historical data yourself by going through the procedure shown in the following figure.

  • Step 1: Select Show Previous Versions of the Files to display previous versions. Objects with the deletion marker are deleted objects.
  • Step 2: Delete the deletion marker to make the corresponding data visible in the console once again.
  • Step 3: After the marker is deleted, the most recent version becomes the Latest Version. Then, this object is displayed in the console regardless of whether you select Show Previous Versions of the Files.

5

Therefore, when versioning is enabled, you can restore data without any assistance. This means you do not have to worry about the consequences of accidental operations, program bugs, overwriting, or other errors.

4. Use Tools to Batch Restore Deleted Data

The OSS console provides an easy way to restore individual objects. However, this is an inefficient and time-consuming method if you need to restore a large number of files when a directory is deleted. To address this need, OSS provides the ossutil tool to perform multiple data repairs and improve repair efficiency.

4.1 Batch Repair by Specified Prefix

6

The overall process of this scenario is shown in the preceding figure. The relevant command is shown below:

 $) ./ossutilmac64 ls oss://test-jsj-versioning/prefix/ --all-versions
| grep -rn "true        true           oss://"
| awk -F ' '  '{drcmd=("./ossutilmac64 rm " $10" --version-id "$7);print drcmd}'
| sh

Here, deletion markers display "true true," so you only need to delete the markers that match the prefix to restore the corresponding objects.

4.2 Batch Repair by Specified Time

7

The overall process of this scenario is shown in the preceding figure. The relevant command is shown below:

 ./ossutilmac64 ls oss://test-jsj-versioning/pre- --all-versions
| awk '{(dtime=($1" "$2" "$3" "$4));
if ((dtime>="2020-06-16 16:55:05 +0800 CST")
&& (dtime<="2020-06-16 16:55:40 +0800 CST")) print}'
| grep -rn "true        true           oss://"
| awk -F ' '  '{drcmd=("./ossutilmac64 rm " $10" --version-id "$7);print drcmd}'
| sh

You only need to delete the markers that match the time range to restore the corresponding objects.

4.3 Batch Repair Based on a Repair List File

8

The overall process of this scenario is shown in the preceding figure. The relevant command is shown below:

 for i in cat file_list;
 do
./ossutilmac64 ls oss://test-jsj-versioning/$i --all-versions
| grep -rn "true        true           oss://"
| awk -F ' '  '{drcmd=("./ossutilmac64 rm " $10" --version-id "$7);print drcmd}'
| sh;
done

You only need to traverse the repair list file and delete the listed deletion markers to restore the corresponding objects.

5. Combine Versioning and Lifecycle Management to Reduce Costs

After you enable versioning, previous versions are retained even when an object is deleted, adding to your storage costs. You can adopt a solution that combines versioning and lifecycle management to enjoy the benefits of versioning at a lower cost, as shown in the following figure:

9

In the lifecycle configuration, you can set policies for current versions (with deletion markers) and previous versions to convert the objects to a specified type after a certain time. This will reduce storage costs. You can also set policies to delete objects after a specified number of days. For example, if you set a policy to delete objects after 30 days, the corresponding data can only be restored within 30 days, similar to the retention period of a recycle bin.

6. Summary

Accidental data deletion is a serious problem that is difficult to avoid. After enabling the OSS versioning feature, you will enjoy an effective data protection solution. After combining versioning and lifecycle management, you can set data retention policies to reduce your storage costs while protecting your data. We hope you will take advantage of this feature soon to protect all of your valuable data.

0 0 0
Share on

Alibaba Cloud Storage

58 posts | 8 followers

You may also like

Comments