Skip to content

Instantly share code, notes, and snippets.

@blainsmith
Created June 3, 2017 00:56
Show Gist options
  • Save blainsmith/2171dc3a9f002ac32a48d828573ad8af to your computer and use it in GitHub Desktop.
Save blainsmith/2171dc3a9f002ac32a48d828573ad8af to your computer and use it in GitHub Desktop.
Copy keys from one Redis instance to another
# Set variables accordingly
source_host=ecfoo.amazonaws.com
source_password=foo
source_port=6666
source_db=0
target_host=ecbar.amazonaws.com
target_password=bar
target_port=6777
target_db=0
redis-cli -h $source_host -a $source_password -p $source_port -n $source_db keys \* | while read key; do
echo "Copying $key";
redis-cli --raw -h $source_host -a $source_password -p $source_port -n $source_db DUMP "$key" | head -c -1|redis-cli -x -h $target_host -a $target_password -p $target_port -n $target_db RESTORE "$key" 0;
done
@itamarhaber
Copy link

Don't use KEYS, use SCAN instead (or the cli's --scan switch).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment