1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-25 17:27:31 +00:00

prune: Delete all archives in a single transaction

This will improve performance and make the whole operation atomic
This commit is contained in:
Jonas Borgström 2014-03-19 21:58:25 +01:00
parent 80e7e637cc
commit 839dd94a59
2 changed files with 10 additions and 6 deletions

View file

@ -316,7 +316,7 @@ def restore_attrs(self, path, item, symlink=False, fd=None):
elif not symlink: elif not symlink:
os.utime(path, (item[b'mtime'] / 10**9, item[b'mtime'] / 10**9)) os.utime(path, (item[b'mtime'] / 10**9, item[b'mtime'] / 10**9))
def delete(self, cache): def delete(self):
unpacker = msgpack.Unpacker(use_list=False) unpacker = msgpack.Unpacker(use_list=False)
for id_, data in zip(self.metadata[b'items'], self.repository.get_many(self.metadata[b'items'])): for id_, data in zip(self.metadata[b'items'], self.repository.get_many(self.metadata[b'items'])):
unpacker.feed(self.key.decrypt(id_, data)) unpacker.feed(self.key.decrypt(id_, data))
@ -328,9 +328,6 @@ def delete(self, cache):
self.cache.chunk_decref(self.id) self.cache.chunk_decref(self.id)
del self.manifest.archives[self.name] del self.manifest.archives[self.name]
self.manifest.write()
self.repository.commit()
cache.commit()
def stat_attrs(self, st, path): def stat_attrs(self, st, path):
item = { item = {

View file

@ -219,7 +219,10 @@ def do_delete(self, args):
manifest, key = Manifest.load(repository) manifest, key = Manifest.load(repository)
cache = Cache(repository, key, manifest) cache = Cache(repository, key, manifest)
archive = Archive(repository, key, manifest, args.archive.archive, cache=cache) archive = Archive(repository, key, manifest, args.archive.archive, cache=cache)
archive.delete(cache) archive.delete()
manifest.write()
repository.commit()
cache.commit()
return self.exit_code return self.exit_code
def do_mount(self, args): def do_mount(self, args):
@ -338,7 +341,11 @@ def do_prune(self, args):
self.print_verbose('Would prune: %s' % format_archive(archive)) self.print_verbose('Would prune: %s' % format_archive(archive))
else: else:
self.print_verbose('Pruning archive: %s' % format_archive(archive)) self.print_verbose('Pruning archive: %s' % format_archive(archive))
archive.delete(cache) archive.delete()
if to_delete and not args.dry_run:
manifest.write()
repository.commit()
cache.commit()
return self.exit_code return self.exit_code
helptext = {} helptext = {}