Skip to content

Commit cc94893

Browse files
committed
Update
1.SQL导出工具完成 2.One-Click工具测试完毕
1 parent 0094a8c commit cc94893

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

Cli-Tools/one_click_tool.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import os
55
import sys
6+
import time
67
import shutil
78
import random
89
import requests
@@ -16,7 +17,7 @@ def get_config(config_path):
1617
else:
1718
print("Config文件不存在!请检查文件路径或使用其他模式")
1819
exit()
19-
return config["mode"],config["file_path"],config["deal_duration"],config["if_gc"],config["minerid"],config["deal_times"],config["max_budget"],config["config_path"],config["encrypt_mode"],config["encrypt_key"]
20+
return config["mode"],config["file_path"],config["deal_duration"],config["if_gc"],config["minerid"],config["deal_times"],config["max_budget"],config["config_path"],config["encrypt_mode"],config["encrypt_key"],config["cid_saving_path"]
2021

2122
def get_opt():
2223
#在这里设定参数默认值
@@ -30,6 +31,7 @@ def get_opt():
3031
config_path = None
3132
encrypt_mode = None
3233
encrypt_key = "VshareCloud"
34+
cid_saving_path = None
3335
#===============#
3436
args = sys.argv
3537
del args[0]
@@ -57,12 +59,14 @@ def get_opt():
5759
encrypt_mode = str(opt_content)
5860
elif opt_name in ("--encryptkey","-k"):
5961
encrypt_key = str(opt_content)
62+
elif opt_name in ("--cid_saving_path","-o"):
63+
cid_saving_path = str(opt_content)
6064
else :
6165
pass
6266
if config_path != None:
6367
return get_config(config_path)
6468
else:
65-
return mode,file_path,deal_duration,if_gc,minerid,deal_times,max_budget,config_path,encrypt_mode,encrypt_key
69+
return mode,file_path,deal_duration,if_gc,minerid,deal_times,max_budget,config_path,encrypt_mode,encrypt_key,cid_saving_path
6670

6771

6872
def get_cid(file_path,encrypt_mode,encrypt_key):
@@ -130,6 +134,15 @@ def get_vshare_nodeid():
130134
print("已选取到节点:%s" % minerid)
131135
return minerid
132136

137+
def backup_cid(cid,cid_saving_path):
138+
if cid_saving_path != None:
139+
f = open("%s/vshare_cids.md" % cid_saving_path,'a')
140+
f.write(str(cid)+ "|" + str(int(time.time())))
141+
f.write('\n')
142+
else:
143+
pass
144+
pass
145+
133146
def ipfs_gc(cid):
134147
print("开始垃圾清理")
135148
subprocess.run("ipfs pin rm %s" % cid, shell=True)
@@ -148,11 +161,13 @@ def ipfs_gc(cid):
148161
config_path = opt[7]
149162
# encrypt_mode = opt[8]
150163
# encrypt_key = opt[9]
164+
cid_saving_path = opt[10]
151165
if mode == "1":
152166
minerid = get_vshare_nodeid()
153167
cmd = "expect /opt/vsharecloud-tools/scripts/single_deal.sh %s %s %s" % (cid, deal_duration, minerid)
154168
subprocess.run(cmd, shell=True)
155169
print("交易已发起,请通过命令 lotus client list-deals 查询交易状态")
170+
backup_cid(cid,cid_saving_path)
156171
if if_gc == "y":
157172
ipfs_gc(cid)
158173
else:
@@ -162,6 +177,7 @@ def ipfs_gc(cid):
162177
cmd = "expect /opt/vsharecloud-tools/scripts/single_deal.sh %s %s %s" % (cid, deal_duration, minerid)
163178
subprocess.run(cmd, shell=True)
164179
print("交易已发起,请通过命令 lotus client list-deals 查询交易状态")
180+
backup_cid(cid,cid_saving_path)
165181
if if_gc == "y":
166182
ipfs_gc(cid)
167183
else:
@@ -171,6 +187,7 @@ def ipfs_gc(cid):
171187
cmd = "expect /opt/vsharecloud-tools/scripts/global_deal.sh %s %s %s %s" % (cid, deal_duration, max_budget, deal_times)
172188
subprocess.run(cmd, shell=True)
173189
print("交易已发起,请通过命令 lotus client list-deals 查询交易状态")
190+
backup_cid(cid,cid_saving_path)
174191
if if_gc == "y":
175192
ipfs_gc(cid)
176193
else:
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"host": "127.0.0.1",
3+
"port": 3306,
4+
"db": "dbname",
5+
"username": "root",
6+
"password": "password"
7+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: utf-8 -*-
2+
import os,time,MySQLdb,json,sys,subprocess
3+
4+
def get_opt():
5+
#在这里设定参数默认值
6+
config_path = None
7+
packup_path = None
8+
#===============#
9+
args = sys.argv
10+
del args[0]
11+
for arg in args:
12+
arg = arg.split("=")
13+
opt_name = arg[0]
14+
opt_content = arg[1]
15+
if opt_name in ("--config"):
16+
config_path = str(opt_content)
17+
elif opt_name in ("--packup-path"):
18+
packup_path = str(opt_content)
19+
else :
20+
pass
21+
return config_path,packup_path
22+
23+
def get_db_config(config_path):
24+
if os.path.isfile(config_path):
25+
f = open(config_path)
26+
sqlpwd = json.load(f)
27+
f.close()
28+
else:
29+
print("SQL Config 文件不存在!")
30+
exit()
31+
return sqlpwd
32+
33+
def getDatabaseNames(sql_config):
34+
db = MySQLdb.connect(host=sql_config['host'], port=sql_config['port'], user=sql_config['username'], passwd=sql_config['password'], db=sql_config['db'], charset='utf8')
35+
cursor = db.cursor()
36+
cursor.execute('show databases;')
37+
dbs = cursor.fetchall()
38+
db.close()
39+
return dbs
40+
41+
def mkdir(path):
42+
path = path.strip()
43+
path = path.rstrip("\\")
44+
isExists = os.path.exists(path)
45+
if not isExists:
46+
os.makedirs(path)
47+
return True
48+
else:
49+
return False
50+
51+
#Main
52+
config_path = get_opt()[0]
53+
packup_path = get_opt()[1]
54+
sql_config = get_db_config(config_path)
55+
timestr = time.strftime("%Y%m%d-%H%M%S",time.localtime(time.time()))
56+
if os.path.exists(packup_path) == False:
57+
os.makedirs(packup_path)
58+
else:
59+
pass
60+
dbs = getDatabaseNames(sql_config)
61+
print(dbs)
62+
for db in dbs:
63+
try:
64+
dbname = db[0]
65+
if dbname=="mysql" or dbname=="performance_schema" or dbname=="information_schema" or dbname=="sys":
66+
pass
67+
else:
68+
cmd = "mysqldump -u%s -p%s %s > %s/%s.sql" % (sql_config['username'], sql_config['password'], dbname, packup_path, (sql_config['db']+"_"+timestr))
69+
print(cmd)
70+
subprocess.run(cmd,shell=True)
71+
except Exception as error:
72+
print(error)

0 commit comments

Comments
 (0)