I have a problem, which when I run the following command:
➜ Downloads redis-cli dump accout_37 > test_account.rdb
➜ Downloads cat test_account.rdb | redis-cli -x restore mytest_dump 0
(error) ERR DUMP payload version or checksum are wrong
It always happen to this problem: (error) ERR DUMP payload version or checksum are wrong, and I still remember that two weeks ago it was normal.
I am working in OS X 10.11.4, and I use homebrew install redis, and redis-cli version is 3.2.0。
I google it , but I only find this Error appeared in http://redis.io/commands/restore。
In fact, My origin intention is that dump key from my machine , then scp dump file to remote server, then restore this key in remote server.
Sorry for poor English。
Comment From: rojingeorge
Hey @xiajian Can you reconfirm if the redis version in your machine and remote server to be same or different? Once RDB format changes, its not backward compatible between versions. So keep the versions same and give a retry.
Comment From: xiajian
Hey @rojingeorge I execute the above command line in same machine。
At First, I guess maybe something wrong in my machine. Then ,I execute the following command line in remote server 1 (Centos 6.5, redis-cli 3.0.7), remote server 2 ( Ubuntu 14.04.4 LTS (GNU/Linux 3.13.0-79-generic x86_64, redis 2.8.4).
redis-cli set 'test' 123
redis-cli dump 'test' > test_123
cat test_123 | redis-cli -x restore mytest_dump 0
(error) ERR DUMP payload version or checksum are wrong
It still happened!! So,I guess it maybe something wrong in commandline or something wrong in redis.
And, I learn the above command line from http://stackoverflow.com/questions/16127682/how-to-use-redis-dump-and-restore-offline.
Comment From: badboy
If you pipe the output of DUMP into a file, it will include an additional newline. You have to remove that.
$ tr -d '\n' < test_123 | redis-cli -x restore mytest_dump 0
OK
Comment From: xiajian
@badboy
Oh, It work! Thank you for your advice.
Comment From: flisky
The dump content may contain newline, so it's safer to use head -c-1.
Full example: redis-cli --raw dump test | head -c-1 | redis-cli -x restore test1 0
Credited to StackOverflow
Comment From: angealtsai
what if i excute like a linux shell file,
!/bin/bash
src_ip=xx.xx.xx.xx src_port=6379 src_auth=123456 dest_ip=127.0.0.1 dest_port=6379 i=1 redis-cli -h $src_ip -p $src_port -a $src_auth keys "*" | while read key do redis-cli -h $src_ip -p $src_port -a $src_auth --raw dump $key | perl -pe 'chomp if eof' | redis-cli -h $dest_ip -p $dest_port -n 0 -x restore $key 0 echo "$i migrate key $key" ((i++)) done ================== how could i deal with the “\n”?
Comment From: yujiaao
if the value contains \n (carrige return) then, head and tr version script not work properly, you can use split/dd/truncate or other bin utils to deal with the last bad byte.
Comment From: SCLogo
if the value contains
\n(carrige return) then,headandtrversion script not work properly, you can usesplit/dd/truncateor other bin utils to deal with the last bad byte.
Can you give an example ?
Comment From: jimsnab
As shown in redis-cli --help there is a -D argument that controls the delimiter. So from the popular answer above, there's no need for head:
redis-cli --raw -D "" dump test | redis-cli -x restore test1 0