From c895c80371930738e7b011727e5595eee4184e75 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Sat, 22 Sep 2012 23:31:38 +0900 Subject: [PATCH] compress backups and store as apkg --- aqt/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/aqt/main.py b/aqt/main.py index cf755bda2..b94e072b2 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -280,7 +280,7 @@ how to restore from a backup.""") # find existing backups backups = [] for file in os.listdir(dir): - m = re.search("backup-(\d+).anki2", file) + m = re.search("backup-(\d+).apkg", file) if not m: # unknown file continue @@ -292,8 +292,11 @@ how to restore from a backup.""") else: n = backups[-1][0] + 1 # do backup - newpath = os.path.join(dir, "backup-%d.anki2" % n) - shutil.copyfile(path, newpath) + newpath = os.path.join(dir, "backup-%d.apkg" % n) + z = zipfile.ZipFile(newpath, "w", zipfile.ZIP_DEFLATED) + z.write(path, "collection.anki2") + z.writestr("media", "{}") + z.close() # remove if over if len(backups) + 1 > nbacks: delete = len(backups) + 1 - nbacks