|
3 | 3 | from ..constants import * # NOQA |
4 | 4 | from ..crypto.key import key_creator, encryption_argument_names, id_hash_argument_names |
5 | 5 | from ..helpers import CancelledByUser |
6 | | -from ..helpers import location_validator, Location |
| 6 | +from ..helpers import location_validator, Location, ChunkerParams, CompressionSpec |
7 | 7 | from ..hashindex import ChunkIndex |
8 | 8 | from ..helpers.argparsing import ArgumentParser |
9 | 9 | from ..manifest import Manifest |
@@ -41,6 +41,13 @@ def do_repo_create(self, args, repository, *, other_repository=None, other_manif |
41 | 41 | repository.acquire_lock() |
42 | 42 | # writing the config is what makes the store a repository, see Repository.create(). |
43 | 43 | repository.save_config(key) |
| 44 | + defaults = {} |
| 45 | + if args.compression is not None: |
| 46 | + defaults["compression"] = str(args.compression) |
| 47 | + if args.chunker_params not in (None, DEFAULT_CHUNKER_PARAMS): |
| 48 | + defaults["chunker_params"] = ",".join(str(p) for p in args.chunker_params) |
| 49 | + if defaults: |
| 50 | + repository.save_defaults(defaults) |
44 | 51 | # we know repo/packs/ still does not have any chunks stored in it, but for some stores, there |
45 | 52 | # might be a lot of empty directories and listing them all might be rather slow, so we better |
46 | 53 | # store an empty ChunkIndex now, so that the first repo operation does not have to build the |
@@ -191,6 +198,29 @@ def build_parser_repo_create(self, subparsers, common_parser, mid_common_parser) |
191 | 198 | To normally work with ``authenticated-*`` repositories, you will need the passphrase, but |
192 | 199 | there is an emergency workaround; see ``BORG_WORKAROUNDS=authenticated_no_key`` docs. |
193 | 200 |
|
| 201 | + Repository defaults |
| 202 | + +++++++++++++++++++ |
| 203 | +
|
| 204 | + ``--compression`` sets the repository's default compression: the commands that compress |
| 205 | + data (``borg create``, ``borg recreate``, ``borg import-tar``, ``borg transfer``, |
| 206 | + ``borg repo-compress``) use it if no compression was given via ``--compression``, the |
| 207 | + environment or the default config file (``default.yaml``). Without a repository default, |
| 208 | + they use lz4. See ``borg help compression`` for the compression specs. |
| 209 | +
|
| 210 | + ``--chunker-params`` sets the repository's default chunker parameters: ``borg create`` and |
| 211 | + ``borg import-tar`` use them if no chunker parameters were given (in the same ways as above). |
| 212 | + ``borg recreate`` and ``borg transfer`` only rechunk if ``--chunker-params`` is given, with |
| 213 | + ``--chunker-params default``, they rechunk to the repository's default chunker parameters. |
| 214 | + Without a repository default, the built-in default chunker parameters are used. |
| 215 | +
|
| 216 | + This is useful if several clients back up into the same repository or if some commands are |
| 217 | + run manually: they all compress and chunk the same way without having to give these options. |
| 218 | + Using the same chunker parameters is important for deduplication. |
| 219 | + ``borg repo-info`` shows the defaults. |
| 220 | +
|
| 221 | + The defaults are stored in the repository and protected by the repository key, so nobody without |
| 222 | + the key can change them (e.g. remove an ``obfuscate`` compression) without being noticed. |
| 223 | +
|
194 | 224 | Creating a related repository |
195 | 225 | +++++++++++++++++++++++++++++ |
196 | 226 |
|
@@ -263,6 +293,27 @@ def build_parser_repo_create(self, subparsers, common_parser, mid_common_parser) |
263 | 293 | help="where to store the key: 'repokey' (in the repository, default) or 'keyfile' " |
264 | 294 | "(in the local keys directory).", |
265 | 295 | ) |
| 296 | + subparser.add_argument( |
| 297 | + "-C", |
| 298 | + "--compression", |
| 299 | + metavar="COMPRESSION", |
| 300 | + dest="compression", |
| 301 | + type=CompressionSpec, |
| 302 | + default=None, |
| 303 | + action=Highlander, |
| 304 | + help="set the default compression of the repository, see the output of the " |
| 305 | + '"borg help compression" command for details. Default: no repository default (lz4 is used).', |
| 306 | + ) |
| 307 | + subparser.add_argument( |
| 308 | + "--chunker-params", |
| 309 | + metavar="PARAMS", |
| 310 | + dest="chunker_params", |
| 311 | + type=ChunkerParams, |
| 312 | + default=None, |
| 313 | + action=Highlander, |
| 314 | + help="set the default chunker parameters of the repository (same format as for borg create). " |
| 315 | + "Default: no repository default (%s,%d,%d,%d,%d is used)." % CHUNKER_PARAMS, |
| 316 | + ) |
266 | 317 | subparser.add_argument( |
267 | 318 | "--copy-crypt-key", |
268 | 319 | dest="copy_crypt_key", |
|
0 commit comments