mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Improving backup efficiency with shutil
Removed the old backup code that created a zip on a file-by-file basis and replaced it with make_archive from shutil to just zip the whole directory
This commit is contained in:
parent
0689b735ff
commit
5c85a575ee
@ -553,13 +553,4 @@ class Helpers:
|
||||
|
||||
return json.loads(content)
|
||||
|
||||
@staticmethod
|
||||
def zip_directory(file, path, compression=zipfile.ZIP_LZMA):
|
||||
with zipfile.ZipFile(file, 'w', compression) as zf:
|
||||
for root, dirs, files in os.walk(path):
|
||||
for file in files:
|
||||
zf.write(os.path.join(root, file),
|
||||
os.path.relpath(os.path.join(root, file),
|
||||
os.path.join(path, '..')))
|
||||
|
||||
helper = Helpers()
|
||||
helper = Helpers()
|
@ -10,6 +10,8 @@ import threading
|
||||
import schedule
|
||||
import logging.config
|
||||
import zipfile
|
||||
import shutil
|
||||
import zlib
|
||||
|
||||
|
||||
from app.classes.shared.helpers import helper
|
||||
@ -324,7 +326,8 @@ class Server:
|
||||
try:
|
||||
backup_filename = "{}/{}.zip".format(conf['backup_path'], datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'))
|
||||
logger.info("Creating backup of server '{}' (ID#{}) at '{}'".format(self.settings['server_name'], self.server_id, backup_filename))
|
||||
helper.zip_directory(backup_filename, self.server_path)
|
||||
# helper.zip_directory(backup_filename, self.server_path)
|
||||
shutil.make_archive(backup_filename, zip, self.server_path)
|
||||
backup_list = self.list_backups()
|
||||
if len(self.list_backups()) > conf["max_backups"]:
|
||||
oldfile = backup_list[0]
|
||||
|
Loading…
Reference in New Issue
Block a user