簡(jiǎn)單粗暴的Redis數(shù)據(jù)備份和恢復(fù)方法
示例
目標(biāo):把服務(wù)器CentOS上的redis數(shù)據(jù)復(fù)制到Mac機(jī)上
步驟:
在CentOS上找dump文件位置
vi /etc/redis.conf dbfilename dump.rdb dir /var/lib/redis
說(shuō)明文件在
/var/lib/redis/dump.rdb
在mac上查找dump文件位置
vi /usr/local/etc/redis.conf dbfilename dump.rdb dir /usr/local/var/db/redis
拷貝服務(wù)器上的dump.rdb到mac機(jī)器
scp root@dv:/var/lib/redis/dump.rdb ./
在mac上重啟Redis
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
PS:備份腳本
看如下腳本,
#! /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!"
有如上腳本,便可以cron等方式備份redis數(shù)據(jù)文件了。細(xì)節(jié)如下:
首先必須進(jìn)行SAVE, 因?yàn)閞edis的rdb文件并非總是內(nèi)存數(shù)據(jù)的完整鏡像,備份之前必須進(jìn)行SAVE,即向其發(fā)送SAVE命令,其次拷貝走其rdb文件即可。
rdb的具體路徑不一定是如上路徑,可以在redis配置文件中查找, /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
相關(guān)文章
Redis中鍵和數(shù)據(jù)庫(kù)通用指令詳解
這篇文章主要為大家介紹了Redis中鍵和數(shù)據(jù)庫(kù)通用指令基本操作詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08
redis解決高并發(fā)看門狗策略的實(shí)現(xiàn)
本文主要介紹了redis解決高并發(fā)看門狗策略的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2025-02-02
淺談內(nèi)存耗盡后Redis會(huì)發(fā)生什么
這篇文章主要介紹了淺談內(nèi)存耗盡后Redis會(huì)發(fā)生什么,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
Redis底層數(shù)據(jù)結(jié)構(gòu)SkipList的實(shí)現(xiàn)
本文主要介紹了Redis底層數(shù)據(jù)結(jié)構(gòu)SkipList的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05

