Introduction to Redis RDB
Redis rdb persistence performs point in time snapshots of our dataset at specific time intervals. Basically, rdb in redis is used to take the backup of our database in a specific time interval that we have defined. It is a very compact and single-file point-in-time representation, which is used for redis data. Redis rdb file is perfect for data backups, we can easily take backups.
- Redis rdb is very good for disaster recovery by using a single compact file which is transferred by data centers onto the S3 bucket.
- While executing the save command, it will return the string OK, indicating that no errors were defined in the specified command.
What is Redis RDB?
For the specified instance if we want to archive the rdb file every hour then it will allow us to easily restore different types of versions of the data set in case a disaster will happen. It will maximize the performance of the redis parent process which we need to persist at the time of forking the child which we do at rest.
The parent process of redis rdb will not perform disc I/O. When compared to the AOF, Redis rdb will allow for faster restarts by using larger datasets. As we all know, backup is essential for any database. It will allow us to perform restorations in the case of errors or failures. We provide protection to the redis database by enabling rdb snapshots.
How to Use Redis RDB File?
The below steps show how we can use the redis rdb file as follows. We need to install the redis on our system.
1. First we are installing the redis as follows. We are using the apt command to install the same as follows.
# apt install redis-server
2. While installing the redis server in the second step we are starting the same by using the below command as follows. Basically, it will not start automatically in the ubuntu system.
3. While starting the redis server now we are login into the server by using the below command as follows.
4. While logging, now we are executing the set command then we are using the save command to create the backup by using redis rdb as follows.
SET key1 val1 SAVE
5. After executing the save command we can see that the dump.rdb file is created in the specified location as follows.
Redis RDB Tools
Redis rdb tools is an open source memory profiling tool for redis that parses redis dump files and generates memory profiling in various formats after parsing the file. This tool provides us with visibility into memory usage and helps us in resolving a variety of customer issues. This tool is very useful for redis point-in-time backup. This tool’s first version was created in 2018.
The rdb tools version online is a SaaS version but we need the self-hosted version of rdb tools. We can start the rdb tools by using the docker container.
Below figure shows how we can install the rdb tools in our system as follows:
# pip install rdbtools
Rdb tool contains the multiple customers used to save costs. Redis dump file parses redis dump files and exports the data to JSON; it also analyses memory while parsing the dump file.
Rdb tools also provide the below utility. Basically, rdb tools are written into python.
Below is the utility of rdb tools as follows:
- Generating memory reports of our data across the keys and databases.
- Convert the dump files into JSON.
- Compare the two dump files by using standard tools.
In the below example we are using rdb tools for converting the rdb file into the JSON as follows:
# rdb --command json dump.rdb
We can also parse the output of the rdb file by using the following command. In the below example, we are displaying the key1 output as follows.
# rdb --command justkeyvals --key "key1.*" dump.rdb
Steps to Restore Data Redis RDB
1. In the first step we are checking whether the AOF is enabled or disabled in our system, Suppose it is enabled then we need to disable it. In the below example, we can see that it is enabled as it’s showing yes in output.
# redis-cli CONFIG GET appendonly
2. In above example we can see that AOF is enabled so in this step we need to disable the same by using below command as follows.
# redis-cli CONFIG SET appendonly no # redis-cli CONFIG GET appendonly
3. After disabling the AOF, now in this step we are stopping the redis server by using below command as follows.
# redis-cli SHUTDOWN
4. After shutting down the redis server, now in this step we are removing the aof and rdb file as follows.
# rm *.aof *.rdb
5. After removing the aof and rdb file, now in this step we are copying the rdb file in redis directory as follows.
# cp dump.rdb /var/lib/redis/
6. After copying the file now in this step, we are starting the redis server by using restored data as follows.
Below are the features of redis rdb as follows. Redis rdb is useful in point in time recovery for storing the data.
- Compactness – The resulting snapshot file is used to map the value of keys. Redis supports the compression of LZF.
- Performance – Because we generate snapshots in the background, rdb compression has no effect on redis database performance.
- Faster restarts – While restarting the redis server we need to load the entire dataset, same time rdb is useful.
- Durability – Redis rdb is durable, it is very reliable into the system software which as we have defined.
- Transparency – The file of rdb is trivial as compared to the rdb snapshot.
- File size – The file size of redis rdb is smaller as compared to the AOF file so we can easily restore the same.
- Persistence – The rdb backup file is more persistence as compared to the AOF file into the redis.
Given below are the FAQs mentioned:
Q1. What is the use of redis rdb?
Answer: It is used to create the snapshot backup. We are creating the specified backup as per specified time frame.
Q2. What is the use of save command in redis rdb?
Answer: Save command into the redis rdb is used for creating snapshot backup. This command will lock the another user until it finishes this operation.
Q3. What is the use of bgsave command in redis rdb?
Answer: Bgsave command into the redis rdb is used for creating snapshot backup. This command will not lock the client; instead, it will run in the background.
The parent process of redis rdb will not perform disc I/O. Redis rdb persistence takes point-in-time snapshots of our dataset at predefined intervals. Basically, rdb in redis was used to take a backup of our database at a predefined time interval.
This is a guide to Redis RDB. Here we discuss the introduction, how to use redis RDB file, tools, features and FAQs. You may also have a look at the following articles to learn more –