{"id":1374,"date":"2023-03-19T10:38:47","date_gmt":"2023-03-19T02:38:47","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1374"},"modified":"2023-04-28T21:15:23","modified_gmt":"2023-04-28T13:15:23","slug":"redis-cross-instance-migration-redis-cloud","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/19\/redis-cross-instance-migration-redis-cloud\/","title":{"rendered":"Redis\u8de8\u5b9e\u4f8b\u8fc1\u79fb &#038; Redis\u4e0a\u4e91"},"content":{"rendered":"<h2>Redis\u8de8\u5b9e\u4f8b\u8fc1\u79fb<\/h2>\n<p>Redis\u8de8\u5b9e\u4f8b\u8fc1\u79fb\u2014\u2014\u6e90\u5b9e\u4f8bdb11\u8fc1\u79fb\u81f3\u76ee\u6807\u5b9e\u4f8bdb30<\/p>\n<pre><code class=\"language-bash\">root@fe2e836e8870:\/data# redis-cli -a pwd1 -n 11 keys \\* |while read key\n> do\n> echo &quot;Copying $key&quot;\n> redis-cli -a pwd1 -n 11 --raw dump $key |head -c -1 \\\n> |redis-cli -h &lt;dst_ip&gt; -p 6379 -a pwd2 -n 30 -x restore $key 0\n> done\n\n## \u5199\u6210\u4e00\u884c\uff0c\u5982\u4e0b\uff1a\nroot@fe2e836e8870:\/data# redis-cli -a pwd1 -n 11 keys \\* |while read key; do echo &quot;Copying $key&quot;; redis-cli -a pwd1 -n 11 --raw dump $key |head -c -1 |redis-cli -h &lt;dst_ip&gt; -p 6379 -a pwd2 -n 30 -x restore $key 0; done<\/code><\/pre>\n<p><!-- more --><\/p>\n<h2>Redis\u4e0a\u4e91<\/h2>\n<p>Redis\u4e0a\u4e91\u2014\u2014\u8fc1\u79fb\u81f3\u963f\u91cc\u4e91\uff0c\u5305\u62ecRedis-shake\u65b9\u6848\u548c\u6570\u636e\u4f20\u8f93\u670d\u52a1\uff08DTS\uff09\u65b9\u6848\uff0c\u672c\u6587\u4ee5Redis-shake\u65b9\u6848\u6f14\u793a<\/p>\n<ul>\n<li>\u901a\u8fc7Redis-shake\u5c06\u81ea\u5efaRedis\u8fc1\u79fb\u81f3\u963f\u91cc\u4e91\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/help.aliyun.com\/document_detail\/111066.html\">https:\/\/help.aliyun.com\/document_detail\/111066.html<\/a><\/li>\n<li>\u4ece\u81ea\u5efaRedis\u8fc1\u79fb\u81f3\u963f\u91cc\u4e91Redis\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/help.aliyun.com\/document_detail\/47896.html\">https:\/\/help.aliyun.com\/document_detail\/47896.html<\/a><\/li>\n<\/ul>\n<p>\uff081\uff09\u70b9\u51fb\u53c2\u8003\u6587\u6863\u4e2d\u7684 redis-shake \uff0c\u4e0b\u8f7d<code>redis-shake.tar.gz<\/code>\u81f3\u672c\u5730<br \/>\n<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/github.com\/alibaba\/RedisShake\/releases\">https:\/\/github.com\/alibaba\/RedisShake\/releases<\/a><\/p>\n<p>\uff082\uff09\u5c06\u4e0b\u8f7d\u597d\u7684<code>redis-shake.tar.gz<\/code>\u4e0a\u4f20\u81f3 redis\u6240\u5728\u7684ECS\uff0c\u5e76\u62f7\u8d1d\u81f3redis\u5bb9\u5668\u4e2d<\/p>\n<pre><code class=\"language-bash\">docker cp \/tmp\/redis-shake.tar.gz docker_redis_1:\/data\/<\/code><\/pre>\n<p>\uff083\uff09\u89e3\u538b<code>redis-shake.tar.gz<\/code><\/p>\n<pre><code class=\"language-bash\">appblog-cn docker # docker-compose exec redis bash\nroot@fe2e836e8870:\/data# tar -xvf redis-shake.tar.gz\nroot@fe2e836e8870:\/data# ls -ahl\ndrwxr-xr-x 3 redis root  4.0K Jun 21 07:37 .\ndrwxr-xr-x 1 root  root  4.0K Jun 10 07:45 ..\n-rw-r--r-- 1 redis users 2.4K Jun 13 15:48 ChangeLog\n-rw-r--r-- 1 redis root  8.6K Jun 21 06:44 redis-shake.conf\n-rwxr-xr-x 1 redis users  11M Jun 13 15:48 redis-shake.linux64\n-rw-r--r-- 1 redis root  3.7M Jun 21 06:01 redis-shake.tar.gz<\/code><\/pre>\n<p>\uff084\uff09\u4fee\u6539<code>redis-shake<\/code>\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre><code class=\"language-bash\">appblog-cn docker # docker-compose exec redis bash\nroot@fe2e836e8870:\/data# vim redis-shake.conf\n\n...\nsource.address = localhost:6379\nsource.password_raw = localRedisPwd\ntarget.address = r-uf65427cede42c14.redis.rds.aliyuncs.com:6379\ntarget.password_raw = yourALIredisPwd\n...\n# \u5176\u4f59\u53c2\u6570\u4fdd\u6301\u9ed8\u8ba4<\/code><\/pre>\n<p>\uff085\uff09\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u8fdb\u884c\u8fc1\u79fb<\/p>\n<pre><code class=\"language-bash\">appblog-cn docker # docker-compose exec redis bash\nroot@fe2e836e8870:\/data# .\/redis-shake.linux64 -type=sync -conf=redis-shake.conf<\/code><\/pre>\n<p>\uff086\uff09\u67e5\u770b\u540c\u6b65\u65e5\u5fd7\u786e\u8ba4\u540c\u6b65\u72b6\u6001\uff0c\u5f53\u51fa\u73b0<code>sync rdb done<\/code>\u65f6\uff0c\u5168\u91cf\u540c\u6b65\u5df2\u7ecf\u5b8c\u6210\uff0c\u540c\u6b65\u8fdb\u5165\u589e\u91cf\u9636\u6bb5\u3002<\/p>\n<pre><code class=\"language-bash\">root@fe2e836e8870:\/data# .\/redis-shake.linux64 -type=sync -conf=redis-shake.conf\n2019\/06\/27 06:53:56 [WARN]\n______________________________\n\\                             \\           _         ______ |\n \\                             \\        \/   \\___-=O&#039;\/|O&#039;\/__|\n  \\  redis-shake, here we go !! \\_______\\          \/ | \/    )\n  \/                             \/        &#039;\/-==__ _\/__|\/__=-|  -GM\n \/                             \/         *             \\ | |\n\/                             \/                        (o)\n------------------------------\nif you have any problem, please visit https:\/\/github.com\/alibaba\/RedisShake\/wiki\/FAQ\n\n2019\/06\/27 06:53:56 [INFO] redis-shake configuration: {&quot;Id&quot;:&quot;redis-shake&quot;,&quot;LogFile&quot;:&quot;&quot;,&quot;LogLevel&quot;:&quot;info&quot;,&quot;SystemProfile&quot;:9310,&quot;HttpProfile&quot;:9320,&quot;NCpu&quot;:0,&quot;Parallel&quot;:32,&quot;SourceType&quot;:&quot;standalone&quot;,&quot;SourceAddress&quot;:&quot;localhost:6379&quot;,&quot;SourcePasswordRaw&quot;:&quot;bckBuqb5hDhCQfSr9eTVEYufn7gBxJ5k&quot;,&quot;SourcePasswordEncoding&quot;:&quot;&quot;,&quot;SourceVersion&quot;:0,&quot;SourceAuthType&quot;:&quot;auth&quot;,&quot;SourceParallel&quot;:1,&quot;SourceTLSEnable&quot;:false,&quot;TargetAddress&quot;:&quot;r-uf65427cede42c14.redis.rds.aliyuncs.com:6379&quot;,&quot;TargetPasswordRaw&quot;:&quot;Karl@612500&quot;,&quot;TargetPasswordEncoding&quot;:&quot;&quot;,&quot;TargetVersion&quot;:0,&quot;TargetDBString&quot;:&quot;-1&quot;,&quot;TargetAuthType&quot;:&quot;auth&quot;,&quot;TargetType&quot;:&quot;standalone&quot;,&quot;TargetTLSEnable&quot;:false,&quot;RdbInput&quot;:[&quot;local&quot;],&quot;RdbOutput&quot;:&quot;local_dump&quot;,&quot;RdbParallel&quot;:1,&quot;RdbSpecialCloud&quot;:&quot;&quot;,&quot;FakeTime&quot;:&quot;&quot;,&quot;Rewrite&quot;:true,&quot;FilterDB&quot;:&quot;&quot;,&quot;FilterKey&quot;:[],&quot;FilterSlot&quot;:[],&quot;BigKeyThreshold&quot;:524288000,&quot;Psync&quot;:false,&quot;Metric&quot;:true,&quot;MetricPrintLog&quot;:false,&quot;HeartbeatUrl&quot;:&quot;&quot;,&quot;HeartbeatInterval&quot;:3,&quot;HeartbeatExternal&quot;:&quot;test external&quot;,&quot;HeartbeatNetworkInterface&quot;:&quot;&quot;,&quot;SenderSize&quot;:104857600,&quot;SenderCount&quot;:5000,&quot;SenderDelayChannelSize&quot;:65535,&quot;KeepAlive&quot;:0,&quot;PidPath&quot;:&quot;&quot;,&quot;ScanKeyNumber&quot;:50,&quot;ScanSpecialCloud&quot;:&quot;&quot;,&quot;ScanKeyFile&quot;:&quot;&quot;,&quot;Qps&quot;:200000,&quot;ReplaceHashTag&quot;:false,&quot;ExtraInfo&quot;:false,&quot;SockFileName&quot;:&quot;&quot;,&quot;SockFileSize&quot;:0,&quot;SourceAddressList&quot;:[&quot;localhost:6379&quot;],&quot;TargetAddressList&quot;:[&quot;r-uf65427cede42c14.redis.rds.aliyuncs.com:6379&quot;],&quot;HeartbeatIp&quot;:&quot;127.0.0.1&quot;,&quot;ShiftTime&quot;:0,&quot;TargetRedisVersion&quot;:&quot;4.0.11&quot;,&quot;TargetReplace&quot;:true,&quot;TargetDB&quot;:-1,&quot;Version&quot;:&quot;improve-1.6.7,678f43481a4826764ed71fedd744a7ee23736536,go1.10.3,2019-06-13_23:48:39&quot;}\n2019\/06\/27 06:53:56 [INFO] routine[0] starts syncing data from localhost:6379 to [r-uf65427cede42c14.redis.rds.aliyuncs.com:6379] with http[9321]\n2019\/06\/27 06:53:57 [INFO] dbSyncer[0] rdb file size = 3429472\n2019\/06\/27 06:53:57 [INFO] Aux information key:redis-ver value:5.0.5\n2019\/06\/27 06:53:57 [INFO] Aux information key:redis-bits value:64\n2019\/06\/27 06:53:57 [INFO] Aux information key:ctime value:1561618436\n2019\/06\/27 06:53:57 [INFO] Aux information key:used-mem value:27379792\n2019\/06\/27 06:53:57 [INFO] Aux information key:repl-stream-db value:0\n2019\/06\/27 06:53:57 [INFO] Aux information key:repl-id value:6641200d52e448927a79ce3e0a3cec641302da7f\n2019\/06\/27 06:53:57 [INFO] Aux information key:repl-offset value:0\n2019\/06\/27 06:53:57 [INFO] Aux information key:aof-preamble value:0\n2019\/06\/27 06:53:57 [INFO] db_size:1 expire_size:1\n2019\/06\/27 06:53:57 [INFO] db_size:3 expire_size:1\n2019\/06\/27 06:53:57 [INFO] db_size:9 expire_size:9\n2019\/06\/27 06:53:57 [INFO] db_size:7 expire_size:4\n2019\/06\/27 06:53:57 [INFO] db_size:6 expire_size:0\n2019\/06\/27 06:53:57 [INFO] db_size:6 expire_size:0\n2019\/06\/27 06:53:57 [INFO] Aux information key:lua value:-- Pop the first job off of the queue...\nlocal job = redis.call(&#039;lpop&#039;, KEYS[1])\nlocal reserved = false\n\nif(job ~= false) then\n    -- Increment the attempt count and place job on the reserved queue...\n    reserved = cjson.decode(job)\n    reserved[&#039;attempts&#039;] = reserved[&#039;attempts&#039;] + 1\n    reserved = cjson.encode(reserved)\n    redis.call(&#039;zadd&#039;, KEYS[2], ARGV[1], reserved)\nend\n\nreturn {job, reserved}\n2019\/06\/27 06:53:57 [INFO] Aux information key:lua value:-- Get all of the jobs with an expired &quot;score&quot;...\nlocal val = redis.call(&#039;zrangebyscore&#039;, KEYS[1], &#039;-inf&#039;, ARGV[1])\n\n-- If we have values in the array, we will remove them from the first queue\n-- and add them onto the destination queue in chunks of 100, which moves\n-- all of the appropriate jobs onto the destination queue very safely.\nif(next(val) ~= nil) then\n    redis.call(&#039;zremrangebyrank&#039;, KEYS[1], 0, #val - 1)\n\n    for i = 1, #val, 100 do\n        redis.call(&#039;rpush&#039;, KEYS[2], unpack(val, i, math.min(i+99, #val)))\n    end\nend\n\nreturn val\n2019\/06\/27 06:53:57 [INFO] Aux information key:lua value:return redis.call(&#039;exists&#039;,KEYS[1])&lt;1 and redis.call(&#039;setex&#039;,KEYS[1],ARGV[2],ARGV[1])\n2019\/06\/27 06:53:57 [INFO] dbSyncer[0] total=3429472 -      3429472 [100%]  entry=35\n2019\/06\/27 06:53:57 [INFO] dbSyncer[0] sync rdb done\n2019\/06\/27 06:53:57 [WARN] dbSyncer[0] GetFakeSlaveOffset not enable when psync == false\n2019\/06\/27 06:53:57 [INFO] dbSyncer[0] Event:IncrSyncStart      Id:redis-shake\n2019\/06\/27 06:53:58 [INFO] dbSyncer[0] sync:  +forwardCommands=0      +filterCommands=0      +writeBytes=0\n2019\/06\/27 06:53:59 [INFO] dbSyncer[0] sync:  +forwardCommands=7      +filterCommands=0      +writeBytes=34\n2019\/06\/27 06:54:00 [INFO] dbSyncer[0] sync:  +forwardCommands=6      +filterCommands=0      +writeBytes=27<\/code><\/pre>\n<p>\uff087\uff09\u767b\u5f55\u963f\u91cc\u4e91Redis\u67e5\u770b\u6570\u636e\u540c\u6b65\u60c5\u51b5<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Redis\u8de8\u5b9e\u4f8b\u8fc1\u79fb Redis\u8de8\u5b9e\u4f8b\u8fc1\u79fb\u2014\u2014\u6e90\u5b9e\u4f8bdb11\u8fc1\u79fb\u81f3\u76ee\u6807\u5b9e\u4f8bdb30 root@fe2e836e [&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":[],"class_list":["post-1374","post","type-post","status-publish","format-standard","hentry","category-redis"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1374","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=1374"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1374\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}