From 5d61634255005ef187518cd0af4a22ef79792f76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Thu, 13 Feb 2020 10:12:53 +0100 Subject: [PATCH] add zipping files on new workdir --- workdirfs.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/workdirfs.py b/workdirfs.py index b69a144..a63a42c 100755 --- a/workdirfs.py +++ b/workdirfs.py @@ -12,6 +12,7 @@ import time import fileinput import argparse +import zipfile try: from fuse import FUSE, FuseOSError, Operations @@ -27,6 +28,7 @@ class WorkdirFS(Operations): def __init__(self, args): self.args = args self.today = datetime.now() - timedelta(hours=self.args.timeoffset) + self.yesterday = datetime.now() - timedelta(hours=self.args.timeoffset) # Helpers # ======= @@ -44,7 +46,15 @@ class WorkdirFS(Operations): if partial.startswith("/"): partial = partial[1:] - path = os.path.join(check_dir(os.path.join(path, self.today.strftime("%Y-%m-%d"))), partial) + path = os.path.join(check_dir( + os.path.join(path, self.today.strftime("%Y-%m-%d")), + os.path.join(path, self.yesterday.strftime("%Y-%m-%d")) + ), + partial + ) + + if self.today > self.yesterday: + self.yesterday = self.today return path @@ -180,16 +190,37 @@ def cleanup_dirs(root): os.path.join(root, _dir)) -def check_dir(path): +def check_dir(path, yesterpath=None): checkdir = os.path.isdir(path) if not checkdir: try: os.makedirs(path, exist_ok=True) print("Created directory {}".format(path), flush=True) + if yesterpath != None and path != yesterpath: + _zipfiles(yesterpath) + except: print("[-] Makedir error") return path +def _zipfiles(path) + print("Zip files in yesterdays archivdir {}".format(path)) + files = [] + # r=root, d=directories, f = files + for r, d, f in os.walk(path): + for file in f: + if '.gz' not in file: + files.append(os.path.join(r, file)) + + for f in files: + print("file to zip: {}".format(f)) + with Zipfile(f+'.gz', allowZip64=True, 'w') as zf: + zf.write(f) + + + + + def main(args): #FUSE(WorkdirFS(root), mountpoint, nothreads=True, foreground=True) check_dir(os.path.join(os.environ['HOME'], args.archive))