mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
compress backups and store as apkg
This commit is contained in:
parent
42a6701029
commit
c895c80371
1 changed files with 6 additions and 3 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue