This article we share with you a simple and rough redis data backup and recovery method, there is an example of migrating Redis data on different hosts, and a key point of backup script implementation, hoping to help everyone.
Example
Goal: Copy Redis data from a server CentOS to a Mac machine
Steps:
Find the dump file location on CentOS
Vi/etc/redis.confdbfilename Dump.rdb Dir/var/lib/redis
The description file is
/var/lib/redis/dump.rdb
Find the dump file location on your Mac
Vi/usr/local/etc/redis.confdbfilename 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 Script
Look at the following script,
#! /bin/bashpath=/usr/local/bin: $PATHredis-cli savedate=$ (date + "%y%m%d") cp/var/lib/redis/6379/dump.rdb/data01/ cache_backup/$date. Rdbecho "done!"
Like a script, you can back up Redis data files in a cron way. Details are as follows:
You must first save, because Redis's Rdb file is not always a full image of the memory data, it must be save before backup, that is, send the Save command, and then copy the Rdb file.
The specific path to the RDB is not necessarily the same as above, and can be found in the Redis configuration file,/etc/redis/6379.conf
# the filename where to dump the Dbdbfilename dump.rdb# the working directory.## the DB would be Written inside this directory, with the filename specified# above using the ' dbfilename ' configuration directive.## Also t He Append only file would be created inside this directory.## Note so you must specify a directory here, not a File name. dir/var/lib/redis/6379