簡單粗暴的Redis數(shù)據(jù)備份和恢復(fù)方法
示例
目標(biāo):把服務(wù)器CentOS上的redis數(shù)據(jù)復(fù)制到Mac機上
步驟:
在CentOS上找dump文件位置
vi /etc/redis.conf dbfilename dump.rdb dir /var/lib/redis
說明文件在
/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機器
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ù)文件了。細節(jié)如下:
首先必須進行SAVE, 因為redis的rdb文件并非總是內(nèi)存數(shù)據(jù)的完整鏡像,備份之前必須進行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ù)結(jié)構(gòu)之簡單動態(tài)字符串sds
Redis 的 string 類型為何使用sds而不是 C 字符串,本文主要介紹 string 的數(shù)據(jù)結(jié)構(gòu)—— 簡單動態(tài)字符串(Simple Dynamic String) 簡稱sds的相關(guān)知識,需要的朋友可以參考下2021-11-11Redis實現(xiàn)排行榜及相同積分按時間排序功能的實現(xiàn)
這篇文章主要介紹了Redis實現(xiàn)排行榜及相同積分按時間排序,本文通過實例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08使用RediSearch實現(xiàn)在Redis中全文檢索
RediSearch?是?Redis?的一個插件,它為?Redis?數(shù)據(jù)庫添加了全文搜索和查詢功能,使開發(fā)人員能夠在?Redis?中高效地執(zhí)行全文檢索操作,下面我們就來看看是具體如何使用的吧2023-08-08redis key過期監(jiān)聽的實現(xiàn)示例
在Redis中,我們可以為Key設(shè)置過期時間,當(dāng)Key的過期時間到達后,Redis會自動將該Key標(biāo)記為已失效,本文就來介紹一下redis key過期監(jiān)聽的實現(xiàn)示例,感興趣的可以了解一下2024-03-03redis計數(shù)器與數(shù)量控制的實現(xiàn)
使用Redis計數(shù)器可以輕松地解決數(shù)量控制的問題,同時還能有效地提高應(yīng)用的性能,本文主要介紹了redis計數(shù)器與數(shù)量控制的實現(xiàn),具有一定的參考價值,感興趣的可以了解一下2023-12-12