How to Use “Data Flashback” on ApsaraDB for Redis to Recover Data by Time Point

Alibaba Tech
6 min readOct 27, 2020

In the data era, business data is the core asset for enterprises. Customers in various industries are constantly seeking for more powerful and fine-grained database backup and recovery capabilities to decrease commercial risks caused by data loss and business logic errors. For example, in the gaming industry, a large number of customers demand for the “game correction” capability to deal with the risk of misoperations or failures.

In 2020, an employee of a listed company accidentally deleted the company’s business-critical database. As a result, the market value of the company was severely affected. Conventional scheduled or manual backups of data are not ideal solutions for the preceding incidents because data backup and “Black Swan” incidents (abnormal incidents that are hard to predict) happen unpredictably. To prevent the incidents above, the ideal solution is to use second-level granularity for backing up data. In this case, most of the data can be recovered should a “Black Swan” incident occur.

Alibaba Cloud provides data flashback for traditional relational databases, such as Oracle to recover data by time point. However, similar functions are seldom provided for mainstream cache products like Redis and Memcached. This may because as caching products, data loss can be tolerated by its user. Also, as an alternative, data in cache can be reloaded through persistence techniques, which is quite useful for transactional relational databases deployed in cache products.

However, as many customers are increasingly demanding for high-performance applications with low latency, businesses are required to simplify their architectures in scenarios with extreme requirements for low latency, such as in the gaming industry. It turns out that more and more companies are using Redis as their primary in-memory database, which brings greater challenges to the data security and recoverability in Redis.

As a leading product in the industry, ApsaraDB for Redis has a series of brilliant versions with proven performance in China. While managing the Redis Community Edition, Alibaba Cloud is also striving to independently develop enhanced key-value storage product Tair which is an enhanced edition of Redis and compatible with Redis protocols.

To satisfy the demands of customers, “higher security” becomes an important feature of services that ApsaraDB for Redis provides. For the enhanced edition of Tair, Alibaba Cloud has launched a data flashback feature to enable customers to recover data from a specific Redis instance at a specific point in time, preparing them for possible risks in advance. The flashback feature is illustrated in the following figure.

It only takes just a few simple steps to use this hack to help you traverse data changes, which allows you restore the database to any time points along the way.

  • Create or startup a Redis instance of Enterprise Enhanced Edition (Tair)
  • Enable data flashback function
  • Read and write Redis database normally
  • Once the instant data recovery requirement occurs, select the corresponding instance and the point in time to be recovered to generate a new instance.
  • Toggle the instance address for the applications related when the new instance is ready.

Here is a simple example:

First, write some data to a Tair instance on Alibaba Cloud by using the following scripts.

% cat preparerepldata.sh
#!/bin/bash

echo "started at: `date +%m%d%H%M%S`"
for i in `seq -f "%010g" 1 $1`
do
namerand=$[ $RANDOM % 3 ]
timerand=`date +%m%d%H%M%S`
nationrand=$[ $RANDOM % 3 ]
redis-cli -h r-t4nq2viog3z4rshoxxpd.redis.singapore.rds.aliyuncs.com -a 'gnuhpc:Pa$$w0rd' hset userprofile foo$timerand $namerand
sleep 0.75 #consider the latency for connection establish
done

echo "ended at: `date +%m%d%H%M%S`"

Run the scripts above to write time-stamped Key-Values (KV) data to a hash structured object called userprofile at a rate of about once per second. A total of 120 keys will be written when it's finished, which we use to simulate actual business data writing.

% bash preparerepldata.sh   120
OK
OK


% redis-cli -h hosts -a 'username:password' hkeys userprofile | wc -l
120
% redis-cli -h hosts -a 'username:password' hkeys userprofile | sort -n
foo0803202709

foo0803202909

As shown above, 120 data records were written between 20:27:09 and 20:29:09 on August 3.

Then, it was found that data risks occurred during the run time of the business mentioned above after 20:28:10 on August 3. In this case, we need to create a new database instance and restore the data from the time point before August 3, 20:28:10 to the new database instance.

We can use the ApsaraDB for Redis console to complete the entire process. Go to the Redis Console on Alibaba Cloud, show the details of your Redis instance, and click on the “Backup and Recovery” function slot in the left navigation bar. Then, select “Data Flashback” and click the “Flashback Now” button. After that, select the source type of your clone, which should be “Point-in-time”. And then choose the specified time point that you want to recover to in “Backup Point in Time” settings.

For the flashback function, the only requirement of the target instance is the larger storage capacity compared with the original one. The target instance is exactly what we created just now for restoring to a specific time point. This is to say that users have the freedom to choose the type of the target instance from Standard (master-replica), Cluster, and Read Write Spliting, since the database architecture is no longer a key factor and the architectures of both instances can be different.

After clicking the “pay” process, the restoration would be complete once the instance is created.

Let’s connect to the new instance and check the restored data.

% redis-cli -h hosts -a 'username:password'   hkeys userprofile | wc -l
62

% redis-cli -h hosts -a 'username:password' hkeys userprofile | sort -n
foo0803202709

foo0803202810

It shows that the data has been successfully recovered to its status at 20:28:10 on August 3, and as expected, none of the data changes after this point of time took effect. This helps users avoid data risks that occurred after the specified time point.

Conclusion

As the world’s leading database enterprise, with the core concept of Faster, Stronger, and More Secure as its product design principle, Alibaba Cloud Database Business Group is committed to providing users with database products characterized by ultimate performance, high stability, high security, and reliability.

As a practice of ‘More Secure’, the data flashback function of Tair in the Enterprise Edition of ApsaraDB for Redis, can meet the requirement of data recovery at a specified time point in a second-level. With this feature, the precious data assets of customers can be protected robustly. And by providing the highest level of protection for valuable data assets, customers are more likely to use Redis as an in-memory database to simplify architecture and rapid business iteration. In addition, Redis is also supported by MyBase, a dedicated cluster of cloud database, which is the customized and optimized solution provided by Alibaba Cloud for large and medium-sized enterprises. Characterized by exclusive resources, independent O&M, and the hybrid deployment of multi-databases, this solution fills the gap in the market. It enables users to enjoy the flexibility of cloud database while meeting their requirements for compliance, high performance, and security of database.

With the data flashback function provided by ApsaraDB for Redis Enhanced Edition, users can recover the data of specified Redis instances at a specified time point, freeing users from concerns of data loss! For more information, see https://www.alibabacloud.com/help/doc-detail/148479.htm

Alibaba Tech

First hand and in-depth information about Alibaba’s latest technology → Facebook: “Alibaba Tech”. Twitter: “AlibabaTech”.

--

--

Alibaba Tech

First-hand & in-depth information about Alibaba's tech innovation in Artificial Intelligence, Big Data & Computer Engineering. Follow us on Facebook!