frontends.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. file_status
  32. This is only output by :ref:`borg_create` and :ref:`borg_recreate` if ``--list`` is specified. The usual
  33. rules for the file listing applies, including the ``--filter`` option.
  34. status
  35. Single-character status as for regular list output
  36. path
  37. Path of the file system object
  38. log_message
  39. Any regular log output invokes this type. Regular log options and filtering applies to these as well.
  40. created
  41. Unix timestamp (float)
  42. levelname
  43. Upper-case log level name (also called severity). Defined levels are: DEBUG, INFO, WARNING, CRITICAL
  44. name
  45. Name of the emitting entity
  46. message
  47. Formatted log message
  48. Standard output
  49. ---------------
  50. *stdout* is different and more command-dependent. Commands like :ref:`borg_info`, :ref:`borg_create`
  51. and :ref:`borg_list` implement a ``--json`` option which turns their regular output into a single JSON object.
  52. Dates are formatted according to ISO-8601 with the strftime format string '%a, %Y-%m-%d %H:%M:%S',
  53. e.g. *Sat, 2016-02-25 23:50:06*.
  54. The root object at least contains a *repository* key with an object containing:
  55. id
  56. The ID of the repository, normally 64 hex characters
  57. location
  58. Canonicalized repository path, thus this may be different from what is specified on the command line
  59. last_modified
  60. Date when the repository was last modified by the Borg client
  61. The *encryption* key, if present, contains:
  62. mode
  63. Textual encryption mode name (same as :ref:`borg_init` ``--encryption`` names)
  64. keyfile
  65. Path to the local key file used for access. Depending on *mode* this key may be absent.
  66. The *cache* key, if present, contains:
  67. path
  68. Path to the local repository cache
  69. stats
  70. Object containing cache stats:
  71. total_chunks
  72. Number of chunks
  73. total_unique_chunks
  74. Number of unique chunks
  75. total_size
  76. Total uncompressed size of all chunks multiplied with their reference counts
  77. total_csize
  78. Total compressed and encrypted size of all chunks multiplied with their reference counts
  79. unique_size
  80. Uncompressed size of all chunks
  81. unique_csize
  82. Compressed and encrypted size of all chunks
  83. .. rubric:: Archive formats
  84. :ref:`borg_info` uses an extended format for archives, which is more expensive to retrieve, while
  85. :ref:`borg_list` uses a simpler format that is faster to retrieve. Either return archives in an
  86. array under the *archives* key, while :ref:`borg_create` returns a single archive object under the
  87. *archive* key.
  88. Both formats contain a *name* key with the archive name, and the *id* key with the hexadecimal archive ID.
  89. info and create further have:
  90. start
  91. Start timestamp
  92. end
  93. End timestamp
  94. duration
  95. Duration in seconds between start and end in seconds (float)
  96. stats
  97. Archive statistics (freshly calculated, this is what makes "info" more expensive)
  98. original_size
  99. Size of files and metadata before compression
  100. compressed_size
  101. Size after compression
  102. deduplicated_size
  103. Deduplicated size (against the current repository, not when the archive was created)
  104. nfiles
  105. Number of regular files in the archive
  106. limits
  107. Object describing the utilization of Borg limits
  108. max_archive_size
  109. Float between 0 and 1 describing how large this archive is relative to the maximum size allowed by Borg
  110. command_line
  111. Array of strings of the command line that created the archive
  112. The note about paths from above applies here as well.
  113. :ref:`borg_info` further has:
  114. hostname
  115. Hostname of the creating host
  116. username
  117. Name of the creating user
  118. comment
  119. Archive comment, if any
  120. .. rubric:: File listings
  121. Listing the contents of an archive can produce *a lot* of JSON. Each item (file, directory, ...) is described
  122. by one object in the *files* array of the :ref:`borg_list` output. Refer to the *borg list* documentation for
  123. the available keys and their meaning.