Redis Learning--Persistent data backup (RDB and AOF)

Source: Internet
Author: User
Tags lzf time interval disk usage redis desktop manager redis server

Next: Installation of the Redis,redis Visual management tool (Redis Desktop Manager) under Windows Setup, Basic use, instantiation of the project

I. How the Dump.rdb file was generated

Ii. What is Redis persistence

Iii. What is the RDB for Redis?

Iv. Redis configuration file redis.config related configuration

V. Advantages of Redis

Vi. shortcomings of Redis

Redis is more powerful than memcache as a cache database: (1) More data types are supported, (2) Redis persistence.

I. How the Dump.rdb file was generated

When the Redis service is hung up, data is automatically backed up locally, depending on the Redis configuration file.

The DUMP.RDB is automatically generated by the Redis server.

By default, the Redis server program automatically iterates through the database every once in a while and writes memory snapshots in a file called "Dump.rdb", a persistence mechanism called snapshot. With snapshot, if the server goes down and the Redis server program restarts, Redis automatically loads the DUMP.RDB and restores the database to the last snapshot state.

How often do you do it once? The path and file name of the Snapshot,snapshot file, which you can specify in the Redis config file.

Second, what is the persistence of Redis

Redis provides different levels of persistence:

(1) RDB persistence mode: Ability to snapshot your data at specified intervals.

(2) aof persistence mode: Each operation to the server, when the server restarts the time to re-execute these commands to restore the original data, the AOF command appends the Redis protocol to save each write operation to the end of the file. Redis also enables background rewriting of aof files to make the aof file less bulky.

(3) If you only want your data to exist when the server is running, you can not use any persistence mode.

(4) You can also open both of these persistence modes at the same time. When the Redis service restarts, it will load the aof file to restore the original data, since the data set saved by the AoF file is generally more complete than the data set saved by the Rdb file.

Iii. What is the RDB for Redis

The RDB writes a snapshot of the in-memory dataset to disk, which is the snapshot snapshot, within a specified time interval .

It recovers when the snapshot files are written directly into memory, and Redis creates (fork) a child process for persistence, writes the data to a temporary file, and the persistence process ends with the temporary file replaced with a file that is persisted.

Throughout the process, the main process is not performing any IO operations, which ensures very high performance. If large-scale data recovery is required and the integrity of the data recovery is not sensitive, the RDB approach is more efficient than the AOF approach. 、

The disadvantage of Redis is that the last persisted data may be lost.

Iv. Redis configuration file redis.config related configuration

(i) Rdb snapshot mode persistent disk

See Redis.window.config file First

################################ snapshotting ################################## Save the DB on disk:## save<seconds> <changes># # would save the DBifBoth the given number of seconds and the given# number of write operations against the DB occurred.## in the exam PLE below the behaviour would be is to save:# afterSEC (min)ifAt least 1Key changed# afterSEC (5 min)ifAt least 10keys changed# afterSecifAt least 10000keys changed## note:you can disable saving completely by commenting off all"Save"lines.## It is also possible to remove all the previously configured save# points by adding a save directive  witha single empty string argument# likeinchThe following example:## save""Save   1save Ten 10000 # bydefaultRedis would stop accepting writesifRDB Snapshots is enabled# (at least one save point) and the latest background save failed.# This would make the user Aware (incha hard-to-do) that data is not persisting# on disk properly, otherwise chances be, that no one would notice and some# di Saster would happen.## If the background saving process would start working again Redis will# automatically allow writes Aga in.## howeverifYou have setup your proper monitoring of the Redis server# and persistence, you may want to disable Thisfeature So, Redis will#ContinueTo work as usual evenifThere is problems withdisk,# permissions, and so Forth.stop-writes-on-bgsave-error yes# Compress string objects using LZF when dump. RDB databases?# fordefaultThat's set to ' yes ' as it 's almost always a win.# If your want to save some CPUinchThe saving child set it to ' no 'but# The dataset would likely be biggerifYou have compressible values or keys.rdbcompression yes# Since version5of RDB A CRC64 checksum is placed at the end of the file.# this makes the format more resistant to corruption but the Re is a performance# hits to pay (around10%When saving and loading RDB files, so you can disable it# formaximum performances.## RDB files created withchecksum disabled has a checksum of zero that will# tell the loading code to skip the Check.rdbchecksum yes# the FIL ename where to dump the Dbdbfilename dump.rdb# the working directory.## the DB would be written inside ThisDirectory withThe filename specified# above using the' Dbfilename 'configuration directive.## The Append only File would also be created inside Thisdirectory.## Note So must specify a directory here, not a file name.dir./

4.1 How to trigger an RDB snapshot

Default snapshot configuration in a configuration file

Save 160 10000

The above meaning means:

(1) If at least one key is changed, the save operation is performed after 900 seconds (15 minutes)

(2) If at least 10 keys are changed, the save operation is performed after 300 seconds (5 minutes)

(3) If at least 10,000 keys are changed, the save operation is performed after 60 seconds (1 minutes)

Command Save: Save, whatever

The command Bgsave:redis asynchronously snapshot operations in the background, while the snapshot can also respond to client requests.

4.2 The default Rdb method holds the Dump.rdb file, and recovery recognition is also DUMP.RDB

4.3stop-writes-on-bgsave-error Yes

If an error occurs in the background save to disk, the write operation is stopped, and the RDB file is compressed using LZF, which consumes the CPU, but can reduce disk usage.

4.4rdbcompression Yes

when you save an RDB and load an RDB file, the checksum prevents errors, but it takes about 10% performance to shut down and improve performance.

4.5rdbchecksum Yes

Exported RDB file name

4.6dbfilename Dump.rdb

set the working directory, the Rdb file will be written to the directory , append only file will be stored in the directory

4.7dir./

Redis will automatically save the snapshot to disk or call Bgsave, which is done by the background process, the other clients can read and write the Redis service, the background to save the snapshot to disk will consume a lot of memory.

(ii) Persistence of AOF (append-only file) mode

Another way is to increment the way that will cause data to change the operation, persist to the file, restart Redis, by Operation Command, restore the data.

Each time the write command is executed, the data is written to Server.aofbuf.

# # More details please check the following article:# http://antirez.com/post/redis-persistence-demystified.html# # If unsure, use"Everysec". # Appendfsync alwaysappendfsync everysec# Appendfsync no# when the AOF fsync policy was set to always or ever Ysec, and a background# saving process (a background save or AOF log background rewriting) is# performing a lot of I/o against the disk, in some Linux configurations# Redis may block tooLongOn the Fsync () call. Note that there is no fix for#  ThisCurrently, as even performing fsyncincha different thread would block# our synchronous write (2) call.

When configured as always, each time the data in the SERVER.AOFBUF is written to a file, it is returned to the client, which guarantees that the data is not lost, but frequent IO operations can degrade performance.

Everysec writes once per second, which can lose operations within one second.

V. Advantages of Redis

(1) Suitable for large-scale data recovery

(2) The data integrity and consistency requirements are not high

Vi. shortcomings of Redis

(1) Make a backup at a certain interval, so if Redis accidentally hangs up, it loses all modifications after the last snapshot.

(2) Fork, the data in memory is cloned, roughly twice times the expansion of the need to consider

Redis Learning--Persistent data backup (RDB and AOF)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.