github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/docs/content/b2.md (about) 1 --- 2 title: "B2" 3 description: "Backblaze B2" 4 date: "2016-10-25" 5 --- 6 7 <i class="fa fa-fire"></i>Backblaze B2 8 ---------------------------------------- 9 10 B2 is [Backblaze's cloud storage system](https://www.backblaze.com/b2/). 11 12 Paths are specified as `remote:bucket` (or `remote:` for the `lsd` 13 command.) You may put subdirectories in too, eg `remote:bucket/path/to/dir`. 14 15 Here is an example of making a b2 configuration. First run 16 17 rclone config 18 19 This will guide you through an interactive setup process. To authenticate 20 you will either need your Account ID (a short hex number) and Master 21 Application Key (a long hex number) OR an Application Key, which is the 22 recommended method. See below for further details on generating and using 23 an Application Key. 24 25 ``` 26 No remotes found - make a new one 27 n) New remote 28 q) Quit config 29 n/q> n 30 name> remote 31 Type of storage to configure. 32 Choose a number from below, or type in your own value 33 [snip] 34 XX / Backblaze B2 35 \ "b2" 36 [snip] 37 Storage> b2 38 Account ID or Application Key ID 39 account> 123456789abc 40 Application Key 41 key> 0123456789abcdef0123456789abcdef0123456789 42 Endpoint for the service - leave blank normally. 43 endpoint> 44 Remote config 45 -------------------- 46 [remote] 47 account = 123456789abc 48 key = 0123456789abcdef0123456789abcdef0123456789 49 endpoint = 50 -------------------- 51 y) Yes this is OK 52 e) Edit this remote 53 d) Delete this remote 54 y/e/d> y 55 ``` 56 57 This remote is called `remote` and can now be used like this 58 59 See all buckets 60 61 rclone lsd remote: 62 63 Create a new bucket 64 65 rclone mkdir remote:bucket 66 67 List the contents of a bucket 68 69 rclone ls remote:bucket 70 71 Sync `/home/local/directory` to the remote bucket, deleting any 72 excess files in the bucket. 73 74 rclone sync /home/local/directory remote:bucket 75 76 ### Application Keys ### 77 78 B2 supports multiple [Application Keys for different access permission 79 to B2 Buckets](https://www.backblaze.com/b2/docs/application_keys.html). 80 81 You can use these with rclone too; you will need to use rclone version 1.43 82 or later. 83 84 Follow Backblaze's docs to create an Application Key with the required 85 permission and add the `applicationKeyId` as the `account` and the 86 `Application Key` itself as the `key`. 87 88 Note that you must put the _applicationKeyId_ as the `account` – you 89 can't use the master Account ID. If you try then B2 will return 401 90 errors. 91 92 ### --fast-list ### 93 94 This remote supports `--fast-list` which allows you to use fewer 95 transactions in exchange for more memory. See the [rclone 96 docs](/docs/#fast-list) for more details. 97 98 ### Modified time ### 99 100 The modified time is stored as metadata on the object as 101 `X-Bz-Info-src_last_modified_millis` as milliseconds since 1970-01-01 102 in the Backblaze standard. Other tools should be able to use this as 103 a modified time. 104 105 Modified times are used in syncing and are fully supported. Note that 106 if a modification time needs to be updated on an object then it will 107 create a new version of the object. 108 109 #### Restricted filename characters 110 111 In addition to the [default restricted characters set](/overview/#restricted-characters) 112 the following characters are also replaced: 113 114 | Character | Value | Replacement | 115 | --------- |:-----:|:-----------:| 116 | \ | 0x5C | \ | 117 118 Invalid UTF-8 bytes will also be [replaced](/overview/#invalid-utf8), 119 as they can't be used in JSON strings. 120 121 ### SHA1 checksums ### 122 123 The SHA1 checksums of the files are checked on upload and download and 124 will be used in the syncing process. 125 126 Large files (bigger than the limit in `--b2-upload-cutoff`) which are 127 uploaded in chunks will store their SHA1 on the object as 128 `X-Bz-Info-large_file_sha1` as recommended by Backblaze. 129 130 For a large file to be uploaded with an SHA1 checksum, the source 131 needs to support SHA1 checksums. The local disk supports SHA1 132 checksums so large file transfers from local disk will have an SHA1. 133 See [the overview](/overview/#features) for exactly which remotes 134 support SHA1. 135 136 Sources which don't support SHA1, in particular `crypt` will upload 137 large files without SHA1 checksums. This may be fixed in the future 138 (see [#1767](https://github.com/rclone/rclone/issues/1767)). 139 140 Files sizes below `--b2-upload-cutoff` will always have an SHA1 141 regardless of the source. 142 143 ### Transfers ### 144 145 Backblaze recommends that you do lots of transfers simultaneously for 146 maximum speed. In tests from my SSD equipped laptop the optimum 147 setting is about `--transfers 32` though higher numbers may be used 148 for a slight speed improvement. The optimum number for you may vary 149 depending on your hardware, how big the files are, how much you want 150 to load your computer, etc. The default of `--transfers 4` is 151 definitely too low for Backblaze B2 though. 152 153 Note that uploading big files (bigger than 200 MB by default) will use 154 a 96 MB RAM buffer by default. There can be at most `--transfers` of 155 these in use at any moment, so this sets the upper limit on the memory 156 used. 157 158 ### Versions ### 159 160 When rclone uploads a new version of a file it creates a [new version 161 of it](https://www.backblaze.com/b2/docs/file_versions.html). 162 Likewise when you delete a file, the old version will be marked hidden 163 and still be available. Conversely, you may opt in to a "hard delete" 164 of files with the `--b2-hard-delete` flag which would permanently remove 165 the file instead of hiding it. 166 167 Old versions of files, where available, are visible using the 168 `--b2-versions` flag. 169 170 **NB** Note that `--b2-versions` does not work with crypt at the 171 moment [#1627](https://github.com/rclone/rclone/issues/1627). Using 172 [--backup-dir](/docs/#backup-dir-dir) with rclone is the recommended 173 way of working around this. 174 175 If you wish to remove all the old versions then you can use the 176 `rclone cleanup remote:bucket` command which will delete all the old 177 versions of files, leaving the current ones intact. You can also 178 supply a path and only old versions under that path will be deleted, 179 eg `rclone cleanup remote:bucket/path/to/stuff`. 180 181 Note that `cleanup` will remove partially uploaded files from the bucket 182 if they are more than a day old. 183 184 When you `purge` a bucket, the current and the old versions will be 185 deleted then the bucket will be deleted. 186 187 However `delete` will cause the current versions of the files to 188 become hidden old versions. 189 190 Here is a session showing the listing and retrieval of an old 191 version followed by a `cleanup` of the old versions. 192 193 Show current version and all the versions with `--b2-versions` flag. 194 195 ``` 196 $ rclone -q ls b2:cleanup-test 197 9 one.txt 198 199 $ rclone -q --b2-versions ls b2:cleanup-test 200 9 one.txt 201 8 one-v2016-07-04-141032-000.txt 202 16 one-v2016-07-04-141003-000.txt 203 15 one-v2016-07-02-155621-000.txt 204 ``` 205 206 Retrieve an old version 207 208 ``` 209 $ rclone -q --b2-versions copy b2:cleanup-test/one-v2016-07-04-141003-000.txt /tmp 210 211 $ ls -l /tmp/one-v2016-07-04-141003-000.txt 212 -rw-rw-r-- 1 ncw ncw 16 Jul 2 17:46 /tmp/one-v2016-07-04-141003-000.txt 213 ``` 214 215 Clean up all the old versions and show that they've gone. 216 217 ``` 218 $ rclone -q cleanup b2:cleanup-test 219 220 $ rclone -q ls b2:cleanup-test 221 9 one.txt 222 223 $ rclone -q --b2-versions ls b2:cleanup-test 224 9 one.txt 225 ``` 226 227 ### Data usage ### 228 229 It is useful to know how many requests are sent to the server in different scenarios. 230 231 All copy commands send the following 4 requests: 232 233 ``` 234 /b2api/v1/b2_authorize_account 235 /b2api/v1/b2_create_bucket 236 /b2api/v1/b2_list_buckets 237 /b2api/v1/b2_list_file_names 238 ``` 239 240 The `b2_list_file_names` request will be sent once for every 1k files 241 in the remote path, providing the checksum and modification time of 242 the listed files. As of version 1.33 issue 243 [#818](https://github.com/rclone/rclone/issues/818) causes extra requests 244 to be sent when using B2 with Crypt. When a copy operation does not 245 require any files to be uploaded, no more requests will be sent. 246 247 Uploading files that do not require chunking, will send 2 requests per 248 file upload: 249 250 ``` 251 /b2api/v1/b2_get_upload_url 252 /b2api/v1/b2_upload_file/ 253 ``` 254 255 Uploading files requiring chunking, will send 2 requests (one each to 256 start and finish the upload) and another 2 requests for each chunk: 257 258 ``` 259 /b2api/v1/b2_start_large_file 260 /b2api/v1/b2_get_upload_part_url 261 /b2api/v1/b2_upload_part/ 262 /b2api/v1/b2_finish_large_file 263 ``` 264 265 #### Versions #### 266 267 Versions can be viewed with the `--b2-versions` flag. When it is set 268 rclone will show and act on older versions of files. For example 269 270 Listing without `--b2-versions` 271 272 ``` 273 $ rclone -q ls b2:cleanup-test 274 9 one.txt 275 ``` 276 277 And with 278 279 ``` 280 $ rclone -q --b2-versions ls b2:cleanup-test 281 9 one.txt 282 8 one-v2016-07-04-141032-000.txt 283 16 one-v2016-07-04-141003-000.txt 284 15 one-v2016-07-02-155621-000.txt 285 ``` 286 287 Showing that the current version is unchanged but older versions can 288 be seen. These have the UTC date that they were uploaded to the 289 server to the nearest millisecond appended to them. 290 291 Note that when using `--b2-versions` no file write operations are 292 permitted, so you can't upload files or delete them. 293 294 ### B2 and rclone link ### 295 296 Rclone supports generating file share links for private B2 buckets. 297 They can either be for a file for example: 298 299 ``` 300 ./rclone link B2:bucket/path/to/file.txt 301 https://f002.backblazeb2.com/file/bucket/path/to/file.txt?Authorization=xxxxxxxx 302 303 ``` 304 305 or if run on a directory you will get: 306 307 ``` 308 ./rclone link B2:bucket/path 309 https://f002.backblazeb2.com/file/bucket/path?Authorization=xxxxxxxx 310 ``` 311 312 you can then use the authorization token (the part of the url from the 313 `?Authorization=` on) on any file path under that directory. For example: 314 315 ``` 316 https://f002.backblazeb2.com/file/bucket/path/to/file1?Authorization=xxxxxxxx 317 https://f002.backblazeb2.com/file/bucket/path/file2?Authorization=xxxxxxxx 318 https://f002.backblazeb2.com/file/bucket/path/folder/file3?Authorization=xxxxxxxx 319 320 ``` 321 322 <!--- autogenerated options start - DO NOT EDIT, instead edit fs.RegInfo in backend/b2/b2.go then run make backenddocs --> 323 ### Standard Options 324 325 Here are the standard options specific to b2 (Backblaze B2). 326 327 #### --b2-account 328 329 Account ID or Application Key ID 330 331 - Config: account 332 - Env Var: RCLONE_B2_ACCOUNT 333 - Type: string 334 - Default: "" 335 336 #### --b2-key 337 338 Application Key 339 340 - Config: key 341 - Env Var: RCLONE_B2_KEY 342 - Type: string 343 - Default: "" 344 345 #### --b2-hard-delete 346 347 Permanently delete files on remote removal, otherwise hide files. 348 349 - Config: hard_delete 350 - Env Var: RCLONE_B2_HARD_DELETE 351 - Type: bool 352 - Default: false 353 354 ### Advanced Options 355 356 Here are the advanced options specific to b2 (Backblaze B2). 357 358 #### --b2-endpoint 359 360 Endpoint for the service. 361 Leave blank normally. 362 363 - Config: endpoint 364 - Env Var: RCLONE_B2_ENDPOINT 365 - Type: string 366 - Default: "" 367 368 #### --b2-test-mode 369 370 A flag string for X-Bz-Test-Mode header for debugging. 371 372 This is for debugging purposes only. Setting it to one of the strings 373 below will cause b2 to return specific errors: 374 375 * "fail_some_uploads" 376 * "expire_some_account_authorization_tokens" 377 * "force_cap_exceeded" 378 379 These will be set in the "X-Bz-Test-Mode" header which is documented 380 in the [b2 integrations checklist](https://www.backblaze.com/b2/docs/integration_checklist.html). 381 382 - Config: test_mode 383 - Env Var: RCLONE_B2_TEST_MODE 384 - Type: string 385 - Default: "" 386 387 #### --b2-versions 388 389 Include old versions in directory listings. 390 Note that when using this no file write operations are permitted, 391 so you can't upload files or delete them. 392 393 - Config: versions 394 - Env Var: RCLONE_B2_VERSIONS 395 - Type: bool 396 - Default: false 397 398 #### --b2-upload-cutoff 399 400 Cutoff for switching to chunked upload. 401 402 Files above this size will be uploaded in chunks of "--b2-chunk-size". 403 404 This value should be set no larger than 4.657GiB (== 5GB). 405 406 - Config: upload_cutoff 407 - Env Var: RCLONE_B2_UPLOAD_CUTOFF 408 - Type: SizeSuffix 409 - Default: 200M 410 411 #### --b2-chunk-size 412 413 Upload chunk size. Must fit in memory. 414 415 When uploading large files, chunk the file into this size. Note that 416 these chunks are buffered in memory and there might a maximum of 417 "--transfers" chunks in progress at once. 5,000,000 Bytes is the 418 minimum size. 419 420 - Config: chunk_size 421 - Env Var: RCLONE_B2_CHUNK_SIZE 422 - Type: SizeSuffix 423 - Default: 96M 424 425 #### --b2-disable-checksum 426 427 Disable checksums for large (> upload cutoff) files 428 429 - Config: disable_checksum 430 - Env Var: RCLONE_B2_DISABLE_CHECKSUM 431 - Type: bool 432 - Default: false 433 434 #### --b2-download-url 435 436 Custom endpoint for downloads. 437 438 This is usually set to a Cloudflare CDN URL as Backblaze offers 439 free egress for data downloaded through the Cloudflare network. 440 This is probably only useful for a public bucket. 441 Leave blank if you want to use the endpoint provided by Backblaze. 442 443 - Config: download_url 444 - Env Var: RCLONE_B2_DOWNLOAD_URL 445 - Type: string 446 - Default: "" 447 448 #### --b2-download-auth-duration 449 450 Time before the authorization token will expire in s or suffix ms|s|m|h|d. 451 452 The duration before the download authorization token will expire. 453 The minimum value is 1 second. The maximum value is one week. 454 455 - Config: download_auth_duration 456 - Env Var: RCLONE_B2_DOWNLOAD_AUTH_DURATION 457 - Type: Duration 458 - Default: 1w 459 460 #### --b2-encoding 461 462 This sets the encoding for the backend. 463 464 See: the [encoding section in the overview](/overview/#encoding) for more info. 465 466 - Config: encoding 467 - Env Var: RCLONE_B2_ENCODING 468 - Type: MultiEncoder 469 - Default: Slash,BackSlash,Del,Ctl,InvalidUtf8,Dot 470 471 <!--- autogenerated options stop --> 472