constants.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # this set must be kept complete, otherwise the RobustUnpacker might malfunction:
  2. ITEM_KEYS = frozenset(['path', 'source', 'rdev', 'chunks', 'chunks_healthy', 'hardlink_master',
  3. 'mode', 'user', 'group', 'uid', 'gid', 'mtime', 'atime', 'ctime', 'birthtime', 'size',
  4. 'xattrs', 'bsdflags', 'acl_nfs4', 'acl_access', 'acl_default', 'acl_extended',
  5. 'part'])
  6. # this is the set of keys that are always present in items:
  7. REQUIRED_ITEM_KEYS = frozenset(['path', 'mtime', ])
  8. # this set must be kept complete, otherwise rebuild_manifest might malfunction:
  9. ARCHIVE_KEYS = frozenset(['version', 'name', 'items', 'cmdline', 'hostname', 'username', 'time', 'time_end',
  10. 'comment', 'chunker_params',
  11. 'recreate_cmdline',
  12. 'recreate_source_id', 'recreate_args', 'recreate_partial_chunks', # used in 1.1.0b1 .. b2
  13. 'size', 'csize', 'nfiles', 'size_parts', 'csize_parts', 'nfiles_parts', ])
  14. # this is the set of keys that are always present in archives:
  15. REQUIRED_ARCHIVE_KEYS = frozenset(['version', 'name', 'items', 'cmdline', 'time', ])
  16. # default umask, overridden by --umask, defaults to read/write only for owner
  17. UMASK_DEFAULT = 0o077
  18. # default file mode to store stdin data, defaults to read/write for owner and group
  19. # forcing to 0o100XXX later
  20. STDIN_MODE_DEFAULT = 0o660
  21. CACHE_TAG_NAME = 'CACHEDIR.TAG'
  22. CACHE_TAG_CONTENTS = b'Signature: 8a477f597d28d172789f06886806bc55'
  23. # A large, but not unreasonably large segment size. Always less than 2 GiB (for legacy file systems). We choose
  24. # 500 MiB which means that no indirection from the inode is needed for typical Linux file systems.
  25. # Note that this is a soft-limit and can be exceeded (worst case) by a full maximum chunk size and some metadata
  26. # bytes. That's why it's 500 MiB instead of 512 MiB.
  27. DEFAULT_MAX_SEGMENT_SIZE = 500 * 1024 * 1024
  28. # in borg < 1.3, this has been defined like this:
  29. # 20 MiB minus 41 bytes for a PUT header (because the "size" field in the Repository includes
  30. # the header, and the total size was set to precisely 20 MiB for borg < 1.3).
  31. MAX_DATA_SIZE = 20971479
  32. # MAX_OBJECT_SIZE = MAX_DATA_SIZE + len(PUT2 header)
  33. # note: for borg >= 1.3, this makes the MAX_OBJECT_SIZE grow slightly over the precise 20MiB used by
  34. # borg < 1.3, but this is not expected to cause any issues.
  35. MAX_OBJECT_SIZE = MAX_DATA_SIZE + 41 + 8 # see assertion at end of repository module
  36. # repo config max_segment_size value must be below this limit to stay within uint32 offsets:
  37. MAX_SEGMENT_SIZE_LIMIT = 2 ** 32 - MAX_OBJECT_SIZE
  38. # have one all-zero bytes object
  39. # we use it at all places where we need to detect or create all-zero buffers
  40. zeros = bytes(MAX_DATA_SIZE)
  41. # borg.remote read() buffer size
  42. BUFSIZE = 10 * 1024 * 1024
  43. # to use a safe, limited unpacker, we need to set a upper limit to the archive count in the manifest.
  44. # this does not mean that you can always really reach that number, because it also needs to be less than
  45. # MAX_DATA_SIZE or it will trigger the check for that.
  46. MAX_ARCHIVES = 400000
  47. # repo.list() / .scan() result count limit the borg client uses
  48. LIST_SCAN_LIMIT = 100000
  49. DEFAULT_SEGMENTS_PER_DIR = 1000
  50. FD_MAX_AGE = 4 * 60 # 4 minutes
  51. CHUNK_MIN_EXP = 19 # 2**19 == 512kiB
  52. CHUNK_MAX_EXP = 23 # 2**23 == 8MiB
  53. HASH_WINDOW_SIZE = 0xfff # 4095B
  54. HASH_MASK_BITS = 21 # results in ~2MiB chunks statistically
  55. # chunker algorithms
  56. CH_BUZHASH = 'buzhash'
  57. CH_FIXED = 'fixed'
  58. # defaults, use --chunker-params to override
  59. CHUNKER_PARAMS = (CH_BUZHASH, CHUNK_MIN_EXP, CHUNK_MAX_EXP, HASH_MASK_BITS, HASH_WINDOW_SIZE)
  60. # chunker params for the items metadata stream, finer granularity
  61. ITEMS_CHUNKER_PARAMS = (CH_BUZHASH, 15, 19, 17, HASH_WINDOW_SIZE)
  62. # normal on-disk data, allocated (but not written, all zeros), not allocated hole (all zeros)
  63. CH_DATA, CH_ALLOC, CH_HOLE = 0, 1, 2
  64. # operating mode of the files cache (for fast skipping of unchanged files)
  65. DEFAULT_FILES_CACHE_MODE_UI = 'ctime,size,inode' # default for "borg create" command (CLI UI)
  66. DEFAULT_FILES_CACHE_MODE = 'd' # most borg commands do not use the files cache at all (disable)
  67. # return codes returned by borg command
  68. # when borg is killed by signal N, rc = 128 + N
  69. EXIT_SUCCESS = 0 # everything done, no problems
  70. EXIT_WARNING = 1 # reached normal end of operation, but there were issues
  71. EXIT_ERROR = 2 # terminated abruptly, did not reach end of operation
  72. EXIT_SIGNAL_BASE = 128 # terminated due to signal, rc = 128 + sig_no
  73. # never use datetime.isoformat(), it is evil. always use one of these:
  74. # datetime.strftime(ISO_FORMAT) # output always includes .microseconds
  75. # datetime.strftime(ISO_FORMAT_NO_USECS) # output never includes microseconds
  76. ISO_FORMAT_NO_USECS = '%Y-%m-%dT%H:%M:%S'
  77. ISO_FORMAT = ISO_FORMAT_NO_USECS + '.%f'
  78. DASHES = '-' * 78
  79. PBKDF2_ITERATIONS = 100000
  80. # https://www.rfc-editor.org/rfc/rfc9106.html#section-4-6.2
  81. ARGON2_ARGS = {'time_cost': 3, 'memory_cost': 2**16, 'parallelism': 4, 'type': 'id'}
  82. ARGON2_SALT_BYTES = 16
  83. # Maps the CLI argument to our internal identifier for the format
  84. KEY_ALGORITHMS = {
  85. # encrypt-and-MAC, kdf: PBKDF2(HMAC−SHA256), encryption: AES256-CTR, authentication: HMAC-SHA256
  86. 'pbkdf2': 'sha256',
  87. # encrypt-then-MAC, kdf: argon2, encryption: chacha20, authentication: poly1305
  88. 'argon2': 'argon2 chacha20-poly1305',
  89. }
  90. class KeyBlobStorage:
  91. NO_STORAGE = 'no_storage'
  92. KEYFILE = 'keyfile'
  93. REPO = 'repository'
  94. class KeyType:
  95. # legacy crypto
  96. # upper 4 bits are ciphersuite, 0 == legacy AES-CTR
  97. KEYFILE = 0x00
  98. # repos with PASSPHRASE mode could not be created any more since borg 1.0, see #97.
  99. # in borg 1.3 all of its code and also the "borg key migrate-to-repokey" command was removed.
  100. # if you still need to, you can use "borg key migrate-to-repokey" with borg 1.0, 1.1 and 1.2.
  101. # Nowadays, we just dispatch this to RepoKey and assume the passphrase was migrated to a repokey.
  102. PASSPHRASE = 0x01 # legacy, attic and borg < 1.0
  103. PLAINTEXT = 0x02
  104. REPO = 0x03
  105. BLAKE2KEYFILE = 0x04
  106. BLAKE2REPO = 0x05
  107. BLAKE2AUTHENTICATED = 0x06
  108. AUTHENTICATED = 0x07
  109. # new crypto
  110. # upper 4 bits are ciphersuite, lower 4 bits are keytype
  111. AESOCBKEYFILE = 0x10
  112. AESOCBREPO = 0x11
  113. CHPOKEYFILE = 0x20
  114. CHPOREPO = 0x21
  115. BLAKE2AESOCBKEYFILE = 0x30
  116. BLAKE2AESOCBREPO = 0x31
  117. BLAKE2CHPOKEYFILE = 0x40
  118. BLAKE2CHPOREPO = 0x41
  119. REPOSITORY_README = """This is a Borg Backup repository.
  120. See https://borgbackup.readthedocs.io/
  121. """
  122. CACHE_README = """This is a Borg Backup cache.
  123. See https://borgbackup.readthedocs.io/
  124. """