updated to xz compression
This commit is contained in:
@@ -2,7 +2,7 @@ from pathlib import Path
|
||||
import contextlib
|
||||
import os
|
||||
from datetime import timedelta, datetime
|
||||
from zipfile import ZipFile
|
||||
import subprocess
|
||||
|
||||
class local_dir_remote:
|
||||
def __init__(self, config):
|
||||
@@ -34,13 +34,12 @@ class local_dir_remote:
|
||||
|
||||
def zip_local_directory(self, job):
|
||||
source_files = self.list_dir(True)
|
||||
zipname = f'{job["zipname"]}-{str(datetime.now()).split(" ")[0]}.zip'
|
||||
with ZipFile(zipname, 'w') as myzip:
|
||||
for files in source_files:
|
||||
try:
|
||||
myzip.write(files)
|
||||
except Exception:
|
||||
continue
|
||||
zipname = f'{job["zipname"]}-{str(datetime.now()).split(" ")[0]}.tar.xz'
|
||||
#-T3 = 3 threads, the backups are meant to run in the night at 5 am to not interfere with players.
|
||||
exec_command_state = f"XZ_OPT='-T3 --memlimit-compress=70%' tar -cJf {zipname} {self.path}"
|
||||
print("exec_command_state: ", exec_command_state)
|
||||
subprocess.run([exec_command_state], shell=True)
|
||||
|
||||
return str(Path.cwd()) + '/' + zipname
|
||||
|
||||
def delete_local_demo(self, pathfile):
|
||||
@@ -51,6 +50,6 @@ class local_dir_remote:
|
||||
|
||||
def delete_local_zip(self, zip_file_path):
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
if (str(zip_file_path).endswith('.zip')):
|
||||
if (str(zip_file_path).endswith('.tar.xz')):
|
||||
os.remove(zip_file_path)
|
||||
print('removed zip: ', zip_file_path)
|
||||
print('removed tar xz: ', zip_file_path)
|
||||
|
||||
Reference in New Issue
Block a user