bitmaps.rst 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629
  1. ..
  2. Copyright 2019 John Snow <jsnow@redhat.com> and Red Hat, Inc.
  3. All rights reserved.
  4. This file is licensed via The FreeBSD Documentation License, the full
  5. text of which is included at the end of this document.
  6. ====================================
  7. Dirty Bitmaps and Incremental Backup
  8. ====================================
  9. Dirty Bitmaps are in-memory objects that track writes to block devices. They
  10. can be used in conjunction with various block job operations to perform
  11. incremental or differential backup regimens.
  12. This document explains the conceptual mechanisms, as well as up-to-date,
  13. complete and comprehensive documentation on the API to manipulate them.
  14. (Hopefully, the "why", "what", and "how".)
  15. The intended audience for this document is developers who are adding QEMU
  16. backup features to management applications, or power users who run and
  17. administer QEMU directly via QMP.
  18. .. contents::
  19. Overview
  20. --------
  21. Bitmaps are bit vectors where each '1' bit in the vector indicates a modified
  22. ("dirty") segment of the corresponding block device. The size of the segment
  23. that is tracked is the granularity of the bitmap. If the granularity of a
  24. bitmap is 64K, each '1' bit means that a 64K region as a whole may have
  25. changed in some way, possibly by as little as one byte.
  26. Smaller granularities mean more accurate tracking of modified disk data, but
  27. requires more computational overhead and larger bitmap sizes. Larger
  28. granularities mean smaller bitmap sizes, but less targeted backups.
  29. The size of a bitmap (in bytes) can be computed as such:
  30. ``size`` = ceil(ceil(``image_size`` / ``granularity``) / 8)
  31. e.g. the size of a 64KiB granularity bitmap on a 2TiB image is:
  32. ``size`` = ((2147483648K / 64K) / 8)
  33. = 4194304B = 4MiB.
  34. QEMU uses these bitmaps when making incremental backups to know which sections
  35. of the file to copy out. They are not enabled by default and must be
  36. explicitly added in order to begin tracking writes.
  37. Bitmaps can be created at any time and can be attached to any arbitrary block
  38. node in the storage graph, but are most useful conceptually when attached to
  39. the root node attached to the guest's storage device model.
  40. That is to say: It's likely most useful to track the guest's writes to disk,
  41. but you could theoretically track things like qcow2 metadata changes by
  42. attaching the bitmap elsewhere in the storage graph. This is beyond the scope
  43. of this document.
  44. QEMU supports persisting these bitmaps to disk via the qcow2 image format.
  45. Bitmaps which are stored or loaded in this way are called "persistent",
  46. whereas bitmaps that are not are called "transient".
  47. QEMU also supports the migration of both transient bitmaps (tracking any
  48. arbitrary image format) or persistent bitmaps (qcow2) via live migration.
  49. Supported Image Formats
  50. -----------------------
  51. QEMU supports all documented features below on the qcow2 image format.
  52. However, qcow2 is only strictly necessary for the persistence feature, which
  53. writes bitmap data to disk upon close. If persistence is not required for a
  54. specific use case, all bitmap features excepting persistence are available for
  55. any arbitrary image format.
  56. For example, Dirty Bitmaps can be combined with the 'raw' image format, but
  57. any changes to the bitmap will be discarded upon exit.
  58. .. warning:: Transient bitmaps will not be saved on QEMU exit! Persistent
  59. bitmaps are available only on qcow2 images.
  60. Dirty Bitmap Names
  61. ------------------
  62. Bitmap objects need a method to reference them in the API. All API-created and
  63. managed bitmaps have a human-readable name chosen by the user at creation
  64. time.
  65. - A bitmap's name is unique to the node, but bitmaps attached to different
  66. nodes can share the same name. Therefore, all bitmaps are addressed via
  67. their (node, name) pair.
  68. - The name of a user-created bitmap cannot be empty ("").
  69. - Transient bitmaps can have JSON unicode names that are effectively not
  70. length limited. (QMP protocol may restrict messages to less than 64MiB.)
  71. - Persistent storage formats may impose their own requirements on bitmap names
  72. and namespaces. Presently, only qcow2 supports persistent bitmaps. See
  73. docs/interop/qcow2.txt for more details on restrictions. Notably:
  74. - qcow2 bitmap names are limited to between 1 and 1023 bytes long.
  75. - No two bitmaps saved to the same qcow2 file may share the same name.
  76. - QEMU occasionally uses bitmaps for internal use which have no name. They are
  77. hidden from API query calls, cannot be manipulated by the external API, are
  78. never persistent, nor ever migrated.
  79. Bitmap Status
  80. -------------
  81. Dirty Bitmap objects can be queried with the QMP command `query-block
  82. <qemu-qmp-ref.html#index-query_002dblock>`_, and are visible via the
  83. `BlockDirtyInfo <qemu-qmp-ref.html#index-BlockDirtyInfo>`_ QAPI structure.
  84. This struct shows the name, granularity, and dirty byte count for each bitmap.
  85. Additionally, it shows several boolean status indicators:
  86. - ``recording``: This bitmap is recording writes.
  87. - ``busy``: This bitmap is in-use by an operation.
  88. - ``persistent``: This bitmap is a persistent type.
  89. - ``inconsistent``: This bitmap is corrupted and cannot be used.
  90. The ``+busy`` status prohibits you from deleting, clearing, or otherwise
  91. modifying a bitmap, and happens when the bitmap is being used for a backup
  92. operation or is in the process of being loaded from a migration. Many of the
  93. commands documented below will refuse to work on such bitmaps.
  94. The ``+inconsistent`` status similarly prohibits almost all operations,
  95. notably allowing only the ``block-dirty-bitmap-remove`` operation.
  96. There is also a deprecated ``status`` field of type `DirtyBitmapStatus
  97. <qemu-qmp-ref.html#index-DirtyBitmapStatus>`_. A bitmap historically had
  98. five visible states:
  99. #. ``Frozen``: This bitmap is currently in-use by an operation and is
  100. immutable. It can't be deleted, renamed, reset, etc.
  101. (This is now ``+busy``.)
  102. #. ``Disabled``: This bitmap is not recording new writes.
  103. (This is now ``-recording -busy``.)
  104. #. ``Active``: This bitmap is recording new writes.
  105. (This is now ``+recording -busy``.)
  106. #. ``Locked``: This bitmap is in-use by an operation, and is immutable.
  107. The difference from "Frozen" was primarily implementation details.
  108. (This is now ``+busy``.)
  109. #. ``Inconsistent``: This persistent bitmap was not saved to disk
  110. correctly, and can no longer be used. It remains in memory to serve as
  111. an indicator of failure.
  112. (This is now ``+inconsistent``.)
  113. These states are directly replaced by the status indicators and should not be
  114. used. The difference between ``Frozen`` and ``Locked`` is an implementation
  115. detail and should not be relevant to external users.
  116. Basic QMP Usage
  117. ---------------
  118. The primary interface to manipulating bitmap objects is via the QMP
  119. interface. If you are not familiar, see the :doc:`qmp-spec` for the
  120. protocol, and :doc:`qemu-qmp-ref` for a full reference of all QMP
  121. commands.
  122. Supported Commands
  123. ~~~~~~~~~~~~~~~~~~
  124. There are six primary bitmap-management API commands:
  125. - ``block-dirty-bitmap-add``
  126. - ``block-dirty-bitmap-remove``
  127. - ``block-dirty-bitmap-clear``
  128. - ``block-dirty-bitmap-disable``
  129. - ``block-dirty-bitmap-enable``
  130. - ``block-dirty-bitmap-merge``
  131. And one related query command:
  132. - ``query-block``
  133. Creation: block-dirty-bitmap-add
  134. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  135. `block-dirty-bitmap-add
  136. <qemu-qmp-ref.html#index-block_002ddirty_002dbitmap_002dadd>`_:
  137. Creates a new bitmap that tracks writes to the specified node. granularity,
  138. persistence, and recording state can be adjusted at creation time.
  139. .. admonition:: Example
  140. to create a new, actively recording persistent bitmap:
  141. .. code-block:: QMP
  142. -> { "execute": "block-dirty-bitmap-add",
  143. "arguments": {
  144. "node": "drive0",
  145. "name": "bitmap0",
  146. "persistent": true,
  147. }
  148. }
  149. <- { "return": {} }
  150. - This bitmap will have a default granularity that matches the cluster size of
  151. its associated drive, if available, clamped to between [4KiB, 64KiB]. The
  152. current default for qcow2 is 64KiB.
  153. .. admonition:: Example
  154. To create a new, disabled (``-recording``), transient bitmap that tracks
  155. changes in 32KiB segments:
  156. .. code-block:: QMP
  157. -> { "execute": "block-dirty-bitmap-add",
  158. "arguments": {
  159. "node": "drive0",
  160. "name": "bitmap1",
  161. "granularity": 32768,
  162. "disabled": true
  163. }
  164. }
  165. <- { "return": {} }
  166. Deletion: block-dirty-bitmap-remove
  167. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168. `block-dirty-bitmap-remove
  169. <qemu-qmp-ref.html#index-block_002ddirty_002dbitmap_002dremove>`_:
  170. Deletes a bitmap. Bitmaps that are ``+busy`` cannot be removed.
  171. - Deleting a bitmap does not impact any other bitmaps attached to the same
  172. node, nor does it affect any backups already created from this bitmap or
  173. node.
  174. - Because bitmaps are only unique to the node to which they are attached, you
  175. must specify the node/drive name here, too.
  176. - Deleting a persistent bitmap will remove it from the qcow2 file.
  177. .. admonition:: Example
  178. Remove a bitmap named ``bitmap0`` from node ``drive0``:
  179. .. code-block:: QMP
  180. -> { "execute": "block-dirty-bitmap-remove",
  181. "arguments": {
  182. "node": "drive0",
  183. "name": "bitmap0"
  184. }
  185. }
  186. <- { "return": {} }
  187. Resetting: block-dirty-bitmap-clear
  188. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  189. `block-dirty-bitmap-clear
  190. <qemu-qmp-ref.html#index-block_002ddirty_002dbitmap_002dclear>`_:
  191. Clears all dirty bits from a bitmap. ``+busy`` bitmaps cannot be cleared.
  192. - An incremental backup created from an empty bitmap will copy no data, as if
  193. nothing has changed.
  194. .. admonition:: Example
  195. Clear all dirty bits from bitmap ``bitmap0`` on node ``drive0``:
  196. .. code-block:: QMP
  197. -> { "execute": "block-dirty-bitmap-clear",
  198. "arguments": {
  199. "node": "drive0",
  200. "name": "bitmap0"
  201. }
  202. }
  203. <- { "return": {} }
  204. Enabling: block-dirty-bitmap-enable
  205. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  206. `block-dirty-bitmap-enable
  207. <qemu-qmp-ref.html#index-block_002ddirty_002dbitmap_002denable>`_:
  208. "Enables" a bitmap, setting the ``recording`` bit to true, causing writes to
  209. begin being recorded. ``+busy`` bitmaps cannot be enabled.
  210. - Bitmaps default to being enabled when created, unless configured otherwise.
  211. - Persistent enabled bitmaps will remember their ``+recording`` status on
  212. load.
  213. .. admonition:: Example
  214. To set ``+recording`` on bitmap ``bitmap0`` on node ``drive0``:
  215. .. code-block:: QMP
  216. -> { "execute": "block-dirty-bitmap-enable",
  217. "arguments": {
  218. "node": "drive0",
  219. "name": "bitmap0"
  220. }
  221. }
  222. <- { "return": {} }
  223. Enabling: block-dirty-bitmap-disable
  224. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  225. `block-dirty-bitmap-disable
  226. <qemu-qmp-ref.html#index-block_002ddirty_002dbitmap_002ddisable>`_:
  227. "Disables" a bitmap, setting the ``recording`` bit to false, causing further
  228. writes to begin being ignored. ``+busy`` bitmaps cannot be disabled.
  229. .. warning::
  230. This is potentially dangerous: QEMU makes no effort to stop any writes if
  231. there are disabled bitmaps on a node, and will not mark any disabled bitmaps
  232. as ``+inconsistent`` if any such writes do happen. Backups made from such
  233. bitmaps will not be able to be used to reconstruct a coherent image.
  234. - Disabling a bitmap may be useful for examining which sectors of a disk
  235. changed during a specific time period, or for explicit management of
  236. differential backup windows.
  237. - Persistent disabled bitmaps will remember their ``-recording`` status on
  238. load.
  239. .. admonition:: Example
  240. To set ``-recording`` on bitmap ``bitmap0`` on node ``drive0``:
  241. .. code-block:: QMP
  242. -> { "execute": "block-dirty-bitmap-disable",
  243. "arguments": {
  244. "node": "drive0",
  245. "name": "bitmap0"
  246. }
  247. }
  248. <- { "return": {} }
  249. Merging, Copying: block-dirty-bitmap-merge
  250. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  251. `block-dirty-bitmap-merge
  252. <qemu-qmp-ref.html#index-block_002ddirty_002dbitmap_002dmerge>`_:
  253. Merges one or more bitmaps into a target bitmap. For any segment that is dirty
  254. in any one source bitmap, the target bitmap will mark that segment dirty.
  255. - Merge takes one or more bitmaps as a source and merges them together into a
  256. single destination, such that any segment marked as dirty in any source
  257. bitmap(s) will be marked dirty in the destination bitmap.
  258. - Merge does not create the destination bitmap if it does not exist. A blank
  259. bitmap can be created beforehand to achieve the same effect.
  260. - The destination is not cleared prior to merge, so subsequent merge
  261. operations will continue to cumulatively mark more segments as dirty.
  262. - If the merge operation should fail, the destination bitmap is guaranteed to
  263. be unmodified. The operation may fail if the source or destination bitmaps
  264. are busy, or have different granularities.
  265. - Bitmaps can only be merged on the same node. There is only one "node"
  266. argument, so all bitmaps must be attached to that same node.
  267. - Copy can be achieved by merging from a single source to an empty
  268. destination.
  269. .. admonition:: Example
  270. Merge the data from ``bitmap0`` into the bitmap ``new_bitmap`` on node
  271. ``drive0``. If ``new_bitmap`` was empty prior to this command, this achieves
  272. a copy.
  273. .. code-block:: QMP
  274. -> { "execute": "block-dirty-bitmap-merge",
  275. "arguments": {
  276. "node": "drive0",
  277. "target": "new_bitmap",
  278. "bitmaps": [ "bitmap0" ]
  279. }
  280. }
  281. <- { "return": {} }
  282. Querying: query-block
  283. ~~~~~~~~~~~~~~~~~~~~~
  284. `query-block
  285. <qemu-qmp-ref.html#index-query_002dblock>`_:
  286. Not strictly a bitmaps command, but will return information about any bitmaps
  287. attached to nodes serving as the root for guest devices.
  288. - The "inconsistent" bit will not appear when it is false, appearing only when
  289. the value is true to indicate there is a problem.
  290. .. admonition:: Example
  291. Query the block sub-system of QEMU. The following json has trimmed irrelevant
  292. keys from the response to highlight only the bitmap-relevant portions of the
  293. API. This result highlights a bitmap ``bitmap0`` attached to the root node of
  294. device ``drive0``.
  295. .. code-block:: QMP
  296. -> {
  297. "execute": "query-block",
  298. "arguments": {}
  299. }
  300. <- {
  301. "return": [ {
  302. "dirty-bitmaps": [ {
  303. "status": "active",
  304. "count": 0,
  305. "busy": false,
  306. "name": "bitmap0",
  307. "persistent": false,
  308. "recording": true,
  309. "granularity": 65536
  310. } ],
  311. "device": "drive0",
  312. } ]
  313. }
  314. Bitmap Persistence
  315. ------------------
  316. As outlined in `Supported Image Formats`_, QEMU can persist bitmaps to qcow2
  317. files. Demonstrated in `Creation: block-dirty-bitmap-add`_, passing
  318. ``persistent: true`` to ``block-dirty-bitmap-add`` will persist that bitmap to
  319. disk.
  320. Persistent bitmaps will be automatically loaded into memory upon load, and
  321. will be written back to disk upon close. Their usage should be mostly
  322. transparent.
  323. However, if QEMU does not get a chance to close the file cleanly, the bitmap
  324. will be marked as ``+inconsistent`` at next load and considered unsafe to use
  325. for any operation. At this point, the only valid operation on such bitmaps is
  326. ``block-dirty-bitmap-remove``.
  327. Losing a bitmap in this way does not invalidate any existing backups that have
  328. been made from this bitmap, but no further backups will be able to be issued
  329. for this chain.
  330. Transactions
  331. ------------
  332. Transactions are a QMP feature that allows you to submit multiple QMP commands
  333. at once, being guaranteed that they will all succeed or fail atomically,
  334. together. The interaction of bitmaps and transactions are demonstrated below.
  335. See `transaction <qemu-qmp.ref.html#index-transaction>`_ in the QMP reference
  336. for more details.
  337. Justification
  338. ~~~~~~~~~~~~~
  339. Bitmaps can generally be modified at any time, but certain operations often
  340. only make sense when paired directly with other commands. When a VM is paused,
  341. it's easy to ensure that no guest writes occur between individual QMP
  342. commands. When a VM is running, this is difficult to accomplish with
  343. individual QMP commands that may allow guest writes to occur between each
  344. command.
  345. For example, using only individual QMP commands, we could:
  346. #. Boot the VM in a paused state.
  347. #. Create a full drive backup of drive0.
  348. #. Create a new bitmap attached to drive0, confident that nothing has been
  349. written to drive0 in the meantime.
  350. #. Resume execution of the VM.
  351. #. At a later point, issue incremental backups from ``bitmap0``.
  352. At this point, the bitmap and drive backup would be correctly in sync, and
  353. incremental backups made from this point forward would be correctly aligned to
  354. the full drive backup.
  355. This is not particularly useful if we decide we want to start incremental
  356. backups after the VM has been running for a while, for which we would want to
  357. perform actions such as the following:
  358. #. Boot the VM and begin execution.
  359. #. Using a single transaction, perform the following operations:
  360. - Create ``bitmap0``.
  361. - Create a full drive backup of ``drive0``.
  362. #. At a later point, issue incremental backups from ``bitmap0``.
  363. .. note:: As a consideration, if ``bitmap0`` is created prior to the full
  364. drive backup, incremental backups can still be authored from this
  365. bitmap, but they will copy extra segments reflecting writes that
  366. occurred prior to the backup operation. Transactions allow us to
  367. narrow critical points in time to reduce waste, or, in the other
  368. direction, to ensure that no segments are omitted.
  369. Supported Bitmap Transactions
  370. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  371. - ``block-dirty-bitmap-add``
  372. - ``block-dirty-bitmap-clear``
  373. - ``block-dirty-bitmap-enable``
  374. - ``block-dirty-bitmap-disable``
  375. - ``block-dirty-bitmap-merge``
  376. The usages for these commands are identical to their respective QMP commands,
  377. but see the sections below for concrete examples.
  378. Incremental Backups - Push Model
  379. --------------------------------
  380. Incremental backups are simply partial disk images that can be combined with
  381. other partial disk images on top of a base image to reconstruct a full backup
  382. from the point in time at which the incremental backup was issued.
  383. The "Push Model" here references the fact that QEMU is "pushing" the modified
  384. blocks out to a destination. We will be using the `blockdev-backup
  385. <qemu-qmp-ref.html#index-blockdev_002dbackup>`_ QMP command to create both
  386. full and incremental backups.
  387. The command is a background job, which has its own QMP API for querying and
  388. management documented in `Background jobs
  389. <qemu-qmp-ref.html#Background-jobs>`_.
  390. Example: New Incremental Backup Anchor Point
  391. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  392. As outlined in the Transactions - `Justification`_ section, perhaps we want to
  393. create a new incremental backup chain attached to a drive.
  394. This example creates a new, full backup of "drive0" and accompanies it with a
  395. new, empty bitmap that records writes from this point in time forward.
  396. The target can be created with the help of `blockdev-add
  397. <qemu-qmp-ref.html#index-blockdev_002dadd>`_ or `blockdev-create
  398. <qemu-qmp-ref.html#index-blockdev_002dcreate>`_ command.
  399. .. note:: Any new writes that happen after this command is issued, even while
  400. the backup job runs, will be written locally and not to the backup
  401. destination. These writes will be recorded in the bitmap
  402. accordingly.
  403. .. code-block:: QMP
  404. -> {
  405. "execute": "transaction",
  406. "arguments": {
  407. "actions": [
  408. {
  409. "type": "block-dirty-bitmap-add",
  410. "data": {
  411. "node": "drive0",
  412. "name": "bitmap0"
  413. }
  414. },
  415. {
  416. "type": "blockdev-backup",
  417. "data": {
  418. "device": "drive0",
  419. "target": "target0",
  420. "sync": "full"
  421. }
  422. }
  423. ]
  424. }
  425. }
  426. <- { "return": {} }
  427. <- {
  428. "timestamp": {
  429. "seconds": 1555436945,
  430. "microseconds": 179620
  431. },
  432. "data": {
  433. "status": "created",
  434. "id": "drive0"
  435. },
  436. "event": "JOB_STATUS_CHANGE"
  437. }
  438. ...
  439. <- {
  440. "timestamp": {...},
  441. "data": {
  442. "device": "drive0",
  443. "type": "backup",
  444. "speed": 0,
  445. "len": 68719476736,
  446. "offset": 68719476736
  447. },
  448. "event": "BLOCK_JOB_COMPLETED"
  449. }
  450. <- {
  451. "timestamp": {...},
  452. "data": {
  453. "status": "concluded",
  454. "id": "drive0"
  455. },
  456. "event": "JOB_STATUS_CHANGE"
  457. }
  458. <- {
  459. "timestamp": {...},
  460. "data": {
  461. "status": "null",
  462. "id": "drive0"
  463. },
  464. "event": "JOB_STATUS_CHANGE"
  465. }
  466. A full explanation of the job transition semantics and the JOB_STATUS_CHANGE
  467. event are beyond the scope of this document and will be omitted in all
  468. subsequent examples; above, several more events have been omitted for brevity.
  469. .. note:: Subsequent examples will omit all events except BLOCK_JOB_COMPLETED
  470. except where necessary to illustrate workflow differences.
  471. Omitted events and json objects will be represented by ellipses:
  472. ``...``
  473. Example: Resetting an Incremental Backup Anchor Point
  474. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  475. If we want to start a new backup chain with an existing bitmap, we can also
  476. use a transaction to reset the bitmap while making a new full backup:
  477. .. code-block:: QMP
  478. -> {
  479. "execute": "transaction",
  480. "arguments": {
  481. "actions": [
  482. {
  483. "type": "block-dirty-bitmap-clear",
  484. "data": {
  485. "node": "drive0",
  486. "name": "bitmap0"
  487. }
  488. },
  489. {
  490. "type": "blockdev-backup",
  491. "data": {
  492. "device": "drive0",
  493. "target": "target0",
  494. "sync": "full"
  495. }
  496. }
  497. ]
  498. }
  499. }
  500. <- { "return": {} }
  501. ...
  502. <- {
  503. "timestamp": {...},
  504. "data": {
  505. "device": "drive0",
  506. "type": "backup",
  507. "speed": 0,
  508. "len": 68719476736,
  509. "offset": 68719476736
  510. },
  511. "event": "BLOCK_JOB_COMPLETED"
  512. }
  513. ...
  514. The result of this example is identical to the first, but we clear an existing
  515. bitmap instead of adding a new one.
  516. .. tip:: In both of these examples, "bitmap0" is tied conceptually to the
  517. creation of new, full backups. This relationship is not saved or
  518. remembered by QEMU; it is up to the operator or management layer to
  519. remember which bitmaps are associated with which backups.
  520. Example: First Incremental Backup
  521. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  522. #. Create a full backup and sync it to a dirty bitmap using any method:
  523. - Either of the two live backup method demonstrated above,
  524. - Using QMP commands with the VM paused as in the `Justification`_ section,
  525. or
  526. - With the VM offline, manually copy the image and start the VM in a paused
  527. state, careful to add a new bitmap before the VM begins execution.
  528. Whichever method is chosen, let's assume that at the end of this step:
  529. - The full backup is named ``drive0.full.qcow2``.
  530. - The bitmap we created is named ``bitmap0``, attached to ``drive0``.
  531. #. Create a destination image for the incremental backup that utilizes the
  532. full backup as a backing image.
  533. - Let's assume the new incremental image is named ``drive0.inc0.qcow2``:
  534. .. code:: bash
  535. $ qemu-img create -f qcow2 drive0.inc0.qcow2 \
  536. -b drive0.full.qcow2 -F qcow2
  537. #. Add target block node:
  538. .. code-block:: QMP
  539. -> {
  540. "execute": "blockdev-add",
  541. "arguments": {
  542. "node-name": "target0",
  543. "driver": "qcow2",
  544. "file": {
  545. "driver": "file",
  546. "filename": "drive0.inc0.qcow2"
  547. }
  548. }
  549. }
  550. <- { "return": {} }
  551. #. Issue an incremental backup command:
  552. .. code-block:: QMP
  553. -> {
  554. "execute": "blockdev-backup",
  555. "arguments": {
  556. "device": "drive0",
  557. "bitmap": "bitmap0",
  558. "target": "target0",
  559. "sync": "incremental"
  560. }
  561. }
  562. <- { "return": {} }
  563. ...
  564. <- {
  565. "timestamp": {...},
  566. "data": {
  567. "device": "drive0",
  568. "type": "backup",
  569. "speed": 0,
  570. "len": 68719476736,
  571. "offset": 68719476736
  572. },
  573. "event": "BLOCK_JOB_COMPLETED"
  574. }
  575. ...
  576. This copies any blocks modified since the full backup was created into the
  577. ``drive0.inc0.qcow2`` file. During the operation, ``bitmap0`` is marked
  578. ``+busy``. If the operation is successful, ``bitmap0`` will be cleared to
  579. reflect the "incremental" backup regimen, which only copies out new changes
  580. from each incremental backup.
  581. .. note:: Any new writes that occur after the backup operation starts do not
  582. get copied to the destination. The backup's "point in time" is when
  583. the backup starts, not when it ends. These writes are recorded in a
  584. special bitmap that gets re-added to bitmap0 when the backup ends so
  585. that the next incremental backup can copy them out.
  586. Example: Second Incremental Backup
  587. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  588. #. Create a new destination image for the incremental backup that points to
  589. the previous one, e.g.: ``drive0.inc1.qcow2``
  590. .. code:: bash
  591. $ qemu-img create -f qcow2 drive0.inc1.qcow2 \
  592. -b drive0.inc0.qcow2 -F qcow2
  593. #. Add target block node:
  594. .. code-block:: QMP
  595. -> {
  596. "execute": "blockdev-add",
  597. "arguments": {
  598. "node-name": "target0",
  599. "driver": "qcow2",
  600. "file": {
  601. "driver": "file",
  602. "filename": "drive0.inc1.qcow2"
  603. }
  604. }
  605. }
  606. <- { "return": {} }
  607. #. Issue a new incremental backup command. The only difference here is that we
  608. have changed the target image below.
  609. .. code-block:: QMP
  610. -> {
  611. "execute": "blockdev-backup",
  612. "arguments": {
  613. "device": "drive0",
  614. "bitmap": "bitmap0",
  615. "target": "target0",
  616. "sync": "incremental"
  617. }
  618. }
  619. <- { "return": {} }
  620. ...
  621. <- {
  622. "timestamp": {...},
  623. "data": {
  624. "device": "drive0",
  625. "type": "backup",
  626. "speed": 0,
  627. "len": 68719476736,
  628. "offset": 68719476736
  629. },
  630. "event": "BLOCK_JOB_COMPLETED"
  631. }
  632. ...
  633. Because the first incremental backup from the previous example completed
  634. successfully, ``bitmap0`` was synchronized with ``drive0.inc0.qcow2``. Here,
  635. we use ``bitmap0`` again to create a new incremental backup that targets the
  636. previous one, creating a chain of three images:
  637. .. admonition:: Diagram
  638. .. code:: text
  639. +-------------------+ +-------------------+ +-------------------+
  640. | drive0.full.qcow2 |<--| drive0.inc0.qcow2 |<--| drive0.inc1.qcow2 |
  641. +-------------------+ +-------------------+ +-------------------+
  642. Each new incremental backup re-synchronizes the bitmap to the latest backup
  643. authored, allowing a user to continue to "consume" it to create new backups on
  644. top of an existing chain.
  645. In the above diagram, neither drive0.inc1.qcow2 nor drive0.inc0.qcow2 are
  646. complete images by themselves, but rely on their backing chain to reconstruct
  647. a full image. The dependency terminates with each full backup.
  648. Each backup in this chain remains independent, and is unchanged by new entries
  649. made later in the chain. For instance, drive0.inc0.qcow2 remains a perfectly
  650. valid backup of the disk as it was when that backup was issued.
  651. Example: Incremental Push Backups without Backing Files
  652. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  653. Backup images are best kept off-site, so we often will not have the preceding
  654. backups in a chain available to link against. This is not a problem at backup
  655. time; we simply do not set the backing image when creating the destination
  656. image:
  657. #. Create a new destination image with no backing file set. We will need to
  658. specify the size of the base image, because the backing file isn't
  659. available for QEMU to use to determine it.
  660. .. code:: bash
  661. $ qemu-img create -f qcow2 drive0.inc2.qcow2 64G
  662. .. note:: Alternatively, you can omit ``mode: "existing"`` from the push
  663. backup commands to have QEMU create an image without a backing
  664. file for you, but you lose control over format options like
  665. compatibility and preallocation presets.
  666. #. Add target block node:
  667. .. code-block:: QMP
  668. -> {
  669. "execute": "blockdev-add",
  670. "arguments": {
  671. "node-name": "target0",
  672. "driver": "qcow2",
  673. "file": {
  674. "driver": "file",
  675. "filename": "drive0.inc2.qcow2"
  676. }
  677. }
  678. }
  679. <- { "return": {} }
  680. #. Issue a new incremental backup command. Apart from the new destination
  681. image, there is no difference from the last two examples.
  682. .. code-block:: QMP
  683. -> {
  684. "execute": "blockdev-backup",
  685. "arguments": {
  686. "device": "drive0",
  687. "bitmap": "bitmap0",
  688. "target": "target0",
  689. "sync": "incremental"
  690. }
  691. }
  692. <- { "return": {} }
  693. ...
  694. <- {
  695. "timestamp": {...},
  696. "data": {
  697. "device": "drive0",
  698. "type": "backup",
  699. "speed": 0,
  700. "len": 68719476736,
  701. "offset": 68719476736
  702. },
  703. "event": "BLOCK_JOB_COMPLETED"
  704. }
  705. ...
  706. The only difference from the perspective of the user is that you will need to
  707. set the backing image when attempting to restore the backup:
  708. .. code:: bash
  709. $ qemu-img rebase drive0.inc2.qcow2 \
  710. -u -b drive0.inc1.qcow2
  711. This uses the "unsafe" rebase mode to simply set the backing file to a file
  712. that isn't present.
  713. It is also possible to use ``--image-opts`` to specify the entire backing
  714. chain by hand as an ephemeral property at runtime, but that is beyond the
  715. scope of this document.
  716. Example: Multi-drive Incremental Backup
  717. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  718. Assume we have a VM with two drives, "drive0" and "drive1" and we wish to back
  719. both of them up such that the two backups represent the same crash-consistent
  720. point in time.
  721. #. For each drive, create an empty image:
  722. .. code:: bash
  723. $ qemu-img create -f qcow2 drive0.full.qcow2 64G
  724. $ qemu-img create -f qcow2 drive1.full.qcow2 64G
  725. #. Add target block nodes:
  726. .. code-block:: QMP
  727. -> {
  728. "execute": "blockdev-add",
  729. "arguments": {
  730. "node-name": "target0",
  731. "driver": "qcow2",
  732. "file": {
  733. "driver": "file",
  734. "filename": "drive0.full.qcow2"
  735. }
  736. }
  737. }
  738. <- { "return": {} }
  739. -> {
  740. "execute": "blockdev-add",
  741. "arguments": {
  742. "node-name": "target1",
  743. "driver": "qcow2",
  744. "file": {
  745. "driver": "file",
  746. "filename": "drive1.full.qcow2"
  747. }
  748. }
  749. }
  750. <- { "return": {} }
  751. #. Create a full (anchor) backup for each drive, with accompanying bitmaps:
  752. .. code-block:: QMP
  753. -> {
  754. "execute": "transaction",
  755. "arguments": {
  756. "actions": [
  757. {
  758. "type": "block-dirty-bitmap-add",
  759. "data": {
  760. "node": "drive0",
  761. "name": "bitmap0"
  762. }
  763. },
  764. {
  765. "type": "block-dirty-bitmap-add",
  766. "data": {
  767. "node": "drive1",
  768. "name": "bitmap0"
  769. }
  770. },
  771. {
  772. "type": "blockdev-backup",
  773. "data": {
  774. "device": "drive0",
  775. "target": "target0",
  776. "sync": "full"
  777. }
  778. },
  779. {
  780. "type": "blockdev-backup",
  781. "data": {
  782. "device": "drive1",
  783. "target": "target1",
  784. "sync": "full"
  785. }
  786. }
  787. ]
  788. }
  789. }
  790. <- { "return": {} }
  791. ...
  792. <- {
  793. "timestamp": {...},
  794. "data": {
  795. "device": "drive0",
  796. "type": "backup",
  797. "speed": 0,
  798. "len": 68719476736,
  799. "offset": 68719476736
  800. },
  801. "event": "BLOCK_JOB_COMPLETED"
  802. }
  803. ...
  804. <- {
  805. "timestamp": {...},
  806. "data": {
  807. "device": "drive1",
  808. "type": "backup",
  809. "speed": 0,
  810. "len": 68719476736,
  811. "offset": 68719476736
  812. },
  813. "event": "BLOCK_JOB_COMPLETED"
  814. }
  815. ...
  816. #. Later, create new destination images for each of the incremental backups
  817. that point to their respective full backups:
  818. .. code:: bash
  819. $ qemu-img create -f qcow2 drive0.inc0.qcow2 \
  820. -b drive0.full.qcow2 -F qcow2
  821. $ qemu-img create -f qcow2 drive1.inc0.qcow2 \
  822. -b drive1.full.qcow2 -F qcow2
  823. #. Add target block nodes:
  824. .. code-block:: QMP
  825. -> {
  826. "execute": "blockdev-add",
  827. "arguments": {
  828. "node-name": "target0",
  829. "driver": "qcow2",
  830. "file": {
  831. "driver": "file",
  832. "filename": "drive0.inc0.qcow2"
  833. }
  834. }
  835. }
  836. <- { "return": {} }
  837. -> {
  838. "execute": "blockdev-add",
  839. "arguments": {
  840. "node-name": "target1",
  841. "driver": "qcow2",
  842. "file": {
  843. "driver": "file",
  844. "filename": "drive1.inc0.qcow2"
  845. }
  846. }
  847. }
  848. <- { "return": {} }
  849. #. Issue a multi-drive incremental push backup transaction:
  850. .. code-block:: QMP
  851. -> {
  852. "execute": "transaction",
  853. "arguments": {
  854. "actions": [
  855. {
  856. "type": "blockev-backup",
  857. "data": {
  858. "device": "drive0",
  859. "bitmap": "bitmap0",
  860. "sync": "incremental",
  861. "target": "target0"
  862. }
  863. },
  864. {
  865. "type": "blockdev-backup",
  866. "data": {
  867. "device": "drive1",
  868. "bitmap": "bitmap0",
  869. "sync": "incremental",
  870. "target": "target1"
  871. }
  872. },
  873. ]
  874. }
  875. }
  876. <- { "return": {} }
  877. ...
  878. <- {
  879. "timestamp": {...},
  880. "data": {
  881. "device": "drive0",
  882. "type": "backup",
  883. "speed": 0,
  884. "len": 68719476736,
  885. "offset": 68719476736
  886. },
  887. "event": "BLOCK_JOB_COMPLETED"
  888. }
  889. ...
  890. <- {
  891. "timestamp": {...},
  892. "data": {
  893. "device": "drive1",
  894. "type": "backup",
  895. "speed": 0,
  896. "len": 68719476736,
  897. "offset": 68719476736
  898. },
  899. "event": "BLOCK_JOB_COMPLETED"
  900. }
  901. ...
  902. Push Backup Errors & Recovery
  903. -----------------------------
  904. In the event of an error that occurs after a push backup job is successfully
  905. launched, either by an individual QMP command or a QMP transaction, the user
  906. will receive a ``BLOCK_JOB_COMPLETE`` event with a failure message,
  907. accompanied by a ``BLOCK_JOB_ERROR`` event.
  908. In the case of a job being cancelled, the user will receive a
  909. ``BLOCK_JOB_CANCELLED`` event instead of a pair of COMPLETE and ERROR
  910. events.
  911. In either failure case, the bitmap used for the failed operation is not
  912. cleared. It will contain all of the dirty bits it did at the start of the
  913. operation, plus any new bits that got marked during the operation.
  914. Effectively, the "point in time" that a bitmap is recording differences
  915. against is kept at the issuance of the last successful incremental backup,
  916. instead of being moved forward to the start of this now-failed backup.
  917. Once the underlying problem is addressed (e.g. more storage space is allocated
  918. on the destination), the incremental backup command can be retried with the
  919. same bitmap.
  920. Example: Individual Failures
  921. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  922. Incremental Push Backup jobs that fail individually behave simply as
  923. described above. This example demonstrates the single-job failure case:
  924. #. Create a target image:
  925. .. code:: bash
  926. $ qemu-img create -f qcow2 drive0.inc0.qcow2 \
  927. -b drive0.full.qcow2 -F qcow2
  928. #. Add target block node:
  929. .. code-block:: QMP
  930. -> {
  931. "execute": "blockdev-add",
  932. "arguments": {
  933. "node-name": "target0",
  934. "driver": "qcow2",
  935. "file": {
  936. "driver": "file",
  937. "filename": "drive0.inc0.qcow2"
  938. }
  939. }
  940. }
  941. <- { "return": {} }
  942. #. Attempt to create an incremental backup via QMP:
  943. .. code-block:: QMP
  944. -> {
  945. "execute": "blockdev-backup",
  946. "arguments": {
  947. "device": "drive0",
  948. "bitmap": "bitmap0",
  949. "target": "target0",
  950. "sync": "incremental"
  951. }
  952. }
  953. <- { "return": {} }
  954. #. Receive a pair of events indicating failure:
  955. .. code-block:: QMP
  956. <- {
  957. "timestamp": {...},
  958. "data": {
  959. "device": "drive0",
  960. "action": "report",
  961. "operation": "write"
  962. },
  963. "event": "BLOCK_JOB_ERROR"
  964. }
  965. <- {
  966. "timestamp": {...},
  967. "data": {
  968. "speed": 0,
  969. "offset": 0,
  970. "len": 67108864,
  971. "error": "No space left on device",
  972. "device": "drive0",
  973. "type": "backup"
  974. },
  975. "event": "BLOCK_JOB_COMPLETED"
  976. }
  977. #. Remove target node:
  978. .. code-block:: QMP
  979. -> {
  980. "execute": "blockdev-del",
  981. "arguments": {
  982. "node-name": "target0",
  983. }
  984. }
  985. <- { "return": {} }
  986. #. Delete the failed image, and re-create it.
  987. .. code:: bash
  988. $ rm drive0.inc0.qcow2
  989. $ qemu-img create -f qcow2 drive0.inc0.qcow2 \
  990. -b drive0.full.qcow2 -F qcow2
  991. #. Add target block node:
  992. .. code-block:: QMP
  993. -> {
  994. "execute": "blockdev-add",
  995. "arguments": {
  996. "node-name": "target0",
  997. "driver": "qcow2",
  998. "file": {
  999. "driver": "file",
  1000. "filename": "drive0.inc0.qcow2"
  1001. }
  1002. }
  1003. }
  1004. <- { "return": {} }
  1005. #. Retry the command after fixing the underlying problem, such as
  1006. freeing up space on the backup volume:
  1007. .. code-block:: QMP
  1008. -> {
  1009. "execute": "blockdev-backup",
  1010. "arguments": {
  1011. "device": "drive0",
  1012. "bitmap": "bitmap0",
  1013. "target": "target0",
  1014. "sync": "incremental"
  1015. }
  1016. }
  1017. <- { "return": {} }
  1018. #. Receive confirmation that the job completed successfully:
  1019. .. code-block:: QMP
  1020. <- {
  1021. "timestamp": {...},
  1022. "data": {
  1023. "device": "drive0",
  1024. "type": "backup",
  1025. "speed": 0,
  1026. "len": 67108864,
  1027. "offset": 67108864
  1028. },
  1029. "event": "BLOCK_JOB_COMPLETED"
  1030. }
  1031. Example: Partial Transactional Failures
  1032. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1033. QMP commands like `blockdev-backup
  1034. <qemu-qmp-ref.html#index-blockdev_002dbackup>`_
  1035. conceptually only start a job, and so transactions containing these commands
  1036. may succeed even if the job it created later fails. This might have surprising
  1037. interactions with notions of how a "transaction" ought to behave.
  1038. This distinction means that on occasion, a transaction containing such job
  1039. launching commands may appear to succeed and return success, but later
  1040. individual jobs associated with the transaction may fail. It is possible that
  1041. a management application may have to deal with a partial backup failure after
  1042. a "successful" transaction.
  1043. If multiple backup jobs are specified in a single transaction, if one of those
  1044. jobs fails, it will not interact with the other backup jobs in any way by
  1045. default. The job(s) that succeeded will clear the dirty bitmap associated with
  1046. the operation, but the job(s) that failed will not. It is therefore not safe
  1047. to delete any incremental backups that were created successfully in this
  1048. scenario, even though others failed.
  1049. This example illustrates a transaction with two backup jobs, where one fails
  1050. and one succeeds:
  1051. #. Issue the transaction to start a backup of both drives.
  1052. .. code-block:: QMP
  1053. -> {
  1054. "execute": "transaction",
  1055. "arguments": {
  1056. "actions": [
  1057. {
  1058. "type": "blockdev-backup",
  1059. "data": {
  1060. "device": "drive0",
  1061. "bitmap": "bitmap0",
  1062. "sync": "incremental",
  1063. "target": "target0"
  1064. }
  1065. },
  1066. {
  1067. "type": "blockdev-backup",
  1068. "data": {
  1069. "device": "drive1",
  1070. "bitmap": "bitmap0",
  1071. "sync": "incremental",
  1072. "target": "target1"
  1073. }
  1074. }]
  1075. }
  1076. }
  1077. #. Receive notice that the Transaction was accepted, and jobs were
  1078. launched:
  1079. .. code-block:: QMP
  1080. <- { "return": {} }
  1081. #. Receive notice that the first job has completed:
  1082. .. code-block:: QMP
  1083. <- {
  1084. "timestamp": {...},
  1085. "data": {
  1086. "device": "drive0",
  1087. "type": "backup",
  1088. "speed": 0,
  1089. "len": 67108864,
  1090. "offset": 67108864
  1091. },
  1092. "event": "BLOCK_JOB_COMPLETED"
  1093. }
  1094. #. Receive notice that the second job has failed:
  1095. .. code-block:: QMP
  1096. <- {
  1097. "timestamp": {...},
  1098. "data": {
  1099. "device": "drive1",
  1100. "action": "report",
  1101. "operation": "read"
  1102. },
  1103. "event": "BLOCK_JOB_ERROR"
  1104. }
  1105. ...
  1106. <- {
  1107. "timestamp": {...},
  1108. "data": {
  1109. "speed": 0,
  1110. "offset": 0,
  1111. "len": 67108864,
  1112. "error": "Input/output error",
  1113. "device": "drive1",
  1114. "type": "backup"
  1115. },
  1116. "event": "BLOCK_JOB_COMPLETED"
  1117. }
  1118. At the conclusion of the above example, ``drive0.inc0.qcow2`` is valid and
  1119. must be kept, but ``drive1.inc0.qcow2`` is incomplete and should be
  1120. deleted. If a VM-wide incremental backup of all drives at a point-in-time is
  1121. to be made, new backups for both drives will need to be made, taking into
  1122. account that a new incremental backup for drive0 needs to be based on top of
  1123. ``drive0.inc0.qcow2``.
  1124. For this example, an incremental backup for ``drive0`` was created, but not
  1125. for ``drive1``. The last VM-wide crash-consistent backup that is available in
  1126. this case is the full backup:
  1127. .. code:: text
  1128. [drive0.full.qcow2] <-- [drive0.inc0.qcow2]
  1129. [drive1.full.qcow2]
  1130. To repair this, issue a new incremental backup across both drives. The result
  1131. will be backup chains that resemble the following:
  1132. .. code:: text
  1133. [drive0.full.qcow2] <-- [drive0.inc0.qcow2] <-- [drive0.inc1.qcow2]
  1134. [drive1.full.qcow2] <-------------------------- [drive1.inc1.qcow2]
  1135. Example: Grouped Completion Mode
  1136. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1137. While jobs launched by transactions normally complete or fail individually,
  1138. it's possible to instruct them to complete or fail together as a group. QMP
  1139. transactions take an optional properties structure that can affect the
  1140. behavior of the transaction.
  1141. The ``completion-mode`` transaction property can be either ``individual``
  1142. which is the default legacy behavior described above, or ``grouped``, detailed
  1143. below.
  1144. In ``grouped`` completion mode, no jobs will report success until all jobs are
  1145. ready to report success. If any job fails, all other jobs will be cancelled.
  1146. Regardless of if a participating incremental backup job failed or was
  1147. cancelled, their associated bitmaps will all be held at their existing
  1148. points-in-time, as in individual failure cases.
  1149. Here's the same multi-drive backup scenario from `Example: Partial
  1150. Transactional Failures`_, but with the ``grouped`` completion-mode property
  1151. applied:
  1152. #. Issue the multi-drive incremental backup transaction:
  1153. .. code-block:: QMP
  1154. -> {
  1155. "execute": "transaction",
  1156. "arguments": {
  1157. "properties": {
  1158. "completion-mode": "grouped"
  1159. },
  1160. "actions": [
  1161. {
  1162. "type": "blockdev-backup",
  1163. "data": {
  1164. "device": "drive0",
  1165. "bitmap": "bitmap0",
  1166. "sync": "incremental",
  1167. "target": "target0"
  1168. }
  1169. },
  1170. {
  1171. "type": "blockdev-backup",
  1172. "data": {
  1173. "device": "drive1",
  1174. "bitmap": "bitmap0",
  1175. "sync": "incremental",
  1176. "target": "target1"
  1177. }
  1178. }]
  1179. }
  1180. }
  1181. #. Receive notice that the Transaction was accepted, and jobs were launched:
  1182. .. code-block:: QMP
  1183. <- { "return": {} }
  1184. #. Receive notification that the backup job for ``drive1`` has failed:
  1185. .. code-block:: QMP
  1186. <- {
  1187. "timestamp": {...},
  1188. "data": {
  1189. "device": "drive1",
  1190. "action": "report",
  1191. "operation": "read"
  1192. },
  1193. "event": "BLOCK_JOB_ERROR"
  1194. }
  1195. <- {
  1196. "timestamp": {...},
  1197. "data": {
  1198. "speed": 0,
  1199. "offset": 0,
  1200. "len": 67108864,
  1201. "error": "Input/output error",
  1202. "device": "drive1",
  1203. "type": "backup"
  1204. },
  1205. "event": "BLOCK_JOB_COMPLETED"
  1206. }
  1207. #. Receive notification that the job for ``drive0`` has been cancelled:
  1208. .. code-block:: QMP
  1209. <- {
  1210. "timestamp": {...},
  1211. "data": {
  1212. "device": "drive0",
  1213. "type": "backup",
  1214. "speed": 0,
  1215. "len": 67108864,
  1216. "offset": 16777216
  1217. },
  1218. "event": "BLOCK_JOB_CANCELLED"
  1219. }
  1220. At the conclusion of *this* example, both jobs have been aborted due to a
  1221. failure. Both destination images should be deleted and are no longer of use.
  1222. The transaction as a whole can simply be re-issued at a later time.
  1223. .. raw:: html
  1224. <!--
  1225. The FreeBSD Documentation License
  1226. Redistribution and use in source (ReST) and 'compiled' forms (SGML, HTML,
  1227. PDF, PostScript, RTF and so forth) with or without modification, are
  1228. permitted provided that the following conditions are met:
  1229. Redistributions of source code (ReST) must retain the above copyright notice,
  1230. this list of conditions and the following disclaimer of this file unmodified.
  1231. Redistributions in compiled form (transformed to other DTDs, converted to
  1232. PDF, PostScript, RTF and other formats) must reproduce the above copyright
  1233. notice, this list of conditions and the following disclaimer in the
  1234. documentation and/or other materials provided with the distribution.
  1235. THIS DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  1236. IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1237. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1238. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
  1239. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  1240. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  1241. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  1242. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  1243. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  1244. ARISING IN ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF ADVISED OF
  1245. THE POSSIBILITY OF SUCH DAMAGE.
  1246. -->