usagerest.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. .. _backup_restore_usagerest:
  2. Usage Via GeoServer's REST API
  3. ==============================
  4. The Backup and Restore REST API consists of a few resources meant to be used in an asynchronous fashion:
  5. .. list-table::
  6. :header-rows: 1
  7. * - Resource
  8. - Method
  9. - Parameters and Notes
  10. * - /rest/br/backup/
  11. - POST
  12. - Post a JSON/XML document with the backup parameters, see below
  13. * - /rest/br/backup/backupId
  14. - GET
  15. - Returns a json/xml representation of the backup operation. See below
  16. * - /rest/br/backup/backupId
  17. - DELETE
  18. - Cancels the backup operation
  19. * - /rest/br/restore
  20. - POST
  21. - Post a JSON/XML document with the restore parameters, see below
  22. * - /rest/br/restore/restoreId
  23. - GET
  24. - Returns a json/xml representation of the backup operation, see below
  25. * - /rest/br/restore/restoreId
  26. - DELETE
  27. - Cancels the restore operation
  28. Usage Example
  29. -------------
  30. We are going to use the command line tool cURL to send HTTP REST requests to GeoServer.
  31. The ``/rest/br/backup/`` and ``/rest/br/restore`` endpoints accept an optional format suffix that allows the Backup / Restore archive to be streamed to / from the client instead of being written on / read from the file system.
  32. **Initiate a Backup**
  33. Prepare a file containing with a JSON object representing the Backup procedure configuration.
  34. ``backup_post.json``:
  35. .. code-block:: json
  36. {
  37. "backup":{
  38. "archiveFile":"/home/sg/BackupAndRestore/test_rest_1.zip",
  39. "overwrite":true,
  40. "options":{
  41. }
  42. }
  43. }
  44. In this case we did not specify any options in the backup configuration so default values will be used.
  45. Available options are:
  46. #. ``BK_BEST_EFFORT``: Skip any failing resources and proceed with the backup procedure. Default: `false`.
  47. #. ``BK_PARAM_PASSWORDS``: Whether outgoing store passwords should be parameterized in the backup. With this option set
  48. all store passwords will be replaced with a token that looks like `${workspaceName:storeName.passwd.encryptedValue}`.
  49. See also ``BK_PASSWORD_TOKENS`` for the Restore command.
  50. #. ``BK_SKIP_SECURITY``: This will exclude security settings from the backup. Default: `true`.
  51. #. ``BK_SKIP_SETTINGS``: This will attempt to exclude global settings from the backup, as well as security settings. Default: `true`.
  52. #. ``BK_SKIP_GWC``: This option will avoid backup / restore the GWC catalog and folders. Default: `false`.
  53. #. ``BK_CLEANUP_TEMP``: This will attempt to delete temporary folder at the end of the execution. Default: `true`.
  54. #. ``exclude.file.path``: A ``;`` separated list of paths relative to the ``GEOSERVER_DATA_DIR``
  55. (e.g.: 'exclude.file.path=/data/geonode;/monitoring;/geofence'). If exist, the backup / restore will skip the path listed. Default: `[]`.
  56. WARNING: ``security`` and ``workspaces`` are treated differently. This option should be used only for custom external resources located under the ``GEOSERVER_DATA_DIR``.
  57. Also an optional ``Filter`` can be passed to restrict the scope of the restore operation to a list of workspaces.
  58. For example:
  59. .. code-block:: json
  60. {
  61. "backup":{
  62. "archiveFile":"/home/sg/BackupAndRestore/test_rest_1.zip",
  63. "overwrite":true,
  64. "options":{
  65. "option": ["BK_BEST_EFFORT=true"]
  66. },
  67. "filter": "name IN ('topp','geosolutions-it')"
  68. }
  69. }
  70. Backup procedure will be initiated.
  71. Here is a sample response:
  72. ::
  73. HTTP/1.1 201 Created
  74. Date: Mon, 01 Aug 2016 14:35:44 GMT
  75. Location: http://mygeoserver/geoserver/rest/br/backup/1
  76. Server: Noelios-Restlet-Engine/1.0..8
  77. Content-Type: application/json
  78. Transfer-Encoding: chunked
  79. .. code-block:: json
  80. {
  81. "backup":{
  82. "totalNumberOfSteps":9,
  83. "execution":{
  84. "id":1,
  85. "version":1,
  86. "stepExecutions":{
  87. "@class":"java.util.concurrent.CopyOnWriteArraySet"
  88. },
  89. "status":[
  90. "STARTED"
  91. ],
  92. "startTime":"2016-08-01 14:35:44.802 UTC",
  93. "createTime":"2016-08-01 14:35:44.798 UTC",
  94. "lastUpdated":"2016-08-01 14:35:44.803 UTC",
  95. "exitStatus":{
  96. "exitCode":"UNKNOWN",
  97. "exitDescription":""
  98. },
  99. "progress":"1\/9"
  100. },
  101. "options":{
  102. "@class":"synchList",
  103. "option":[
  104. "OVERWRITE=true"
  105. ]
  106. },
  107. "warningsList":{
  108. "@class":"synchList"
  109. },
  110. "archiveFile":{
  111. "@class":"resource",
  112. "$":"\/home\/sg\/BackupAndRestore\/test_rest_1.zip"
  113. },
  114. "overwrite":true
  115. }
  116. }
  117. At the end of the backup procedure you'll be able to download the generated archive to your local file system by making an HTTP GET request to the same endpoint, using the **backup ID** as above and adding the ``.zip`` at the end.
  118. .. code-block:: bash
  119. curl -u "admin:geoserver" -i -X GET "http://mygeoserver/geoserver/rest/br/backup/1.zip" -o 1.zip
  120. .. figure:: images/usagerest001.png
  121. :align: center
  122. **Query status of Backup executions**
  123. Status of the operation can be queried making an HTTP GET request to the location listed in the response.
  124. .. code-block:: text
  125. ``http://mygeoserver/geoserver/rest/br/backup/$ID.{json/xml}``
  126. Replace ``$ID`` with the **ID** of the backup operation you'd like to inspect.
  127. .. code-block:: bash
  128. curl -u "admin:geoserver" http://mygeoserver/geoserver/rest/br/backup/1.json
  129. or
  130. .. code-block:: bash
  131. curl -u "admin:geoserver" http://mygeoserver/geoserver/rest/br/backup/1.xml
  132. GeoServer will respond with the status of the backup job corresponding to that ID
  133. .. figure:: images/usagerest002.png
  134. :align: center
  135. .. figure:: images/usagerest003.png
  136. :align: center
  137. Here you are able to see the status of all the steps involved in the backup procedure with creation time, start time, end time, exit status etc.
  138. **Cancel a Backup**
  139. Cancel an in progress Backup by sending an HTTP DELETE request with the ID of the task
  140. .. code-block:: bash
  141. curl -v -XDELETE -u "admin:geoserver" http://mygeoserver/geoserver/rest/br/backup/$ID
  142. Replace ``$ID`` with the **ID** of the backup operation you'd like to cancel.
  143. **Initiate a Restore**
  144. Prepare a file with a JSON object representing the Restore procedure configuration
  145. ``restore_post.json``:
  146. .. code-block:: json
  147. {
  148. "restore":{
  149. "archiveFile":"/home/sg/BackupAndRestore/test_rest_1.zip",
  150. "options":{
  151. }
  152. }
  153. }
  154. In this case we did not specify any options in the restore configuration so default values will be used.
  155. Available Options are:
  156. #. ``BK_DRY_RUN``: Only test the archive do not persist the restored configuration. Default: `false`.
  157. #. ``BK_BEST_EFFORT``: Skip any failing resources and proceed with the restore procedure. Default: `false`.
  158. #. ``BK_PASSWORD_TOKENS``: A comma separated list of equal sign separated key/values to be replaced in data store passwords
  159. in an incoming backup. For example:
  160. .. code-block:: text
  161. BK_PASSWORD_TOKENS=${workspace:store1.passwd.encryptedValye}=foo,${workspace:store2.passwd.encryptedValue}=bar
  162. #. ``BK_SKIP_SECURITY``: This will exclude security settings from the restore. Default: `true`.
  163. #. ``BK_SKIP_SETTINGS``: This will attempt to exclude global settings from the backup, as well as security settings. Default: `true`.
  164. #. ``BK_PURGE_RESOURCES``: If 'false' this parameter will avoid deleting incoming resources where possible. In particular,
  165. existing workspaces will not be deleted during the restore. Default: `true`.
  166. #. ``BK_SKIP_GWC``: This option will avoid backup / restore the GWC catalog and folders. Default: `false`.
  167. #. ``BK_CLEANUP_TEMP``: This will attempt to delete temporary folder at the end of the execution. Default: `true`.
  168. #. ``exclude.file.path``: A ``;`` separated list of paths relative to the ``GEOSERVER_DATA_DIR``
  169. (e.g.: 'exclude.file.path=/data/geonode;/monitoring;/geofence'). If exist, the backup / restore will skip the path listed. Default: `[]`.
  170. WARNING: ``security`` and ``workspaces`` are treated differently. This option should be used only for custom external resources located under the ``GEOSERVER_DATA_DIR``.
  171. Also an optional ``Filter`` can be passed to restrict the scope of the restore operation to a list of workspaces.
  172. For example:
  173. .. code-block:: text
  174. {
  175. "restore":{
  176. "archiveFile":"/home/sg/BackupAndRestore/test_rest_1.zip",
  177. "options":{
  178. "option": ["BK_DRY_RUN=true"]
  179. },
  180. "filter": "name IN ('topp','geosolutions-it')"
  181. }
  182. }
  183. If ``archiveFile`` is specified, the archive specified on that path of the remote file system will be used to initiate the restore procedure.
  184. Otherwise the archive needs to be uploaded from your local system.
  185. Then make a POST HTTP request to GeoServer's REST interface endpoint for the restore procedure
  186. .. code-block:: bash
  187. curl -u "admin:geoserver" -i -H "Content-Type: application/json" -X POST --data @restore_post.json http://mygeoserver/geoserver/rest/br/restore/
  188. Restore procedure will be initiated.
  189. Here is a sample response:
  190. ::
  191. HTTP/1.1 201 Created
  192. Date: Mon, 01 Aug 2016 15:07:29 GMT
  193. Location: http://mygeoserver/geoserver/rest/br/restore/2
  194. Server: Noelios-Restlet-Engine/1.0..8
  195. Content-Type: application/json
  196. Transfer-Encoding: chunked
  197. .. code-block:: json
  198. {
  199. "restore":{
  200. "totalNumberOfSteps":9,
  201. "execution":{
  202. "id":2,
  203. "version":1,
  204. "stepExecutions":{
  205. "@class":"java.util.concurrent.CopyOnWriteArraySet"
  206. },
  207. "status":[
  208. "STARTED"
  209. ],
  210. "startTime":"2016-08-01 15:07:29.398 UTC",
  211. "createTime":"2016-08-01 15:07:29.393 UTC",
  212. "lastUpdated":"2016-08-01 15:07:29.398 UTC",
  213. "exitStatus":{
  214. "exitCode":"UNKNOWN",
  215. "exitDescription":""
  216. },
  217. "progress":"0\/9"
  218. },
  219. "options":{
  220. "@class":"synchList"
  221. },
  222. "warningsList":{
  223. "@class":"synchList"
  224. },
  225. "archiveFile":{
  226. "@class":"resource",
  227. "$":"\/home\/sg\/BackupAndRestore\/test_rest_1.zip"
  228. }
  229. }
  230. }
  231. .. figure:: images/usagerest004.png
  232. :align: center
  233. To upload the archive from our local system instead, omit the archiveFile parameter in the JSON object and pass the ``--upload-file`` parameter to cURL:
  234. ``restore_post.json``:
  235. .. code-block:: json
  236. {
  237. "restore":{
  238. "options":{
  239. },
  240. }
  241. }
  242. .. code-block:: bash
  243. curl -u "admin:geoserver" -i -H "Content-Type: application/json" --upload-file "archive_to_restore.zip" -X POST --data @restore_post.json http://localhost:8081/geoserver/rest/br/restore/
  244. Local ``archive_to_restore.zip`` archive will be uploaded and used by the restore procedure.
  245. .. figure:: images/usagerest005.png
  246. :align: center
  247. Query for status of Restore operations
  248. ``http://mygeoserver/geoser/restore/$ID.{json/xml}``:
  249. .. code-block:: text
  250. {
  251. "restore":{
  252. "execution":{
  253. "hash":2,
  254. "key":{
  255. "@class":"long",
  256. "$":"2"
  257. },
  258. "val":{
  259. "@class":"restore",
  260. "totalNumberOfSteps":9,
  261. "execution":{
  262. "id":2,
  263. "version":2,
  264. "stepExecutions":{
  265. "@class":"java.util.concurrent.CopyOnWriteArraySet",
  266. "step":[
  267. {
  268. "name":"restoreNamespaceInfos",
  269. "status":"COMPLETED",
  270. "exitStatus":{
  271. "exitCode":"COMPLETED",
  272. "exitDescription":""
  273. },
  274. "startTime":"8\/1\/16 3:07 PM",
  275. "endTime":"8\/1\/16 3:07 PM",
  276. "lastUpdated":"8\/1\/16 3:07 PM",
  277. "parameters":{
  278. "input.file.path":"file:\/\/\/opt\/tomcat-geoserver-2.9.x\/temp\/tmpbbe2388a-f26d-4f26-a20f-88c653d88aec",
  279. "time":1470064049392
  280. },
  281. "readCount":1,
  282. "writeCount":1,
  283. "failureExceptions":""
  284. },
  285. ...
  286. {
  287. "name":"restoreGeoServerSecurityManager",
  288. "status":"COMPLETED",
  289. "exitStatus":{
  290. "exitCode":"COMPLETED",
  291. "exitDescription":""
  292. },
  293. "startTime":"8\/1\/16 3:07 PM",
  294. "endTime":"8\/1\/16 3:07 PM",
  295. "lastUpdated":"8\/1\/16 3:07 PM",
  296. "parameters":{
  297. "input.file.path":"file:\/\/\/opt\/tomcat-geoserver-2.9.x\/temp\/tmpbbe2388a-f26d-4f26-a20f-88c653d88aec",
  298. "time":1470064049392
  299. },
  300. "readCount":0,
  301. "writeCount":0,
  302. "failureExceptions":""
  303. }
  304. ]
  305. },
  306. "status":"COMPLETED",
  307. "startTime":"2016-08-01 15:07:29.398 UTC",
  308. "createTime":"2016-08-01 15:07:29.393 UTC",
  309. "endTime":"2016-08-01 15:07:30.356 UTC",
  310. "lastUpdated":"2016-08-01 15:07:30.772 UTC",
  311. "exitStatus":{
  312. "exitCode":"COMPLETED",
  313. "exitDescription":""
  314. },
  315. "progress":"9\/9"
  316. },
  317. "options":{
  318. "@class":"synchList"
  319. },
  320. "warningsList":{
  321. "@class":"synchList"
  322. },
  323. "archiveFile":{
  324. "@class":"resource",
  325. "$":"\/home\/sg\/BackupAndRestore\/test_rest_1.zip"
  326. }
  327. }
  328. }
  329. ...
  330. Here you are able to see the status of all the steps involved in the restore procedure with creation time, start time, end time, exit status etc.
  331. **Cancel a Restore**
  332. Cancel an in-progress Restore by sending an HTTP DELETE request:
  333. .. code-block:: bash
  334. curl -v -XDELETE -u "admin:geoserver" http://mygeoserver/geoserver/rest/br/restore/$ID
  335. Replace ``$ID`` with the **ID** of the restore operation you'd like to cancel.