![]() |
RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 #!/usr/bin/python 00002 # Wolfgang Sourdeau - march 2003 00003 # Copyright (c) 2013 Datacratic. All rights reserved. 00004 00005 # backup script for the Banker database 00006 00007 # FIXME: this script does not perform the backup atomically, which can lead to 00008 # small inconsistencies between the states of the accounts 00009 00010 import redis 00011 import json 00012 import datetime 00013 import sys 00014 00015 00016 00017 r = redis.Redis(host='localhost') 00018 00019 d = {} 00020 for key in r.keys(): 00021 val_type = r.type(key) 00022 if val_type == "hash": 00023 d[key] = r.hgetall(key) 00024 elif val_type == "string": 00025 d[key] = r.get(key) 00026 else: 00027 raise Exception("unhandled value type: %s" % val_type) 00028 00029 00030 filename = "banker_backup_%s.json" % datetime.datetime.now().strftime("%Y-%m-%d_%H-%M") 00031 writer = open(filename, "w") 00032 writer.write(json.dumps(d)) 00033 writer.close()