compress backups and store as apkg

This commit is contained in:
Damien Elmes 2012-09-22 23:31:38 +09:00
parent 42a6701029
commit c895c80371

View file

@ -280,7 +280,7 @@ how to restore from a backup.""")
# find existing backups # find existing backups
backups = [] backups = []
for file in os.listdir(dir): for file in os.listdir(dir):
m = re.search("backup-(\d+).anki2", file) m = re.search("backup-(\d+).apkg", file)
if not m: if not m:
# unknown file # unknown file
continue continue
@ -292,8 +292,11 @@ how to restore from a backup.""")
else: else:
n = backups[-1][0] + 1 n = backups[-1][0] + 1
# do backup # do backup
newpath = os.path.join(dir, "backup-%d.anki2" % n) newpath = os.path.join(dir, "backup-%d.apkg" % n)
shutil.copyfile(path, newpath) z = zipfile.ZipFile(newpath, "w", zipfile.ZIP_DEFLATED)
z.write(path, "collection.anki2")
z.writestr("media", "{}")
z.close()
# remove if over # remove if over
if len(backups) + 1 > nbacks: if len(backups) + 1 > nbacks:
delete = len(backups) + 1 - nbacks delete = len(backups) + 1 - nbacks