-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrestoredatabase.py
58 lines (51 loc) · 2.01 KB
/
restoredatabase.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
from time import sleep
class restore(object):
def __init__(self):
self.file = ('.frm and .ibd folder path ex C:\\database\\') #directory location must be inside single quotes
self.fileoutput = self.file+"output\\"
self.listdir = os.listdir(self.file)
self.listdiroutput = os.listdir(self.fileoutput)
def cmd_restore(self):
pathfile = self.listdir
for i in pathfile:
if ".frm" in i:
# Change user and password mysql that running at your machine
os.system('mysqlfrm --server=root:password@localhost --port=3311 '+self.file+str(i)+' > '+self.fileoutput+str(i.replace(".frm",""))+'.sql')
print(i)
def delete_list(self, pathfile):
list_word = ["#...done."]
openfile = open(pathfile)
lines = openfile.readlines()
for i in range(0,10):
list_word.append(lines[i])
openfile.close()
return list_word
def delete_text(self, name_file, openfile, savefile):
delete_list = self.delete_list(openfile)
with open(openfile) as fin, open(savefile, "w+") as fout:
for line in fin:
for word in delete_list:
line = line.replace(word, "")
fout.write(line)
fin.close()
fout.close()
return print('delete')
def prosess(self):
for i in self.listdiroutput:
if '.sql' in i:
self.delete_text(i,self.fileoutput+str(i),self.fileoutput+str(i).replace('.sql','.txt'))
def marge(self):
filenames = []
for i in self.listdiroutput:
if '.txt' in i:
filenames.append(self.fileoutput+str(i))
with open(self.file+'final.sql', 'w') as outfile:
for names in filenames:
with open(names) as infile:
outfile.write(infile.read())
outfile.write("\n")
def run(self):
self.cmd_restore()
sleep(10)
self.prosess()