-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmemcacheddump.py
38 lines (37 loc) · 971 Bytes
/
memcacheddump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
apt-get install python3-memcache
apt-get install libmemcached-tools
"""
#!/usr/bin/python
import sys
import memcache
import subprocess
import json
import re
out = "memdump"
host = "127.0.0.1"
port = "11211"
if "-f" in sys.argv:
out = sys.argv[sys.argv.index("-f")+1]
if "-h" in sys.argv:
host = sys.argv[sys.argv.index("-h")+1]
if "-p" in sys.argv:
port = sys.argv[sys.argv.index("-p")+1]
print ("conecting...")
hostport = host+":"+port
s = memcache.Client([hostport])
print ("checking keys...")
output = subprocess.check_output("memcdump --servers="+hostport+"|| true", shell=True, text=True)
data = re.split('\n+', output)
lista = {}
for key in data:
if key != '':
lista[key]=s.get(key)
print ("dumping "+key+"...")
jsonfinal = json.dumps(lista, ensure_ascii=False)
print ("writing output...")
fileWrite = open(out, "w")
fileWrite.write(jsonfinal)
fileWrite.close()
print ("memcache file created")
print ("finish dump")