frontends.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. .. include:: ../global.rst.inc
  2. .. highlight:: json
  3. .. _json_output:
  4. All about JSON: How to develop frontends
  5. ========================================
  6. Borg does not have a public API on the Python level. That does not keep you from writing :code:`import borg`,
  7. but does mean that there are no release-to-release guarantees on what you might find in that package, not
  8. even for point releases (1.1.x), and there is no documentation beyond the code and the internals documents.
  9. Borg does on the other hand provide an API on a command-line level. In other words, a frontend should to
  10. (for example) create a backup archive just invoke :ref:`borg_create`.
  11. Logging
  12. -------
  13. Especially for graphical frontends it is important to be able to convey and reformat progress information
  14. in meaningful ways. The ``--log-json`` option turns the stderr stream of Borg into a stream of JSON lines,
  15. where each line is a JSON object. The *type* key of the object determines its other contents.
  16. Since JSON can only encode text, any string representing a file system path may miss non-text parts.
  17. The following types are in use. Progress information is governed by the usual rules for progress information,
  18. it is not produced unless ``--progress`` is specified.
  19. archive_progress
  20. Output during operations creating archives (:ref:`borg_create` and :ref:`borg_recreate`).
  21. The following keys exist, each represents the current progress.
  22. original_size
  23. Original size of data processed so far (before compression and deduplication)
  24. compressed_size
  25. Compressed size
  26. deduplicated_size
  27. Deduplicated size
  28. nfiles
  29. Number of (regular) files processed so far
  30. path
  31. Current path
  32. time
  33. Unix timestamp (float)
  34. progress_message
  35. A message-based progress information with no concrete progress information, just a message
  36. saying what is currently being worked on.
  37. operation
  38. unique, opaque integer ID of the operation
  39. :ref:`msgid <msgid>`
  40. Message ID of the operation (may be *null*)
  41. finished
  42. boolean indicating whether the operation has finished, only the last object for an *operation*
  43. can have this property set to *true*.
  44. message
  45. current progress message (may be empty/absent)
  46. time
  47. Unix timestamp (float)
  48. progress_percent
  49. Absolute progress information with defined end/total and current value.
  50. operation
  51. unique, opaque integer ID of the operation
  52. :ref:`msgid <msgid>`
  53. Message ID of the operation (may be *null*)
  54. finished
  55. boolean indicating whether the operation has finished, only the last object for an *operation*
  56. can have this property set to *true*.
  57. message
  58. A formatted progress message, this will include the percentage and perhaps other information
  59. current
  60. Current value (always less-or-equal to *total*)
  61. info
  62. Array that describes the current item, may be *null*, contents depend on *msgid*
  63. total
  64. Total value
  65. time
  66. Unix timestamp (float)
  67. file_status
  68. This is only output by :ref:`borg_create` and :ref:`borg_recreate` if ``--list`` is specified. The usual
  69. rules for the file listing applies, including the ``--filter`` option.
  70. status
  71. Single-character status as for regular list output
  72. path
  73. Path of the file system object
  74. log_message
  75. Any regular log output invokes this type. Regular log options and filtering applies to these as well.
  76. time
  77. Unix timestamp (float)
  78. levelname
  79. Upper-case log level name (also called severity). Defined levels are: DEBUG, INFO, WARNING, ERROR, CRITICAL
  80. name
  81. Name of the emitting entity
  82. message
  83. Formatted log message
  84. :ref:`msgid <msgid>`
  85. Message ID, may be *null* or absent
  86. See Prompts_ for the types used by prompts.
  87. .. rubric:: Examples (reformatted, each object would be on exactly one line)
  88. :ref:`borg_extract` progress::
  89. {"message": "100.0% Extracting: src/borgbackup.egg-info/entry_points.txt",
  90. "current": 13000228, "total": 13004993, "info": ["src/borgbackup.egg-info/entry_points.txt"],
  91. "operation": 1, "msgid": "extract", "type": "progress_percent", "finished": false}
  92. {"message": "100.0% Extracting: src/borgbackup.egg-info/SOURCES.txt",
  93. "current": 13004993, "total": 13004993, "info": ["src/borgbackup.egg-info/SOURCES.txt"],
  94. "operation": 1, "msgid": "extract", "type": "progress_percent", "finished": false}
  95. {"operation": 1, "msgid": "extract", "type": "progress_percent", "finished": true}
  96. :ref:`borg_create` file listing with progress::
  97. {"original_size": 0, "compressed_size": 0, "deduplicated_size": 0, "nfiles": 0, "type": "archive_progress", "path": "src"}
  98. {"type": "file_status", "status": "U", "path": "src/borgbackup.egg-info/entry_points.txt"}
  99. {"type": "file_status", "status": "U", "path": "src/borgbackup.egg-info/SOURCES.txt"}
  100. {"type": "file_status", "status": "d", "path": "src/borgbackup.egg-info"}
  101. {"type": "file_status", "status": "d", "path": "src"}
  102. {"original_size": 13176040, "compressed_size": 11386863, "deduplicated_size": 503, "nfiles": 277, "type": "archive_progress", "path": ""}
  103. Internal transaction progress::
  104. {"message": "Saving files cache", "operation": 2, "msgid": "cache.commit", "type": "progress_message", "finished": false}
  105. {"message": "Saving cache config", "operation": 2, "msgid": "cache.commit", "type": "progress_message", "finished": false}
  106. {"message": "Saving chunks cache", "operation": 2, "msgid": "cache.commit", "type": "progress_message", "finished": false}
  107. {"operation": 2, "msgid": "cache.commit", "type": "progress_message", "finished": true}
  108. A debug log message::
  109. {"message": "35 self tests completed in 0.08 seconds",
  110. "type": "log_message", "created": 1488278449.5575905, "levelname": "DEBUG", "name": "borg.archiver"}
  111. Prompts
  112. -------
  113. Prompts assume a JSON form as well when the ``--log-json`` option is specified. Responses
  114. are still read verbatim from *stdin*, while prompts are JSON messages printed to *stderr*,
  115. just like log messages.
  116. Prompts use the *question_prompt* and *question_prompt_retry* types for the prompt itself,
  117. and *question_invalid_answer*, *question_accepted_default*, *question_accepted_true*,
  118. *question_accepted_false* and *question_env_answer* types for information about
  119. prompt processing.
  120. The *message* property contains the same string displayed regularly in the same situation,
  121. while the *msgid* property may contain a msgid_, typically the name of the
  122. environment variable that can be used to override the prompt. It is the same for all JSON
  123. messages pertaining to the same prompt.
  124. .. rubric:: Examples (reformatted, each object would be on exactly one line)
  125. Providing an invalid answer::
  126. {"type": "question_prompt", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING",
  127. "message": "... Type 'YES' if you understand this and want to continue: "}
  128. incorrect answer # input on stdin
  129. {"type": "question_invalid_answer", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING", "is_prompt": false,
  130. "message": "Invalid answer, aborting."}
  131. Providing a false (negative) answer::
  132. {"type": "question_prompt", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING",
  133. "message": "... Type 'YES' if you understand this and want to continue: "}
  134. NO # input on stdin
  135. {"type": "question_accepted_false", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING",
  136. "message": "Aborting.", "is_prompt": false}
  137. Providing a true (affirmative) answer::
  138. {"type": "question_prompt", "msgid": "BORG_CHECK_I_KNOW_WHAT_I_AM_DOING",
  139. "message": "... Type 'YES' if you understand this and want to continue: "}
  140. YES # input on stdin
  141. # no further output, just like the prompt without --log-json
  142. Passphrase prompts
  143. ------------------
  144. Passphrase prompts should be handled differently. Use the environment variables *BORG_PASSPHRASE*
  145. and *BORG_NEW_PASSPHRASE* (see :ref:`env_vars` for reference) to pass passphrases to Borg, don't
  146. use the interactive passphrase prompts.
  147. When setting a new passphrase (:ref:`borg_init`, :ref:`borg_key_change-passphrase`) normally
  148. Borg prompts whether it should display the passphrase. This can be suppressed by setting
  149. the environment variable *BORG_DISPLAY_PASSPHRASE* to *no*.
  150. When "confronted" with an unknown repository, where the application does not know whether
  151. the repository is encrypted, the following algorithm can be followed to detect encryption:
  152. 1. Set *BORG_PASSPHRASE* to gibberish (for example a freshly generated UUID4, which cannot
  153. possibly be the passphrase)
  154. 2. Invoke ``borg list repository ...``
  155. 3. If this fails, due the repository being encrypted and the passphrase obviously being
  156. wrong, you'll get an error with the *PassphraseWrong* msgid.
  157. The repository is encrypted, for further access the application will need the passphrase.
  158. 4. If this does not fail, then the repository is not encrypted.
  159. Standard output
  160. ---------------
  161. *stdout* is different and more command-dependent than logging. Commands like :ref:`borg_info`, :ref:`borg_create`
  162. and :ref:`borg_list` implement a ``--json`` option which turns their regular output into a single JSON object.
  163. Dates are formatted according to ISO-8601 in local time. Neither an explicit time zone nor microseconds
  164. are specified *at this time* (subject to change). The equivalent strftime format string is '%Y-%m-%dT%H:%M:%S',
  165. e.g. 2017-08-07T12:27:20.
  166. The root object at least contains a *repository* key with an object containing:
  167. id
  168. The ID of the repository, normally 64 hex characters
  169. location
  170. Canonicalized repository path, thus this may be different from what is specified on the command line
  171. last_modified
  172. Date when the repository was last modified by the Borg client
  173. The *encryption* key, if present, contains:
  174. mode
  175. Textual encryption mode name (same as :ref:`borg_init` ``--encryption`` names)
  176. keyfile
  177. Path to the local key file used for access. Depending on *mode* this key may be absent.
  178. The *cache* key, if present, contains:
  179. path
  180. Path to the local repository cache
  181. stats
  182. Object containing cache stats:
  183. total_chunks
  184. Number of chunks
  185. total_unique_chunks
  186. Number of unique chunks
  187. total_size
  188. Total uncompressed size of all chunks multiplied with their reference counts
  189. total_csize
  190. Total compressed and encrypted size of all chunks multiplied with their reference counts
  191. unique_size
  192. Uncompressed size of all chunks
  193. unique_csize
  194. Compressed and encrypted size of all chunks
  195. Example *borg info* output::
  196. {
  197. "cache": {
  198. "path": "/home/user/.cache/borg/0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  199. "stats": {
  200. "total_chunks": 511533,
  201. "total_csize": 17948017540,
  202. "total_size": 22635749792,
  203. "total_unique_chunks": 54892,
  204. "unique_csize": 1920405405,
  205. "unique_size": 2449675468
  206. }
  207. },
  208. "encryption": {
  209. "mode": "repokey"
  210. },
  211. "repository": {
  212. "id": "0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  213. "last_modified": "2017-08-07T12:27:20",
  214. "location": "/home/user/testrepo"
  215. },
  216. "security_dir": "/home/user/.config/borg/security/0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  217. "archives": []
  218. }
  219. Archive formats
  220. +++++++++++++++
  221. :ref:`borg_info` uses an extended format for archives, which is more expensive to retrieve, while
  222. :ref:`borg_list` uses a simpler format that is faster to retrieve. Either return archives in an
  223. array under the *archives* key, while :ref:`borg_create` returns a single archive object under the
  224. *archive* key.
  225. Both formats contain a *name* key with the archive name, the *id* key with the hexadecimal archive ID,
  226. and the *start* key with the start timestamp.
  227. *borg info* and *borg create* further have:
  228. end
  229. End timestamp
  230. duration
  231. Duration in seconds between start and end in seconds (float)
  232. stats
  233. Archive statistics (freshly calculated, this is what makes "info" more expensive)
  234. original_size
  235. Size of files and metadata before compression
  236. compressed_size
  237. Size after compression
  238. deduplicated_size
  239. Deduplicated size (against the current repository, not when the archive was created)
  240. nfiles
  241. Number of regular files in the archive
  242. limits
  243. Object describing the utilization of Borg limits
  244. max_archive_size
  245. Float between 0 and 1 describing how large this archive is relative to the maximum size allowed by Borg
  246. command_line
  247. Array of strings of the command line that created the archive
  248. The note about paths from above applies here as well.
  249. :ref:`borg_info` further has:
  250. hostname
  251. Hostname of the creating host
  252. username
  253. Name of the creating user
  254. comment
  255. Archive comment, if any
  256. Example of a simple archive listing (``borg list --last 1 --json``)::
  257. {
  258. "archives": [
  259. {
  260. "id": "80cd07219ad725b3c5f665c1dcf119435c4dee1647a560ecac30f8d40221a46a",
  261. "name": "host-system-backup-2017-02-27",
  262. "start": "2017-08-07T12:27:20"
  263. }
  264. ],
  265. "encryption": {
  266. "mode": "repokey"
  267. },
  268. "repository": {
  269. "id": "0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  270. "last_modified": "2017-08-07T12:27:20",
  271. "location": "/home/user/repository"
  272. }
  273. }
  274. The same archive with more information (``borg info --last 1 --json``)::
  275. {
  276. "archives": [
  277. {
  278. "command_line": [
  279. "/home/user/.local/bin/borg",
  280. "create",
  281. "/home/user/repository",
  282. "..."
  283. ],
  284. "comment": "",
  285. "duration": 5.641542,
  286. "end": "2017-02-27T12:27:20",
  287. "hostname": "host",
  288. "id": "80cd07219ad725b3c5f665c1dcf119435c4dee1647a560ecac30f8d40221a46a",
  289. "limits": {
  290. "max_archive_size": 0.0001330855110409714
  291. },
  292. "name": "host-system-backup-2017-02-27",
  293. "start": "2017-02-27T12:27:20",
  294. "stats": {
  295. "compressed_size": 1880961894,
  296. "deduplicated_size": 2791,
  297. "nfiles": 53669,
  298. "original_size": 2400471280
  299. },
  300. "username": "user"
  301. }
  302. ],
  303. "cache": {
  304. "path": "/home/user/.cache/borg/0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  305. "stats": {
  306. "total_chunks": 511533,
  307. "total_csize": 17948017540,
  308. "total_size": 22635749792,
  309. "total_unique_chunks": 54892,
  310. "unique_csize": 1920405405,
  311. "unique_size": 2449675468
  312. }
  313. },
  314. "encryption": {
  315. "mode": "repokey"
  316. },
  317. "repository": {
  318. "id": "0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  319. "last_modified": "2017-08-07T12:27:20",
  320. "location": "/home/user/repository"
  321. }
  322. }
  323. File listings
  324. +++++++++++++
  325. Listing the contents of an archive can produce *a lot* of JSON. Since many JSON implementations
  326. don't support a streaming mode of operation, which is pretty much required to deal with this amount of
  327. JSON, output is generated in the `JSON lines <http://jsonlines.org/>`_ format, which is simply
  328. a number of JSON objects separated by new lines.
  329. Each item (file, directory, ...) is described by one object in the :ref:`borg_list` output.
  330. Refer to the *borg list* documentation for the available keys and their meaning.
  331. Example (excerpt) of ``borg list --json-lines``::
  332. {"type": "d", "mode": "drwxr-xr-x", "user": "user", "group": "user", "uid": 1000, "gid": 1000, "path": "linux", "healthy": true, "source": "", "linktarget": "", "flags": null, "isomtime": "2017-02-27T12:27:20", "size": 0}
  333. {"type": "d", "mode": "drwxr-xr-x", "user": "user", "group": "user", "uid": 1000, "gid": 1000, "path": "linux/baz", "healthy": true, "source": "", "linktarget": "", "flags": null, "isomtime": "2017-02-27T12:27:20", "size": 0}
  334. .. _msgid:
  335. Message IDs
  336. -----------
  337. Message IDs are strings that essentially give a log message or operation a name, without actually using the
  338. full text, since texts change more frequently. Message IDs are unambiguous and reduce the need to parse
  339. log messages.
  340. Assigned message IDs are:
  341. .. See scripts/errorlist.py; this is slightly edited.
  342. Errors
  343. Archive.AlreadyExists
  344. Archive {} already exists
  345. Archive.DoesNotExist
  346. Archive {} does not exist
  347. Archive.IncompatibleFilesystemEncodingError
  348. Failed to encode filename "{}" into file system encoding "{}". Consider configuring the LANG environment variable.
  349. Cache.CacheInitAbortedError
  350. Cache initialization aborted
  351. Cache.EncryptionMethodMismatch
  352. Repository encryption method changed since last access, refusing to continue
  353. Cache.RepositoryAccessAborted
  354. Repository access aborted
  355. Cache.RepositoryIDNotUnique
  356. Cache is newer than repository - do you have multiple, independently updated repos with same ID?
  357. Cache.RepositoryReplay
  358. Cache is newer than repository - this is either an attack or unsafe (multiple repos with same ID)
  359. Buffer.MemoryLimitExceeded
  360. Requested buffer size {} is above the limit of {}.
  361. ExtensionModuleError
  362. The Borg binary extension modules do not seem to be properly installed
  363. IntegrityError
  364. Data integrity error: {}
  365. NoManifestError
  366. Repository has no manifest.
  367. PlaceholderError
  368. Formatting Error: "{}".format({}): {}({})
  369. KeyfileInvalidError
  370. Invalid key file for repository {} found in {}.
  371. KeyfileMismatchError
  372. Mismatch between repository {} and key file {}.
  373. KeyfileNotFoundError
  374. No key file for repository {} found in {}.
  375. PassphraseWrong
  376. passphrase supplied in BORG_PASSPHRASE is incorrect
  377. PasswordRetriesExceeded
  378. exceeded the maximum password retries
  379. RepoKeyNotFoundError
  380. No key entry found in the config of repository {}.
  381. UnsupportedManifestError
  382. Unsupported manifest envelope. A newer version is required to access this repository.
  383. UnsupportedPayloadError
  384. Unsupported payload type {}. A newer version is required to access this repository.
  385. NotABorgKeyFile
  386. This file is not a borg key backup, aborting.
  387. RepoIdMismatch
  388. This key backup seems to be for a different backup repository, aborting.
  389. UnencryptedRepo
  390. Keymanagement not available for unencrypted repositories.
  391. UnknownKeyType
  392. Keytype {0} is unknown.
  393. LockError
  394. Failed to acquire the lock {}.
  395. LockErrorT
  396. Failed to acquire the lock {}.
  397. ConnectionClosed
  398. Connection closed by remote host
  399. InvalidRPCMethod
  400. RPC method {} is not valid
  401. PathNotAllowed
  402. Repository path not allowed
  403. RemoteRepository.RPCServerOutdated
  404. Borg server is too old for {}. Required version {}
  405. UnexpectedRPCDataFormatFromClient
  406. Borg {}: Got unexpected RPC data format from client.
  407. UnexpectedRPCDataFormatFromServer
  408. Got unexpected RPC data format from server:
  409. {}
  410. Repository.AlreadyExists
  411. Repository {} already exists.
  412. Repository.CheckNeeded
  413. Inconsistency detected. Please run "borg check {}".
  414. Repository.DoesNotExist
  415. Repository {} does not exist.
  416. Repository.InsufficientFreeSpaceError
  417. Insufficient free space to complete transaction (required: {}, available: {}).
  418. Repository.InvalidRepository
  419. {} is not a valid repository. Check repo config.
  420. Repository.AtticRepository
  421. Attic repository detected. Please run "borg upgrade {}".
  422. Repository.ObjectNotFound
  423. Object with key {} not found in repository {}.
  424. Operations
  425. - cache.begin_transaction
  426. - cache.download_chunks, appears with ``borg create --no-cache-sync``
  427. - cache.commit
  428. - cache.sync
  429. *info* is one string element, the name of the archive currently synced.
  430. - repository.compact_segments
  431. - repository.replay_segments
  432. - repository.check_segments
  433. - check.verify_data
  434. - extract
  435. *info* is one string element, the name of the path currently extracted.
  436. - extract.permissions
  437. - archive.delete
  438. Prompts
  439. BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK
  440. For "Warning: Attempting to access a previously unknown unencrypted repository"
  441. BORG_RELOCATED_REPO_ACCESS_IS_OK
  442. For "Warning: The repository at location ... was previously located at ..."
  443. BORG_CHECK_I_KNOW_WHAT_I_AM_DOING
  444. For "Warning: 'check --repair' is an experimental feature that might result in data loss."
  445. BORG_DELETE_I_KNOW_WHAT_I_AM_DOING
  446. For "You requested to completely DELETE the repository *including* all archives it contains:"
  447. BORG_RECREATE_I_KNOW_WHAT_I_AM_DOING
  448. For "recreate is an experimental feature."