Skip to content

Instantly share code, notes, and snippets.

@andrewbrg
Created February 18, 2020 05:10
Show Gist options
  • Save andrewbrg/33d6c509bc0c73f5043d30d8e6e32b28 to your computer and use it in GitHub Desktop.
Save andrewbrg/33d6c509bc0c73f5043d30d8e6e32b28 to your computer and use it in GitHub Desktop.
Migrate Redis DB to another place (use MIGRATE COPY for v3.0<= redis)
#!/bin/bash
# Set connection data accordingly
source_host=localhost
source_port=6379
source_db=1
target_host=localhost
target_port=6379
target_db=2
# Copy all keys without preserving ttl!
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