Created
September 25, 2017 17:03
-
-
Save lucaswerkmeister/3e2f0bd56cc45a334de01e18103a2dfe to your computer and use it in GitHub Desktop.
pure Bash script to dump all keys in a memcached server
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 | |
# connect to memcached | |
exec 3<>/dev/tcp/"${1:-localhost}"/"${2:-11211}" || exit $? | |
# get slab numbers | |
printf 'stats slabs\r\n' >&3 | |
slabnums=() | |
while IFS=' :' read -r stat slabnum _; do | |
if [[ $stat == $'END\r' ]]; then | |
break | |
fi | |
if ! [[ $slabnum =~ ^[0-9]*$ ]]; then | |
continue | |
fi | |
for index in "${!slabnums[@]}"; do | |
if [[ ${slabnums[index]} == "$slabnum" ]]; then | |
continue 2 | |
fi | |
done | |
slabnums+=($slabnum) | |
done <&3 | |
# dump each slab | |
for ((index=0;index<${#slabnums[@]};index++)); do | |
slabnum=${slabnums[index]} | |
printf 'stats cachedump %d 0\r\n' "$slabnum" >&3 | |
while read -r line; do | |
if [[ $line == $'END\r' ]]; then | |
break | |
fi | |
printf '%s\n' "${line%$'\r'}" | |
done <&3 | |
done | |
# close connection | |
printf 'quit\r\n' >&3 | |
exec 3<&- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment