Cloning Redis Servers for a Roll-Out
This morning I was getting ready for a roll-out of some new code, and I didn't want to have to re-populate the production cache with a lot of data that I already had in my UAT cache - which has been running for more than a week, and populating data as it goes. The script isn't all that hard - is just runs through all the servers that need to be cloned, stops them, copies over the data file and then restarts the redis server.
#!/bin/bash for b in {1..8}; do echo "working on redis_${b}..." echo " stopping redis${b} server..." pid=`top -Unobody -c -b | grep redis_${b}.conf | awk '{ print $1 }'` sudo kill -9 $pid echo " copying data from caliban over..." scp opt-analytics-redis4-uat.snc1:/var/groupon/redis_${b}/dump.rdb . sudo cp dump.rdb /var/groupon/redis_${b}/ sudo chown nobody:nobody /var/groupon/redis_${b}/dump.rdb rm dump.rdb echo " restarting redis_${b} server..." sudo /usr/local/etc/init.d/redis_${b} start done
Yeah, it's nothing special, but I'm trying to be a little more diligent on the posts, and this was kinda fun to write, and it works perfectly.