Skip to content

Instantly share code, notes, and snippets.

@guljarpd
Created August 21, 2019 14:56
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 guljarpd/3aeaacd9a02f0e106d0fa074c21f3b5e to your computer and use it in GitHub Desktop.
Save guljarpd/3aeaacd9a02f0e106d0fa074c21f3b5e to your computer and use it in GitHub Desktop.
migrate redis db to another redis db.
#!/bin/bash
#source DB (localhost or IP)
source_host=localhost
source_port=6379
source_db=0
#target DB (localhost or IP)
target_host=localhost2
target_port=6379
target_db=0
#copy command
redis-cli -h $source_host -p $source_port -n $source_db keys \* | while read key;
do
echo "copying $key"
redis-cli --raw -h $source_host -p $source_port -n $source_db DUMP "$key" | head -c -1 | redis-cli -x -h $target_host -p $target_port -n $target_db RESTORE "$key" 0
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment