frontends.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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 with the strftime format string '%a, %Y-%m-%d %H:%M:%S',
  164. e.g. *Sat, 2016-02-25 23:50:06*.
  165. The root object at least contains a *repository* key with an object containing:
  166. id
  167. The ID of the repository, normally 64 hex characters
  168. location
  169. Canonicalized repository path, thus this may be different from what is specified on the command line
  170. last_modified
  171. Date when the repository was last modified by the Borg client
  172. The *encryption* key, if present, contains:
  173. mode
  174. Textual encryption mode name (same as :ref:`borg_init` ``--encryption`` names)
  175. keyfile
  176. Path to the local key file used for access. Depending on *mode* this key may be absent.
  177. The *cache* key, if present, contains:
  178. path
  179. Path to the local repository cache
  180. stats
  181. Object containing cache stats:
  182. total_chunks
  183. Number of chunks
  184. total_unique_chunks
  185. Number of unique chunks
  186. total_size
  187. Total uncompressed size of all chunks multiplied with their reference counts
  188. total_csize
  189. Total compressed and encrypted size of all chunks multiplied with their reference counts
  190. unique_size
  191. Uncompressed size of all chunks
  192. unique_csize
  193. Compressed and encrypted size of all chunks
  194. Example *borg info* output::
  195. {
  196. "cache": {
  197. "path": "/home/user/.cache/borg/0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  198. "stats": {
  199. "total_chunks": 511533,
  200. "total_csize": 17948017540,
  201. "total_size": 22635749792,
  202. "total_unique_chunks": 54892,
  203. "unique_csize": 1920405405,
  204. "unique_size": 2449675468
  205. }
  206. },
  207. "encryption": {
  208. "mode": "repokey"
  209. },
  210. "repository": {
  211. "id": "0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  212. "last_modified": "Mon, 2017-02-27 21:21:58",
  213. "location": "/home/user/testrepo"
  214. },
  215. "security_dir": "/home/user/.config/borg/security/0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  216. "archives": []
  217. }
  218. Archive formats
  219. +++++++++++++++
  220. :ref:`borg_info` uses an extended format for archives, which is more expensive to retrieve, while
  221. :ref:`borg_list` uses a simpler format that is faster to retrieve. Either return archives in an
  222. array under the *archives* key, while :ref:`borg_create` returns a single archive object under the
  223. *archive* key.
  224. Both formats contain a *name* key with the archive name, the *id* key with the hexadecimal archive ID,
  225. and the *start* key with the start timestamp.
  226. *borg info* and *borg create* further have:
  227. end
  228. End timestamp
  229. duration
  230. Duration in seconds between start and end in seconds (float)
  231. stats
  232. Archive statistics (freshly calculated, this is what makes "info" more expensive)
  233. original_size
  234. Size of files and metadata before compression
  235. compressed_size
  236. Size after compression
  237. deduplicated_size
  238. Deduplicated size (against the current repository, not when the archive was created)
  239. nfiles
  240. Number of regular files in the archive
  241. limits
  242. Object describing the utilization of Borg limits
  243. max_archive_size
  244. Float between 0 and 1 describing how large this archive is relative to the maximum size allowed by Borg
  245. command_line
  246. Array of strings of the command line that created the archive
  247. The note about paths from above applies here as well.
  248. :ref:`borg_info` further has:
  249. hostname
  250. Hostname of the creating host
  251. username
  252. Name of the creating user
  253. comment
  254. Archive comment, if any
  255. Example of a simple archive listing (``borg list --last 1 --json``)::
  256. {
  257. "archives": [
  258. {
  259. "id": "80cd07219ad725b3c5f665c1dcf119435c4dee1647a560ecac30f8d40221a46a",
  260. "name": "host-system-backup-2017-02-27",
  261. "start": "Mon, 2017-02-27 21:21:52"
  262. }
  263. ],
  264. "encryption": {
  265. "mode": "repokey"
  266. },
  267. "repository": {
  268. "id": "0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  269. "last_modified": "Mon, 2017-02-27 21:21:58",
  270. "location": "/home/user/repository"
  271. }
  272. }
  273. The same archive with more information (``borg info --last 1 --json``)::
  274. {
  275. "archives": [
  276. {
  277. "command_line": [
  278. "/home/user/.local/bin/borg",
  279. "create",
  280. "/home/user/repository",
  281. "..."
  282. ],
  283. "comment": "",
  284. "duration": 5.641542,
  285. "end": "Mon, 2017-02-27 21:21:58",
  286. "hostname": "host",
  287. "id": "80cd07219ad725b3c5f665c1dcf119435c4dee1647a560ecac30f8d40221a46a",
  288. "limits": {
  289. "max_archive_size": 0.0001330855110409714
  290. },
  291. "name": "host-system-backup-2017-02-27",
  292. "start": "Mon, 2017-02-27 21:21:52",
  293. "stats": {
  294. "compressed_size": 1880961894,
  295. "deduplicated_size": 2791,
  296. "nfiles": 53669,
  297. "original_size": 2400471280
  298. },
  299. "username": "user"
  300. }
  301. ],
  302. "cache": {
  303. "path": "/home/user/.cache/borg/0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  304. "stats": {
  305. "total_chunks": 511533,
  306. "total_csize": 17948017540,
  307. "total_size": 22635749792,
  308. "total_unique_chunks": 54892,
  309. "unique_csize": 1920405405,
  310. "unique_size": 2449675468
  311. }
  312. },
  313. "encryption": {
  314. "mode": "repokey"
  315. },
  316. "repository": {
  317. "id": "0cbe6166b46627fd26b97f8831e2ca97584280a46714ef84d2b668daf8271a23",
  318. "last_modified": "Mon, 2017-02-27 21:21:58",
  319. "location": "/home/user/repository"
  320. }
  321. }
  322. File listings
  323. +++++++++++++
  324. Listing the contents of an archive can produce *a lot* of JSON. Since many JSON implementations
  325. don't support a streaming mode of operation, which is pretty much required to deal with this amount of
  326. JSON, output is generated in the `JSON lines <http://jsonlines.org/>`_ format, which is simply
  327. a number of JSON objects separated by new lines.
  328. Each item (file, directory, ...) is described by one object in the :ref:`borg_list` output.
  329. Refer to the *borg list* documentation for the available keys and their meaning.
  330. Example (excerpt) of ``borg list --json-lines``::
  331. {"type": "d", "mode": "drwxr-xr-x", "user": "user", "group": "user", "uid": 1000, "gid": 1000, "path": "linux", "healthy": true, "source": "", "linktarget": "", "flags": null, "isomtime": "Sat, 2016-05-07 19:46:01", "size": 0}
  332. {"type": "d", "mode": "drwxr-xr-x", "user": "user", "group": "user", "uid": 1000, "gid": 1000, "path": "linux/baz", "healthy": true, "source": "", "linktarget": "", "flags": null, "isomtime": "Sat, 2016-05-07 19:46:01", "size": 0}
  333. .. _msgid:
  334. Message IDs
  335. -----------
  336. Message IDs are strings that essentially give a log message or operation a name, without actually using the
  337. full text, since texts change more frequently. Message IDs are unambiguous and reduce the need to parse
  338. log messages.
  339. Assigned message IDs are:
  340. .. See scripts/errorlist.py; this is slightly edited.
  341. Errors
  342. Archive.AlreadyExists
  343. Archive {} already exists
  344. Archive.DoesNotExist
  345. Archive {} does not exist
  346. Archive.IncompatibleFilesystemEncodingError
  347. Failed to encode filename "{}" into file system encoding "{}". Consider configuring the LANG environment variable.
  348. Cache.CacheInitAbortedError
  349. Cache initialization aborted
  350. Cache.EncryptionMethodMismatch
  351. Repository encryption method changed since last access, refusing to continue
  352. Cache.RepositoryAccessAborted
  353. Repository access aborted
  354. Cache.RepositoryIDNotUnique
  355. Cache is newer than repository - do you have multiple, independently updated repos with same ID?
  356. Cache.RepositoryReplay
  357. Cache is newer than repository - this is either an attack or unsafe (multiple repos with same ID)
  358. Buffer.MemoryLimitExceeded
  359. Requested buffer size {} is above the limit of {}.
  360. ExtensionModuleError
  361. The Borg binary extension modules do not seem to be properly installed
  362. IntegrityError
  363. Data integrity error: {}
  364. NoManifestError
  365. Repository has no manifest.
  366. PlaceholderError
  367. Formatting Error: "{}".format({}): {}({})
  368. KeyfileInvalidError
  369. Invalid key file for repository {} found in {}.
  370. KeyfileMismatchError
  371. Mismatch between repository {} and key file {}.
  372. KeyfileNotFoundError
  373. No key file for repository {} found in {}.
  374. PassphraseWrong
  375. passphrase supplied in BORG_PASSPHRASE is incorrect
  376. PasswordRetriesExceeded
  377. exceeded the maximum password retries
  378. RepoKeyNotFoundError
  379. No key entry found in the config of repository {}.
  380. UnsupportedManifestError
  381. Unsupported manifest envelope. A newer version is required to access this repository.
  382. UnsupportedPayloadError
  383. Unsupported payload type {}. A newer version is required to access this repository.
  384. NotABorgKeyFile
  385. This file is not a borg key backup, aborting.
  386. RepoIdMismatch
  387. This key backup seems to be for a different backup repository, aborting.
  388. UnencryptedRepo
  389. Keymanagement not available for unencrypted repositories.
  390. UnknownKeyType
  391. Keytype {0} is unknown.
  392. LockError
  393. Failed to acquire the lock {}.
  394. LockErrorT
  395. Failed to acquire the lock {}.
  396. ConnectionClosed
  397. Connection closed by remote host
  398. InvalidRPCMethod
  399. RPC method {} is not valid
  400. PathNotAllowed
  401. Repository path not allowed
  402. RemoteRepository.RPCServerOutdated
  403. Borg server is too old for {}. Required version {}
  404. UnexpectedRPCDataFormatFromClient
  405. Borg {}: Got unexpected RPC data format from client.
  406. UnexpectedRPCDataFormatFromServer
  407. Got unexpected RPC data format from server:
  408. {}
  409. Repository.AlreadyExists
  410. Repository {} already exists.
  411. Repository.CheckNeeded
  412. Inconsistency detected. Please run "borg check {}".
  413. Repository.DoesNotExist
  414. Repository {} does not exist.
  415. Repository.InsufficientFreeSpaceError
  416. Insufficient free space to complete transaction (required: {}, available: {}).
  417. Repository.InvalidRepository
  418. {} is not a valid repository. Check repo config.
  419. Repository.AtticRepository
  420. Attic repository detected. Please run "borg upgrade {}".
  421. Repository.ObjectNotFound
  422. Object with key {} not found in repository {}.
  423. Operations
  424. - cache.begin_transaction
  425. - cache.download_chunks, appears with ``borg create --no-cache-sync``
  426. - cache.commit
  427. - cache.sync
  428. *info* is one string element, the name of the archive currently synced.
  429. - repository.compact_segments
  430. - repository.replay_segments
  431. - repository.check_segments
  432. - check.verify_data
  433. - extract
  434. *info* is one string element, the name of the path currently extracted.
  435. - extract.permissions
  436. - archive.delete
  437. Prompts
  438. BORG_UNKNOWN_UNENCRYPTED_REPO_ACCESS_IS_OK
  439. For "Warning: Attempting to access a previously unknown unencrypted repository"
  440. BORG_RELOCATED_REPO_ACCESS_IS_OK
  441. For "Warning: The repository at location ... was previously located at ..."
  442. BORG_CHECK_I_KNOW_WHAT_I_AM_DOING
  443. For "Warning: 'check --repair' is an experimental feature that might result in data loss."
  444. BORG_DELETE_I_KNOW_WHAT_I_AM_DOING
  445. For "You requested to completely DELETE the repository *including* all archives it contains:"
  446. BORG_RECREATE_I_KNOW_WHAT_I_AM_DOING
  447. For "recreate is an experimental feature."