Home >Backend Development >PHP Tutorial >Redis data backup and recovery methods

Redis data backup and recovery methods

小云云
小云云Original
2017-12-14 14:06:412543browse

In this article, we share with you a simple and crude Redis data backup and recovery method, an example of migrating Redis data on different hosts, and a key point tip for backup script implementation. We hope it can help everyone.

Example

Goal: Copy the redis data on the server CentOS to the Mac machine

Steps:

Find on CentOS Dump file location


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

Instruction file is at


/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 dump.rdb on the server to the mac machine


scp root@dv:/var/lib/redis/dump.rdb ./

Restart Redis on the 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!"

If you have the above script, you can Back up redis data files using cron or other methods. The details are as follows:
First, SAVE must be performed, because the rdb file of redis is not always a complete image of the memory data. SAVE must be performed before backup, that is, sending a SAVE command to it, and then copying its rdb file.
The specific path of rdb is not necessarily the above path, it 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

Related recommendations:

Detailed Explanation of Data Backup and Recovery for MySQL Database_MySQL

Detailed Explanation for Data Backup and Recovery of MySQL Database

The most detailed explanation in history Simple MySQL data backup and restore tutorial

The above is the detailed content of Redis data backup and recovery methods. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn