Skip to content

Instantly share code, notes, and snippets.

@wangshuai1992
Created November 23, 2022 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wangshuai1992/9923c0b88f0be48978530bb14a86dd8a to your computer and use it in GitHub Desktop.
Save wangshuai1992/9923c0b88f0be48978530bb14a86dd8a to your computer and use it in GitHub Desktop.
move redis data using dump
#!/bin/bash
#redis 源ip
src_ip=xxx.cache.amazonaws.com.cn
#redis 源port
src_port=6379
src_db=0
#redis 目的ip
dest_ip=xxx.cache.amazonaws.com.cn
#redis 目的port
dest_port=6379
dest_db=5
#要迁移的key前缀
key_prefix=xxx
i=1
redis-cli -h $src_ip -p $src_port -n $src_db keys "${key_prefix}*" | while read key
do
redis-cli -h $dest_ip -p $dest_port -n $dest_db del $key
redis-cli -h $src_ip -p $src_port --raw dump $key | perl -pe 'chomp if eof' | redis-cli -h $dest_ip -p $dest_port -n $dest_db -x restore $key 0
echo "$i migrate key $key"
i=$(($i + 1))
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment