What's the simplest way to get a dump of all memcached keys into a file?

前端 未结 5 1921
挽巷
挽巷 2020-12-30 04:15

This is from just a single memcached server with around 20M keys (no expiry) and around 2G of data.

What\'s the easiest way to get a dump of all the key/value pairs

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-30 04:45

    memccat

    Here is the script which I'm using to dump all the objects into corresponding files:

    while read -r key; do
        [ -f "$key" ] || echo "get $key" | nc localhost 11211 > "$key.dump";
    done < <(memcdump --server localhost)
    

    It uses memcdump command which should be part of memcached utils.

    For compressed objects, see: How to dump a compressed object for given key from Memcache?

    memcdump

    To dump a list of keys from a server, use memcdump/memdump tool, e.g.

    memcdump --servers=localhost | tee my_keys.lst
    

    To print the value of one item, use netcat:

    echo "get 13456_-cache-some_object" | nc localhost 11211
    

    To dump all objects into the screen via memcdump/memdump and netcat:

    memcdump --servers=localhost | xargs -L1 -I% sh -c 'echo "get %" | nc localhost 11211'
    

    memcached-tool

    In the recent version of memcached there is also memcached-tool command, e.g.

    memcached-tool localhost:11211 dump | less # dumps keys and values
    

提交回复
热议问题