Quellcode durchsuchen

borg info <repo>: print general repo information (#1680)

enkore vor 8 Jahren
Ursprung
Commit
27bc73c23e
2 geänderte Dateien mit 16 neuen und 2 gelöschten Zeilen
  1. 12 2
      src/borg/archiver.py
  2. 4 0
      src/borg/key.py

+ 12 - 2
src/borg/archiver.py

@@ -920,7 +920,7 @@ class Archiver:
         if any((args.location.archive, args.first, args.last, args.prefix)):
         if any((args.location.archive, args.first, args.last, args.prefix)):
             return self._info_archives(args, repository, manifest, key, cache)
             return self._info_archives(args, repository, manifest, key, cache)
         else:
         else:
-            return self._info_repository(cache)
+            return self._info_repository(repository, key, cache)
 
 
     def _info_archives(self, args, repository, manifest, key, cache):
     def _info_archives(self, args, repository, manifest, key, cache):
         def format_cmdline(cmdline):
         def format_cmdline(cmdline):
@@ -957,7 +957,17 @@ class Archiver:
                 print()
                 print()
         return self.exit_code
         return self.exit_code
 
 
-    def _info_repository(self, cache):
+    def _info_repository(self, repository, key, cache):
+        print('Repository ID: %s' % bin_to_hex(repository.id))
+        if key.NAME == 'plaintext':
+            encrypted = 'No'
+        else:
+            encrypted = 'Yes (%s)' % key.NAME
+        print('Encrypted: %s' % encrypted)
+        if key.NAME == 'key file':
+            print('Key file: %s' % key.find_key())
+        print('Cache: %s' % cache.path)
+        print(DASHES)
         print(STATS_HEADER)
         print(STATS_HEADER)
         print(str(cache))
         print(str(cache))
         return self.exit_code
         return self.exit_code

+ 4 - 0
src/borg/key.py

@@ -118,6 +118,7 @@ class KeyBase:
 
 
 class PlaintextKey(KeyBase):
 class PlaintextKey(KeyBase):
     TYPE = 0x02
     TYPE = 0x02
+    NAME = 'plaintext'
 
 
     chunk_seed = 0
     chunk_seed = 0
 
 
@@ -281,6 +282,7 @@ class PassphraseKey(AESKeyBase):
     # - --encryption=passphrase is an invalid argument now
     # - --encryption=passphrase is an invalid argument now
     # This class is kept for a while to support migration from passphrase to repokey mode.
     # This class is kept for a while to support migration from passphrase to repokey mode.
     TYPE = 0x01
     TYPE = 0x01
+    NAME = 'passphrase'
     iterations = 100000  # must not be changed ever!
     iterations = 100000  # must not be changed ever!
 
 
     @classmethod
     @classmethod
@@ -432,6 +434,7 @@ class KeyfileKeyBase(AESKeyBase):
 
 
 class KeyfileKey(KeyfileKeyBase):
 class KeyfileKey(KeyfileKeyBase):
     TYPE = 0x00
     TYPE = 0x00
+    NAME = 'key file'
     FILE_ID = 'BORG_KEY'
     FILE_ID = 'BORG_KEY'
 
 
     def sanity_check(self, filename, id):
     def sanity_check(self, filename, id):
@@ -491,6 +494,7 @@ class KeyfileKey(KeyfileKeyBase):
 
 
 class RepoKey(KeyfileKeyBase):
 class RepoKey(KeyfileKeyBase):
     TYPE = 0x03
     TYPE = 0x03
+    NAME = 'repokey'
 
 
     def find_key(self):
     def find_key(self):
         loc = self.repository._location.canonical_path()
         loc = self.repository._location.canonical_path()