Last active
August 28, 2022 09:27
-
-
Save FabulousCupcake/4ec90f6f5d7015f1a1a42fb3b3b6a4fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script migrates keys from a redis instance to another using only redis-cli | |
# This is necessary if you're migrating from a redis instance where MIGRATE command is removed | |
# such as heroku or aws elasticache | |
# Caveat & Notes: | |
# • Does not preserve expiry time or ttl | |
# • Slow, copies keys sequentially, took about 5 minutes for 500 keys | |
set -Eueo pipefail | |
SOURCE_HOST=ec2-12-34-567-890.eu-west-1.compute.amazonaws.com | |
SOURCE_PORT=12345 | |
SOURCE_DB=0 | |
SOURCE_AUTH=6a0f0731d84afa4082031e3a72354991 | |
TARGET_HOST=containers-us-west-123.railway.app | |
TARGET_PORT=12345 | |
TARGET_DB=0 | |
TARGET_AUTH=286755fad04869ca523320acce0dc6a4 | |
function redis-source() { | |
REDISCLI_AUTH="$SOURCE_AUTH" redis-cli -h $SOURCE_HOST -p $SOURCE_PORT -n $SOURCE_DB $@ | |
} | |
function redis-target() { | |
REDISCLI_AUTH="$TARGET_AUTH" redis-cli -h $TARGET_HOST -p $TARGET_PORT -n $TARGET_DB $@ | |
} | |
# Check Connection | |
printf "Source Redis PING... " | |
redis-source PING | |
printf "Target Redis PING... " | |
redis-target PING | |
REDISCLI_AUTH="$SOURCE_AUTH" redis-cli -h $SOURCE_HOST -p $SOURCE_PORT -n $SOURCE_DB keys \* | while read key; do | |
printf "$key... " | |
redis-source --raw DUMP $key | head -c-1 | redis-target -x RESTORE $key 0 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment