fixed backup
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
|
||||
import os
|
||||
from zipfile import ZipFile
|
||||
|
||||
from models.database import Database
|
||||
|
||||
@@ -9,13 +10,22 @@ class Utils:
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
|
||||
@staticmethod
|
||||
def export_db(file):
|
||||
with open(f"./{file}", 'w') as f:
|
||||
def export_db():
|
||||
with open(f"./backup.sql", 'w') as f:
|
||||
for line in Database.connection.iterdump():
|
||||
f.write('%s\n' % line)
|
||||
|
||||
with ZipFile("backup.zip", "w") as zip:
|
||||
zip.write("backup.sql")
|
||||
|
||||
os.remove("./backup.sql")
|
||||
|
||||
@staticmethod
|
||||
def import_db(file):
|
||||
with open(f"./{file}", 'r') as f:
|
||||
str = f.read()
|
||||
Database.connection.executescript(str)
|
||||
def import_db():
|
||||
with ZipFile("backup.zip", 'r') as zip:
|
||||
zip.extractall("./")
|
||||
with open(f"./backup.sql", 'r') as f:
|
||||
str = f.read()
|
||||
Database.connection.executescript(str)
|
||||
|
||||
os.remove("./backup.sql")
|
Reference in New Issue
Block a user