Simple and crude Redis data backup and recovery method
- 2020-05-12 06:25:17
- OfStack
The sample
Goal: copy the redis data from the server CentOS to the Mac machine
Steps:
Find the dump file location on CentOS
vi /etc/redis.conf
dbfilename dump.rdb
dir /var/lib/redis
Description file in
/var/lib/redis/dump.rdb
Find the dump file location on mac
vi /usr/local/etc/redis.conf
dbfilename dump.rdb
dir /usr/local/var/db/redis
Copy the dump.rdb on the server to the mac machine
scp root@dv:/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 scripts
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!"
Just like the above script, you can backup the redis data files by cron and other methods. The details are as follows:
SAVE must be done first, because redis's rdb file is not always the full image of the in-memory data. SAVE must be done before backup, that is, the SAVE command is sent to it, and then the rdb file can be copied.
rdb path of concrete is not 1 above, can find in 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