github.com/cozy/cozy-stack@v0.0.0-20240327093429-939e4a21320e/docs/move.md (about) 1 [Table of contents](README.md#table-of-contents) 2 3 # Move, export and import 4 5 ## Export 6 7 A Cozy's user can ask at any time to export a snapshot of all its data and 8 metadata. This export takes place asynchronously and is separated in two parts: 9 10 - a metadata tarball containing the in a JSON format all the doctypes 11 - multi-part files tarballs containing the files (or a subpart of the files). 12 13 The export process is part of a worker described in the 14 [workers section](./workers.md#export) of the documentation. 15 16 Endpoints described in this documentation require a permission on the 17 `io.cozy.exports` doctype. 18 19 ### POST /move/exports 20 21 This endpoint can be used to create a new export job. 22 23 Exports options fields are: 24 25 - `parts_size` (optional) (int): the size in bytes of a tarball files part. 26 - `max_age` (optional) (duration / nanosecs): the maximum age of the export 27 data. 28 - `with_doctypes` (optional) (string array): the list of exported doctypes 29 30 #### Request 31 32 ```http 33 POST /move/exports HTTP/1.1 34 Host: source.cozy.localhost 35 Authorization: Bearer ... 36 Content-Type: application/vnd.api+json 37 ``` 38 39 ```json 40 { 41 "data": { 42 "attributes": { 43 "parts_size": 10240, 44 "with_doctypes": [] 45 } 46 } 47 } 48 ``` 49 50 ### GET /move/exports/:opaque-identifier 51 52 This endpoint can be used to fetch the metadata of an export. 53 54 Exports fields are: 55 56 - `parts_size` (int): the size in bytes of a tarball files part. 57 - `parts_cursors` (string array): the list of cursors to access to the 58 different files parts. 59 - `with_doctypes` (string array): the list of exported doctypes 60 (if empty of null, all doctypes are exported) 61 - `state` (string): the state of the export (`"exporting"` / `"done"` / 62 `"error"`). 63 - `created_at` (string / time): the date of creation of the export 64 - `expires_at` (string / time): the date of expiration of the export 65 - `total_size` (int): the total size of the exported documents from CouchDB 66 - `creation_duration` (int): the amount of nanoseconds taken for the creation 67 of the export 68 - `error` (string): an error string if the export is in an `"error"` state 69 70 #### Request 71 72 ```http 73 GET /move/exports/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX HTTP/1.1 74 Host: source.cozy.localhost 75 Authorization: Bearer ... 76 Content-Type: application/vnd.api+json 77 ``` 78 79 ```json 80 { 81 "data": { 82 "type": "io.cozy.exports", 83 "id": "86dbb546ca49f0ed1ce0a1ff0d1b15e3", 84 "meta": { 85 "rev": "2-XXX" 86 }, 87 "attributes": { 88 "parts_size": 10240, 89 "parts_cursors": ["AAA", "BBB", "CCC"], 90 "with_doctypes": [], 91 "state": "done", 92 "created_at": "2018-05-04T08:59:37.530693972+02:00", 93 "expires_at": "2018-05-11T08:59:37.530693972+02:00", 94 "total_size": 1123, 95 "creation_duration": 62978511, 96 "error": "" 97 } 98 } 99 } 100 ``` 101 102 ### GET /move/exports/data/:opaque-identifier?cursor=XXX 103 104 This endpoint will download an archive containing the metadata and files of the 105 user, as part of a multi-part download. The cursor given should be one of the 106 defined in the export document `parts_cursors`. 107 108 Only the first part of the archive contains the metadata. 109 110 To get all the parts, this endpoint must be called one time with no cursor, and 111 one time for each cursor in `parts_cursors`. 112 113 ## Import 114 115 ### POST /move/imports/precheck 116 117 This endpoint can be use to check that an export can be imported from the given 118 URL, before doing the real import. It is called from the settings application, 119 not from the cozy-move wizard. 120 121 #### Request 122 123 ```http 124 POST /move/imports/precheck HTTP/1.1 125 Host: destination.cozy.localhost 126 Authorization: Bearer ... 127 Content-Type: application/vnd.api+json 128 ``` 129 130 ```json 131 { 132 "data": { 133 "attributes": { 134 "url": "https://settings.source.cozy.localhost/#/exports/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 135 } 136 } 137 } 138 ``` 139 140 #### Responses 141 142 - `204 No Content` if every thing is fine 143 - `412 Precondition Failed` if no archive can be found at the given URL 144 - `422 Entity Too Large` if the quota is too small to import the files 145 146 ### POST /move/imports 147 148 This endpoint can be used to really start an import. 149 150 #### Request 151 152 ```http 153 POST /move/imports HTTP/1.1 154 Host: destination.cozy.localhost 155 Authorization: Bearer ... 156 Content-Type: application/vnd.api+json 157 ``` 158 159 ```json 160 { 161 "data": { 162 "attributes": { 163 "url": "https://settings.source.cozy.localhost/#/exports/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 164 } 165 } 166 } 167 ``` 168 169 #### Responses 170 171 ```http 172 HTTP/1.1 303 See Other 173 Location: https://destination.cozy.localhost/move/importing 174 ``` 175 176 ### POST /move/importing 177 178 This endpoint is called on the target Cozy by the source Cozy to block the 179 instance during the move. A `source` parameter can be put in the query-string, 180 with the domain of the Cozy source (for information). 181 182 ### GET /move/importing 183 184 This shows a page for the user to wait that the import finishes. 185 186 ### GET /move/importing/realtime 187 188 This is a websocket endpoint that can be used to wait for the end of the 189 import. The server will send an event when it is done (or errored): 190 191 ``` 192 server> {"redirect": "http://cozy.localhost:8080/auth/login"} 193 ``` 194 195 ### GET /move/authorize 196 197 This endpoint is used by cozy-move to select the cozy source. If the user is 198 already logged in, we don't ask its password again, as the delivered token will 199 still need a confirmation by mail to start moving the Cozy. 200 201 #### Request 202 203 ```http 204 GET /move/authorize?state=8d560d60&redirect_uri=https://move.cozycloud.cc/callback/source HTTP/1.1 205 Server: source.cozy.localhost 206 ``` 207 208 #### Response 209 210 ```http 211 HTTP/1.1 302 Found 212 Location: https://move.cozycloud.cc/callback/source?code=543d7eb8149c&used=123456"a=5000000&state=8d560d60&vault=false 213 ``` 214 215 ### POST /move/initialize 216 217 This endpoint is used by the settings application to open the move wizard. 218 219 #### Request 220 221 ```http 222 POST /move/initialize HTTP/1.1 223 Host: source.cozy.localhost 224 ``` 225 226 #### Response 227 228 ```http 229 HTTP/1.1 307 Temporary Redirect 230 Location: https://move.cozycloud.cc/initialize?code=834d7eb8149c&cozy_url=https://source.cozy.localhost&used=123456"a=5000000&client_id=09136b00-1778-0139-f0a7-543d7eb8149c&client_secret=NDkyZTEzMDA&vault=false 231 ``` 232 233 ### POST /move/request 234 235 This endpoint is used after the user has selected both instances on cozy-move 236 to prepare the export and send the confirmation mail. 237 238 #### Request 239 240 ```http 241 POST /move/request HTTP/1.1 242 Content-Type: application/x-www-form-urlencoded 243 244 code=834d7eb8149c 245 &target_url=https://target.cozy.localhost/ 246 &target_token=M2EwYjlhZjAtMTc3OC0wMTM5LWYwYWMtNTQzZDdlYjgxNDlj 247 &target_client_id=09136b00-1778-0139-f0a7-543d7eb8149c 248 &target_client_secret=NDkyZTEzMDA 249 ``` 250 251 **Note:** instead of `code`, we can have `token`, `client_id`, and 252 `client_secret` (depending if the user has started the workflow from the 253 settings app or from cozy-move). 254 255 #### Response 256 257 ```http 258 HTTP/1.1 200 OK 259 Content-Type: application/html 260 ``` 261 262 ### GET /move/go 263 264 This endpoint is used to confirm the move. It will ask the other Cozy to block 265 its-self during the move and pushs a job for the export. 266 267 #### Request 268 269 ```http 270 GET /move/go?secret=tNTQzZDdlYjgxNDlj HTTP/1.1 271 Host: source.cozy.localhost 272 ``` 273 274 #### Reponse 275 276 ```http 277 HTTP/1.1 303 See Other 278 Location: https://target.cozy.localhost/move/importing 279 ``` 280 281 ### POST /move/finalize 282 283 When the move has finished successfully, the target Cozy calls this endpoint on 284 the source Cozy so that it can stop the konnectors and unblock the instance. 285 286 #### Request 287 288 ```http 289 POST /move/finalize?subdomain=flat HTTP/1.1 290 Host: source.cozy.localhost 291 ``` 292 #### Reponse 293 294 ``` 295 HTTP/1.1 204 No Content 296 ``` 297 298 ### POST /move/abort 299 300 If the export or the import fails during a move, the stack will call this 301 endpoint for the other instance to unblock it. 302 303 #### Request 304 305 ```http 306 POST /move/abort HTTP/1.1 307 Host: source.cozy.localhost 308 ``` 309 #### Reponse 310 311 ``` 312 HTTP/1.1 204 No Content 313 ``` 314 315 ### GET /move/vault 316 317 This shows a page for the user with instructions about how to import their vault.