Browse Source

repo-create: write empty ChunkIndex to repo/cache/, docs

Thomas Waldmann 9 months ago
parent
commit
4e576d51c7
2 changed files with 12 additions and 0 deletions
  1. 4 0
      src/borg/archiver/repo_create_cmd.py
  2. 8 0
      src/borg/repository.py

+ 4 - 0
src/borg/archiver/repo_create_cmd.py

@@ -69,6 +69,10 @@ class RepoCreateMixIn:
         This command creates a new, empty repository. A repository is a ``borgstore`` store
         containing the deduplicated data from zero or more archives.
 
+        Repository creation can be quite slow for some kinds of stores (e.g. for ``sftp:``) -
+        this is due to borgstore pre-creating all directories needed, making usage of the
+        store faster.
+
         Encryption mode TLDR
         ++++++++++++++++++++
 

+ 8 - 0
src/borg/repository.py

@@ -181,6 +181,14 @@ class Repository:
             self.version = 3
             self.store.store("config/version", str(self.version).encode())
             self.store.store("config/id", bin_to_hex(os.urandom(32)).encode())
+            # we know repo/data/ still does not have any chunks stored in it,
+            # but for some stores, there might be a lot of empty directories and
+            # listing them all might be rather slow, so we better cache an empty
+            # ChunkIndex from here so that the first repo operation does not have
+            # to build the ChunkIndex the slow way by listing all the directories.
+            from borg.cache import write_chunkindex_to_repo_cache
+
+            write_chunkindex_to_repo_cache(self, ChunkIndex(), compact=True, clear=True, force_write=True)
         finally:
             self.store.close()