Last active
August 29, 2015 14:10
-
-
Save rtitle/fedc5f403ac5718767b2 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
#!/bin/bash | |
# Dumps memcached data from one server and restores on another. | |
# Useful for copying production data to staging. | |
# | |
# Generates a ./user_ids file with the users that were copied and an ./error file for errors. | |
# The user_ids file can be plugged into the JMeter RTS load generator. | |
# | |
# Takes a maximum number of entries to copy. If unspecified it copies everything. | |
# | |
# Usage: | |
# ./memcached_dump source dest [max] | |
# ./memcached_dump.sh "rts-cache01.sliad.dataxu.net:1760" "test-rts-cache01.us01.dataxu.net:1760" 1000 | |
SOURCE=$1 | |
DEST=$2 | |
MAX=$3 | |
if [[ -z $SOURCE || -z $DEST ]]; then | |
echo 'Usage: ./memcached_dump [source] [dest]' | |
echo 'Example: ./memcached_dump.sh "rts-cache01.sliad.dataxu.net:1760" "test-rts-cache01.us01.dataxu.net:1760" 1000' | |
exit 1 | |
fi | |
echo "Dumping ${SOURCE} to ${DEST}" | |
if [[ -n $MAX ]]; then | |
echo "Copying at most ${MAX} entries" | |
else | |
echo "Copying all entries!" | |
fi | |
DATA_DIR=/tmp/memcached_dump | |
rm -rf ${DATA_DIR} | |
mkdir -p ${DATA_DIR} | |
echo "Dumping..." | |
export MEMCACHED_SERVERS=${SOURCE} | |
if [[ -n $MAX ]]; then | |
dump_cmd="memcdump | head -${MAX}" | |
else | |
dump_cmd="memcdump" | |
fi | |
eval "${dump_cmd}" | xargs -n1 -i bash -c "memccat {} --file ${DATA_DIR}/{} && echo {}" >./user_ids 2>error | |
echo "`du -sh ${DATA_DIR}`" | |
echo "Restoring..." | |
export MEMCACHED_SERVERS=${DEST} | |
find ${DATA_DIR} -type f -exec memccp {} \; | |
echo "Done!" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment