{"id":1371,"date":"2023-03-19T10:32:00","date_gmt":"2023-03-19T02:32:00","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1371"},"modified":"2023-03-19T10:34:31","modified_gmt":"2023-03-19T02:34:31","slug":"redis-data-import-export-and-database-migration-between-instances","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/19\/redis-data-import-export-and-database-migration-between-instances\/","title":{"rendered":"Redis\u6570\u636e\u5bfc\u5165\u5bfc\u51fa\uff0c\u5b9e\u4f8b\u95f4db\u8fc1\u79fb"},"content":{"rendered":"<h3>\u6e90\u5b9e\u4f8bdb0\u8fc1\u79fb\u81f3\u76ee\u6807\u5b9e\u4f8bdb1<\/h3>\n<pre><code class=\"language-bash\">[root@172.20.0.1 ~]# cat redis_mv.sh\n#!\/bin\/bash\nredis-cli -h 172.20.0.1 -p 6379 -a password -n 0 keys &quot;*&quot; | while read key\ndo\n    redis-cli -h 172.20.0.1 -p 6379 -a password -n 0 --raw dump $key | perl -pe &#039;chomp if eof&#039; | redis-cli -h 172.20.0.2 -p 6379 -a password -n 1 -x restore $key 0\n    echo &quot;migrate key $key&quot;\ndone<\/code><\/pre>\n<p><!-- more --><\/p>\n<h3>aof\u5bfc\u5165\u65b9\u5f0f<\/h3>\n<ol>\n<li>\u6e90\u5b9e\u4f8b\u751f\u6210aof\u6570\u636e<\/li>\n<\/ol>\n<pre><code class=\"language-bash\"># \u6e05\u7a7a\u4e0a\u6587\u76ee\u6807\u5b9e\u4f8b\u5168\u90e8\u6570\u636e\n[root@172.20.0.1 ~]# redis-cli -h 172.20.0.2 -a password flushall\nOK\n# \u6e90\u5b9e\u4f8b\u5f00\u542faof\u529f\u80fd\uff0c\u5c06\u5728dir\u76ee\u5f55\u4e0b\u751f\u6210appendonly.aof\u6587\u4ef6\n[root@172.20.0.1 ~]# redis-cli -h 172.20.0.1 -a password config set appendonly yes\nOK<\/code><\/pre>\n<ol start=\"2\">\n<li>\u76ee\u6807\u5b9e\u4f8b\u5bfc\u5165aof\u6570\u636e<\/li>\n<\/ol>\n<pre><code class=\"language-bash\"># \u5047\u8bbeappendonly.aof\u5c31\u5728\u5f53\u524d\u8def\u5f84\u4e0b\n[root@172.20.0.1 ~]# redis-cli -h 172.20.0.2 -a password --pipe &lt; appendonly.aof\nAll data transferred. Waiting for the last reply...\nLast reply received from server.\nerrors: 0, replies: 5\n# \u6e90\u5b9e\u4f8b\u5173\u95edaof\u529f\u80fd\n[root@172.20.0.1 ~]# redis-cli -h 172.20.0.1 -a password config set appendonly no\nOK<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6e90\u5b9e\u4f8bdb0\u8fc1\u79fb\u81f3\u76ee\u6807\u5b9e\u4f8bdb1 [root@172.20.0.1 ~]# cat redis_mv.sh # [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[153],"class_list":["post-1371","post","type-post","status-publish","format-standard","hentry","category-redis","tag-redis"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1371"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1371\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}