Simple and crude method of redis data backup and recovery

Time:2019-12-30

Example

Target: copy redis data on server CentOS to MAC

Steps:

Find the dump file location on CentOS


vi /etc/redis.conf
dbfilename dump.rdb 
dir /var/lib/redis

The documentation is available at


/var/lib/redis/dump.rdb

Find the dump file location on the MAC


vi /usr/local/etc/redis.conf


dbfilename dump.rdb 
dir /usr/local/var/db/redis

Copy dump.rdb from the server to the MAC machine


scp [email protected]:/var/lib/redis/dump.rdb ./

Restart redis on MAC


launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist 
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist

PS: backup script
Look at the following script,


#! /bin/bash

PATH=/usr/local/bin:$PATH
redis-cli SAVE

date=$(date +"%Y%m%d")
cp /var/lib/redis/6379/dump.rdb /data01/cache_backup/$date.rdb

echo "done!"

With the above script, you can back up redis data files in Cron and other ways. The details are as follows:
First, save must be performed, because the RDB file of redis is not always the complete image of the memory data. Before backup, save must be performed, that is, send the Save command to it, and then copy the RDB file.
The specific path of RDB is not necessarily the above path, which can be found in the redis configuration file, / etc / redis / 6379.conf


# The filename where to dump the DB
dbfilename dump.rdb

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# Also the Append Only File will be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis/6379

Recommended Today

Introduction to Chinese multimodal benchmark evaluation Muge

background In recent years, the successful practice of large-scale neural network model and pre training technology not only promotes the rapid development of computer vision and natural language processing, but also promotes the research of multimodal representation learning. In 2020, Jeff Dean pointed out that multimodal research will be a major trend in future research. […]