2
0

frontends.rst 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. .. include:: ../global.rst.inc
  2. .. highlight:: none
  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:
  18. archive_progress
  19. Output during operations creating archives (:ref:`borg_create` and :ref:`borg_recreate`).
  20. The following keys exist, each represents the current progress.
  21. original_size
  22. Original size of data processed so far (before compression and deduplication)
  23. compressed_size
  24. Compressed size
  25. deduplicated_size
  26. Deduplicated size
  27. nfiles
  28. Number of (regular) files processed so far
  29. path
  30. Current path
  31. progress_message
  32. A message-based progress information with no concrete progress information, just a message
  33. saying what is currently worked on.
  34. operation
  35. unique, opaque integer ID of the operation
  36. msgid
  37. Message ID of the operation (may be *none*)
  38. finished
  39. boolean indicating whether the operation has finished, only the last object for an *operation*
  40. can have this property set to *true*.
  41. message
  42. current progress message (may be empty/absent)
  43. progress_percent
  44. Absolute progress information with defined end/total and current value.
  45. operation
  46. unique, opaque integer ID of the operation
  47. msgid
  48. Message ID of the operation (may be *none*)
  49. finished
  50. boolean indicating whether the operation has finished, only the last object for an *operation*
  51. can have this property set to *true*.
  52. message
  53. A formatted progress message, this will include the percentage and perhaps other information
  54. current
  55. Current value (always less-or-equal to *total*)
  56. total
  57. Total value
  58. file_status
  59. This is only output by :ref:`borg_create` and :ref:`borg_recreate` if ``--list`` is specified. The usual
  60. rules for the file listing applies, including the ``--filter`` option.
  61. status
  62. Single-character status as for regular list output
  63. path
  64. Path of the file system object
  65. log_message
  66. Any regular log output invokes this type. Regular log options and filtering applies to these as well.
  67. created
  68. Unix timestamp (float)
  69. levelname
  70. Upper-case log level name (also called severity). Defined levels are: DEBUG, INFO, WARNING, ERROR, CRITICAL
  71. name
  72. Name of the emitting entity
  73. message
  74. Formatted log message
  75. Standard output
  76. ---------------
  77. *stdout* is different and more command-dependent. Commands like :ref:`borg_info`, :ref:`borg_create`
  78. and :ref:`borg_list` implement a ``--json`` option which turns their regular output into a single JSON object.
  79. Dates are formatted according to ISO-8601 with the strftime format string '%a, %Y-%m-%d %H:%M:%S',
  80. e.g. *Sat, 2016-02-25 23:50:06*.
  81. The root object at least contains a *repository* key with an object containing:
  82. id
  83. The ID of the repository, normally 64 hex characters
  84. location
  85. Canonicalized repository path, thus this may be different from what is specified on the command line
  86. last_modified
  87. Date when the repository was last modified by the Borg client
  88. The *encryption* key, if present, contains:
  89. mode
  90. Textual encryption mode name (same as :ref:`borg_init` ``--encryption`` names)
  91. keyfile
  92. Path to the local key file used for access. Depending on *mode* this key may be absent.
  93. The *cache* key, if present, contains:
  94. path
  95. Path to the local repository cache
  96. stats
  97. Object containing cache stats:
  98. total_chunks
  99. Number of chunks
  100. total_unique_chunks
  101. Number of unique chunks
  102. total_size
  103. Total uncompressed size of all chunks multiplied with their reference counts
  104. total_csize
  105. Total compressed and encrypted size of all chunks multiplied with their reference counts
  106. unique_size
  107. Uncompressed size of all chunks
  108. unique_csize
  109. Compressed and encrypted size of all chunks
  110. .. rubric:: Archive formats
  111. :ref:`borg_info` uses an extended format for archives, which is more expensive to retrieve, while
  112. :ref:`borg_list` uses a simpler format that is faster to retrieve. Either return archives in an
  113. array under the *archives* key, while :ref:`borg_create` returns a single archive object under the
  114. *archive* key.
  115. Both formats contain a *name* key with the archive name, and the *id* key with the hexadecimal archive ID.
  116. info and create further have:
  117. start
  118. Start timestamp
  119. end
  120. End timestamp
  121. duration
  122. Duration in seconds between start and end in seconds (float)
  123. stats
  124. Archive statistics (freshly calculated, this is what makes "info" more expensive)
  125. original_size
  126. Size of files and metadata before compression
  127. compressed_size
  128. Size after compression
  129. deduplicated_size
  130. Deduplicated size (against the current repository, not when the archive was created)
  131. nfiles
  132. Number of regular files in the archive
  133. limits
  134. Object describing the utilization of Borg limits
  135. max_archive_size
  136. Float between 0 and 1 describing how large this archive is relative to the maximum size allowed by Borg
  137. command_line
  138. Array of strings of the command line that created the archive
  139. The note about paths from above applies here as well.
  140. :ref:`borg_info` further has:
  141. hostname
  142. Hostname of the creating host
  143. username
  144. Name of the creating user
  145. comment
  146. Archive comment, if any
  147. .. rubric:: File listings
  148. Listing the contents of an archive can produce *a lot* of JSON. Each item (file, directory, ...) is described
  149. by one object in the *files* array of the :ref:`borg_list` output. Refer to the *borg list* documentation for
  150. the available keys and their meaning.