簡單粗暴的Redis資料備份和恢複方法_Redis

來源:互聯網
上載者:User

樣本

目標:把伺服器CentOS上的redis資料複製到Mac機上

步驟:

在CentOS上找dump檔案位置

vi /etc/redis.confdbfilename dump.rdb dir /var/lib/redis

說明檔案在

/var/lib/redis/dump.rdb

在mac上尋找dump檔案位置

vi /usr/local/etc/redis.confdbfilename dump.rdb dir /usr/local/var/db/redis

拷貝伺服器上的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/bashPATH=/usr/local/bin:$PATHredis-cli SAVEdate=$(date +"%Y%m%d")cp /var/lib/redis/6379/dump.rdb /data01/cache_backup/$date.rdbecho "done!"

有如上指令碼,便可以cron等方式備份redis資料檔案了。細節如下:
首先必須進行SAVE, 因為redis的rdb檔案並非總是記憶體資料的完整鏡像,備份之前必須進行SAVE,即向其發送SAVE命令,其次拷貝走其rdb檔案即可。
rdb的具體路徑不一定是如上路徑,可以在redis設定檔中尋找, /etc/redis/6379.conf

# The filename where to dump the DBdbfilename 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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.