{"id":103460,"date":"2024-08-27T19:21:13","date_gmt":"2024-08-27T11:21:13","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=103460"},"modified":"2024-08-27T19:21:13","modified_gmt":"2024-08-27T11:21:13","slug":"backup-restore-redis","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/backup-restore-redis.html","title":{"rendered":"Centos 7 backup and restore Redis data"},"content":{"rendered":"

\"\"<\/p>\n

\u4f55\u4e3aRedis\uff1f<\/strong><\/span><\/div>\n

Redis\u662f\u5185\u5b58\u4e2d\u7684\u952e\u503c\u7f13\u5b58\u548c\u5b58\u50a8\uff08\u5373\u6570\u636e\u5e93\uff09\uff0c\u4e5f\u53ef\u4ee5\u6c38\u4e45\u4fdd\u5b58\u5230\u78c1\u76d8\u3002\u5728\u672c\u6587\u4e2d\uff0c\u4f60\u5c06\u4e86\u89e3\uff0c\u5982\u4f55\u5728Centos 7\u4e0a\u5907\u4efd\u8fd8\u539f\u60a8\u7684redis\u6570\u636e\u5e93\u3002<\/p>\n

\u5907\u4efd\u8fd8\u539f\u8bf4\u660e<\/strong><\/span><\/div>\n

\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cRedis\u6570\u636e\u5c06\u4fdd\u5b58\u5230\u78c1\u76d8\u4e2d\u7684.rdb\u6587\u4ef6\u4e2d\uff0c\u8be5\u6587\u4ef6\u662fRedis\u6570\u636e\u96c6\u7684\u65f6\u95f4\u70b9\u5feb\u7167\u3002\u5feb\u7167\u662f\u6309\u7167\u6307\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u8fdb\u884c\u7684\uff0c\u6240\u4ee5\u5bf9\u4e8e\u5907\u4efd\u6765\u8bf4\u662f\u5b8c\u7f8e\u7684\u3002<\/p>\n

\u6570\u636e\u5907\u4efd\u7bc7<\/strong><\/span><\/div>\n

\u5728Centos 7\u548c\u5176\u4ed6Linux\u53d1\u884c\u7248\u4e2d\uff0cRedis\u6570\u636e\u5e93\u76ee\u5f55\u9ed8\u8ba4\u662f\/var\/lib\/redis\u3002\u4f46\u662f\uff0c\u5982\u679c\u60a8\u66f4\u6539\u4e86redis\u5b58\u50a8\u4f4d\u7f6e\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7\u952e\u5165\u4ee5\u4e0b\u547d\u4ee4\u67e5\u627e\uff1a<\/p>\n

\r\n[root@renwolecom ~]# find \/ -name *rdb\r\n\r\n\u4f7f\u7528redis-cli\u7ba1\u7406\u5de5\u5177\u8fdb\u5165\u6570\u636e\u5e93\uff1a\r\n\r\n[root@renwolecom ~]# redis-cli\r\n\u7531\u4e8e\u5927\u90e8\u5206\u6570\u636e\u90fd\u8fd0\u884c\u5728\u5185\u5b58\u4e2d\uff0credis\u53ea\u4f1a\u6bcf\u9694\u4e00\u6bb5\u65f6\u95f4\u4fdd\u5b58\u4e00\u6b21\uff0c\u4e3a\u83b7\u53d6\u6700\u65b0\u526f\u672c\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a\r\n\r\n10.10.204.64:6379> save\r\nOK\r\n(1.02s)\r\n\u53e6\u5916\uff0c\u5982\u679cRedis\u8bbe\u7f6e\u4e86\u7528\u6237\u8ba4\u8bc1\uff0c\u5c31\u9700\u8981\u5148\u9a8c\u8bc1\uff0c\u518d\u4fdd\u5b58\uff0c\u4f8b\u5982\uff1a\r\n\r\n10.10.204.64:6379> auth RenwoleQxl5qpKHrh9khuTW\r\n10.10.204.64:6379> save\r\n\u4e4b\u540e\u8fdb\u884c\u5907\u4efd\u5373\u53ef\uff0c\u4f8b\u5982\uff1a\r\n\r\n[root@renwolecom ~]# cp \/var\/lib\/redis\/dump.rdb \/apps\/redis-backup-20180129\r\n<\/pre>\n
\u6570\u636e\u8fd8\u539f\u7bc7<\/strong><\/span><\/div>\n

\u6062\u590d\u5907\u4efd\u9700\u8981\u60a8\u4f7f\u7528\u6062\u590d\u6587\u4ef6\u66ff\u6362\u73b0\u6709\u7684Redis\u6570\u636e\u5e93\u6587\u4ef6\u3002\u4e3a\u4fdd\u8bc1\u539f\u59cb\u6570\u636e\u6587\u4ef6\u4e0d\u88ab\u7834\u574f\uff0c\u6211\u4eec\u5efa\u8bae\u5c3d\u53ef\u80fd\u6062\u590d\u5230\u65b0\u7684Redis\u670d\u52a1\u5668\u3002<\/p>\n

\u505c\u6b62Redis\u6570\u636e\u5e93\uff0c\u4e00\u65e6\u505c\u6b62\uff0cRedis\u6570\u636e\u5e93\u5904\u4e8e\u8131\u673a\u72b6\u6001\u3002<\/p>\n

\r\n[root@renwolecom ~]# systemctl stop redis\r\n\u5982\u679c\u6062\u590d\u5230\u539f\u59cbRedis\u670d\u52a1\u5668\uff0c\u8bf7\u91cd\u547d\u540d\u5f53\u524d\u6570\u636e\u6587\u4ef6\uff0c\u4e4b\u540e\u518d\u8fdb\u884c\u6062\u590d\uff1a\r\n\r\n[root@renwolecom ~]# mv \/var\/lib\/redis\/dump.rdb \/var\/lib\/redis\/dump.rdb.old\r\n[root@renwolecom ~]# cp -p \/apps\/redis-backup-20180129\/dump.rdb \/var\/lib\/redis\/dump.rdb\r\n\u8bbe\u7f6edump.rdb\u6587\u4ef6\u6743\u9650\uff0c\u62f7\u8d1d\u8fc7\u6765\u7684\u6570\u636e\u6587\u4ef6\uff0c\u53ef\u80fd\u4e0d\u5177\u5907Redis\u7528\u6237\u53ca\u8bfb\u53d6\u6743\u9650\uff0c\u9700\u8981\u624b\u52a8\u8d4b\u4e88\uff1a\r\n\r\n[root@renwolecom ~]# chown redis:redis \/var\/lib\/redis\/dump.rdb\r\n[root@renwolecom ~]# chmod 660 \/var\/lib\/redis\/dump.rdb\r\n\u542f\u52a8redis\r\n\r\n[root@renwolecom ~]# systemctl start redis\r\n\u5927\u529f\u544a\u6210\uff01\u73b0\u5728\u4f60\u53ef\u4ee5\u767b\u5f55redis\u6838\u5b9e\u6570\u636e\u4e86\u3002\r\n<\/pre>\n

\u6ce8\u610f\u8bf4\u660e\uff1a<\/p>\n

\u6839\u636e\u9700\u6c42\uff0c\u5173\u95edAOF\uff0cAOF\u8ddf\u8e2a\u6bcf\u4e2a\u5199\u64cd\u4f5c\u5230Redis\u6570\u636e\u5e93\u3002\u7531\u4e8e\u6211\u4eec\u8bd5\u56fe\u4ece\u65f6\u95f4\u70b9\u5907\u4efd\u4e2d\u6062\u590d\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u5e0c\u671bRedis\u91cd\u65b0\u521b\u5efa\u5b58\u50a8\u5728\u5176AOF\u6587\u4ef6\u4e2d\u7684\u64cd\u4f5c\u3002<\/p>\n

\u662f\u5426\u5f00\u542fAOF\u53ef\u4ee5\u901a\u8fc7\u67e5\u770b\u6587\u4ef6\u83b7\u6089\uff1a<\/p>\n

\r\n[root@renwolecom ~]# ls \/var\/lib\/redis\/\r\n<\/pre>\n

\u5982\u679c\u770b\u5230.aof\u540e\u7f00\u7684\u6587\u4ef6\uff0c\u8bf4\u660e\u4f60\u542f\u7528\u4e86AOF\u3002<\/p>\n

\u91cd\u547d\u540d.aof\u6587\u4ef6\uff0c<\/p>\n

\r\n[root@renwolecom ~]# mv \/var\/lib\/redis\/*.aof \/var\/lib\/redis\/appendonly.aof.old\r\n<\/pre>\n

\u5982\u679c\u6709\u591a\u4e2a.aof\u6587\u4ef6\uff0c\u8bf7\u5355\u72ec\u547d\u540d\u3002<\/p>\n

\u7f16\u8f91\u4f60\u7684Redis\u914d\u7f6e\u6587\u4ef6\u6682\u65f6\u5173\u95edAOF\uff1a<\/p>\n

\r\n[root@renwolecom ~]# vim \/etc\/redis\/redis.conf\r\nappendonly no\r\n<\/pre>\n
\n

\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/renwole.com\/archives\/1147<\/a><\/p>\n

\u672c\u6587\u5730\u5740\uff1ahttps:\/\/lrxjmw.cn\/backup-restore-redis.html<\/a>\u7f16\u8f91\uff1a\u5434\u5411\u5e73\uff0c\u5ba1\u6838\u5458\uff1a\u9004\u589e\u5b9d<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"

\u4f55\u4e3aRedis\uff1f Redis\u662f\u5185\u5b58\u4e2d\u7684\u952e\u503c\u7f13\u5b58\u548c\u5b58\u50a8\uff08\u5373\u6570\u636e\u5e93\uff09\uff0c\u4e5f\u53ef\u4ee5\u6c38\u4e45\u4fdd\u5b58\u5230\u78c1\u76d8\u3002\u5728\u672c\u6587\u4e2d\uff0c\u4f60\u5c06\u4e86\u89e3\uff0c\u5982 […]<\/p>\n","protected":false},"author":668,"featured_media":101118,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-103460","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/103460","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=103460"}],"version-history":[{"count":8,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/103460\/revisions"}],"predecessor-version":[{"id":292821,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/103460\/revisions\/292821"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/101118"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=103460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=103460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=103460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}