MCPcopy
hub / github.com/borgbackup/borg / do_delete

Method do_delete

src/borg/archiver/delete_cmd.py:16–60  ·  view source on GitHub ↗

Deletes archives.

(self, args, repository)

Source from the content-addressed store, hash-verified

14class DeleteMixIn:
15 @with_repository(manifest=False)
16 def do_delete(self, args, repository):
17 """Deletes archives."""
18 self.output_list = args.output_list
19 dry_run = args.dry_run
20 manifest = Manifest.load(repository, (Manifest.Operation.DELETE,))
21 if args.name:
22 archive_infos = [manifest.archives.get_one([args.name])]
23 else:
24 archive_infos = manifest.archives.list_considering(args)
25 archive_infos = [ai for ai in archive_infos if "@PROT" not in ai.tags]
26 count = len(archive_infos)
27 if count == 0:
28 return
29 if not args.name and not args.match_archives and args.first == 0 and args.last == 0:
30 raise CommandError(
31 "Aborting: if you really want to delete all archives, please use -a 'sh:*' "
32 "or just delete the whole repository (might be much faster)."
33 )
34
35 deleted = False
36 logger_list = logging.getLogger("borg.output.list")
37 for i, archive_info in enumerate(archive_infos, 1):
38 name, id, hex_id = archive_info.name, archive_info.id, bin_to_hex(archive_info.id)
39 # format early before deletion of the archive
40 archive_formatted = format_archive(archive_info)
41 try:
42 # this does NOT use Archive.delete, so this code hopefully even works in cases a corrupt archive
43 # would make the code in class Archive crash, so the user can at least get rid of such archives.
44 if not dry_run:
45 manifest.archives.delete_by_id(id)
46 except KeyError:
47 self.print_warning(f"Archive {name} {hex_id} not found ({i}/{count}).")
48 else:
49 deleted = True
50 if self.output_list:
51 msg = "Would delete: {} ({}/{})" if dry_run else "Deleted archive: {} ({}/{})"
52 logger_list.info(msg.format(archive_formatted, i, count))
53 if dry_run:
54 logger.info("Finished dry-run.")
55 elif deleted:
56 manifest.write()
57 self.print_warning('Done. Run "borg compact" to free space.', wc=None)
58 else:
59 self.print_warning("Aborted.", wc=None)
60 return
61
62 def build_parser_delete(self, subparsers, common_parser, mid_common_parser):
63 from ._common import process_epilog, define_archive_filters_group

Callers 1

measurement_runMethod · 0.80

Calls 11

CommandErrorClass · 0.85
bin_to_hexFunction · 0.85
format_archiveFunction · 0.85
get_oneMethod · 0.80
list_consideringMethod · 0.80
delete_by_idMethod · 0.80
print_warningMethod · 0.80
loadMethod · 0.45
infoMethod · 0.45
formatMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected