From 479bab1d96291bc1bfb648a277c50efe39bc99da Mon Sep 17 00:00:00 2001 From: lionel <> Date: Sat, 2 Oct 2021 00:41:27 +0200 Subject: [PATCH] Multithreading gzip --- Backup.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Backup.py b/Backup.py index 4b0ba0a..252de9b 100644 --- a/Backup.py +++ b/Backup.py @@ -1,5 +1,5 @@ import re -import gzip +import mgzip as gzip import tarfile import sqlite3 from crypt import * @@ -26,10 +26,10 @@ class Backup: print(f + " : ", human_size(size)) if size > tarball_size: enc = crypt(compress(uri), self.key) - crypt_name = self.bdd.add([{'name': f, 'path': uri}], compress_mode="gz") + crypt_name = self.bdd.add([{'name': f, 'path': uri, 'size': size}], compress_mode="gz") save(enc, os.path.join(self.save_location, crypt_name)) else: - files.append({'name': f, 'path': uri}) + files.append({'name': f, 'path': uri, 'size': size}) elif os.path.isdir(uri): self.recurse(uri) if len(files) > 0: @@ -128,6 +128,7 @@ class DataBase: id INTEGER PRIMARY KEY UNIQUE NOT NULL, name TEXT, path TEXT, + size TEXT, crypt_id INTEGER, CONSTRAINT files_crypt_FK FOREIGN KEY (crypt_id) REFERENCES crypt(id) ) @@ -149,7 +150,8 @@ class DataBase: cursor.execute("""SELECT IFNULL(max(id) + 1, 0) FROM files""") files_id = cursor.fetchone()[0] for file in list_file: - cursor.execute("""INSERT INTO files VALUES(?, ?, ?, ?)""", (files_id, file['name'], file['path'], crypt_id)) + cursor.execute("""INSERT INTO files VALUES(?, ?, ?, ?, ?)""", + (files_id, file['name'], file['path'], file['size'], crypt_id)) files_id += 1 cursor.execute("""INSERT INTO crypt VALUES(?, ?)""", (crypt_id, compress_mode))