github.com/rclone/rclone@v1.66.1-0.20240517100346-7b89735ae726/docs/content/b2.md (about) 1 --- 2 title: "B2" 3 description: "Backblaze B2" 4 versionIntroduced: "v1.26" 5 --- 6 7 # {{< icon "fa fa-fire" >}} Backblaze B2 8 9 B2 is [Backblaze's cloud storage system](https://www.backblaze.com/b2/). 10 11 Paths are specified as `remote:bucket` (or `remote:` for the `lsd` 12 command.) You may put subdirectories in too, e.g. `remote:bucket/path/to/dir`. 13 14 ## Configuration 15 16 Here is an example of making a b2 configuration. First run 17 18 rclone config 19 20 This will guide you through an interactive setup process. To authenticate 21 you will either need your Account ID (a short hex number) and Master 22 Application Key (a long hex number) OR an Application Key, which is the 23 recommended method. See below for further details on generating and using 24 an Application Key. 25 26 ``` 27 No remotes found, make a new one? 28 n) New remote 29 q) Quit config 30 n/q> n 31 name> remote 32 Type of storage to configure. 33 Choose a number from below, or type in your own value 34 [snip] 35 XX / Backblaze B2 36 \ "b2" 37 [snip] 38 Storage> b2 39 Account ID or Application Key ID 40 account> 123456789abc 41 Application Key 42 key> 0123456789abcdef0123456789abcdef0123456789 43 Endpoint for the service - leave blank normally. 44 endpoint> 45 Remote config 46 -------------------- 47 [remote] 48 account = 123456789abc 49 key = 0123456789abcdef0123456789abcdef0123456789 50 endpoint = 51 -------------------- 52 y) Yes this is OK 53 e) Edit this remote 54 d) Delete this remote 55 y/e/d> y 56 ``` 57 58 This remote is called `remote` and can now be used like this 59 60 See all buckets 61 62 rclone lsd remote: 63 64 Create a new bucket 65 66 rclone mkdir remote:bucket 67 68 List the contents of a bucket 69 70 rclone ls remote:bucket 71 72 Sync `/home/local/directory` to the remote bucket, deleting any 73 excess files in the bucket. 74 75 rclone sync --interactive /home/local/directory remote:bucket 76 77 ### Application Keys 78 79 B2 supports multiple [Application Keys for different access permission 80 to B2 Buckets](https://www.backblaze.com/b2/docs/application_keys.html). 81 82 You can use these with rclone too; you will need to use rclone version 1.43 83 or later. 84 85 Follow Backblaze's docs to create an Application Key with the required 86 permission and add the `applicationKeyId` as the `account` and the 87 `Application Key` itself as the `key`. 88 89 Note that you must put the _applicationKeyId_ as the `account` – you 90 can't use the master Account ID. If you try then B2 will return 401 91 errors. 92 93 ### --fast-list 94 95 This remote supports `--fast-list` which allows you to use fewer 96 transactions in exchange for more memory. See the [rclone 97 docs](/docs/#fast-list) for more details. 98 99 ### Modification times 100 101 The modification time is stored as metadata on the object as 102 `X-Bz-Info-src_last_modified_millis` as milliseconds since 1970-01-01 103 in the Backblaze standard. Other tools should be able to use this as 104 a modified time. 105 106 Modified times are used in syncing and are fully supported. Note that 107 if a modification time needs to be updated on an object then it will 108 create a new version of the object. 109 110 ### Restricted filename characters 111 112 In addition to the [default restricted characters set](/overview/#restricted-characters) 113 the following characters are also replaced: 114 115 | Character | Value | Replacement | 116 | --------- |:-----:|:-----------:| 117 | \ | 0x5C | \ | 118 119 Invalid UTF-8 bytes will also be [replaced](/overview/#invalid-utf8), 120 as they can't be used in JSON strings. 121 122 Note that in 2020-05 Backblaze started allowing \ characters in file 123 names. Rclone hasn't changed its encoding as this could cause syncs to 124 re-transfer files. If you want rclone not to replace \ then see the 125 `--b2-encoding` flag below and remove the `BackSlash` from the 126 string. This can be set in the config. 127 128 ### SHA1 checksums 129 130 The SHA1 checksums of the files are checked on upload and download and 131 will be used in the syncing process. 132 133 Large files (bigger than the limit in `--b2-upload-cutoff`) which are 134 uploaded in chunks will store their SHA1 on the object as 135 `X-Bz-Info-large_file_sha1` as recommended by Backblaze. 136 137 For a large file to be uploaded with an SHA1 checksum, the source 138 needs to support SHA1 checksums. The local disk supports SHA1 139 checksums so large file transfers from local disk will have an SHA1. 140 See [the overview](/overview/#features) for exactly which remotes 141 support SHA1. 142 143 Sources which don't support SHA1, in particular `crypt` will upload 144 large files without SHA1 checksums. This may be fixed in the future 145 (see [#1767](https://github.com/rclone/rclone/issues/1767)). 146 147 Files sizes below `--b2-upload-cutoff` will always have an SHA1 148 regardless of the source. 149 150 ### Transfers 151 152 Backblaze recommends that you do lots of transfers simultaneously for 153 maximum speed. In tests from my SSD equipped laptop the optimum 154 setting is about `--transfers 32` though higher numbers may be used 155 for a slight speed improvement. The optimum number for you may vary 156 depending on your hardware, how big the files are, how much you want 157 to load your computer, etc. The default of `--transfers 4` is 158 definitely too low for Backblaze B2 though. 159 160 Note that uploading big files (bigger than 200 MiB by default) will use 161 a 96 MiB RAM buffer by default. There can be at most `--transfers` of 162 these in use at any moment, so this sets the upper limit on the memory 163 used. 164 165 ### Versions 166 167 When rclone uploads a new version of a file it creates a [new version 168 of it](https://www.backblaze.com/b2/docs/file_versions.html). 169 Likewise when you delete a file, the old version will be marked hidden 170 and still be available. Conversely, you may opt in to a "hard delete" 171 of files with the `--b2-hard-delete` flag which would permanently remove 172 the file instead of hiding it. 173 174 Old versions of files, where available, are visible using the 175 `--b2-versions` flag. 176 177 It is also possible to view a bucket as it was at a certain point in time, 178 using the `--b2-version-at` flag. This will show the file versions as they 179 were at that time, showing files that have been deleted afterwards, and 180 hiding files that were created since. 181 182 If you wish to remove all the old versions, and unfinished large file 183 uploads, then you can use the `rclone cleanup remote:bucket` command 184 which will delete all the old versions of files, leaving the current ones 185 intact. You can also supply a path and only old versions under that path 186 will be deleted, e.g. `rclone cleanup remote:bucket/path/to/stuff`. 187 188 Note that `cleanup` will remove partially uploaded files from the bucket 189 if they are more than a day old. If you want more control over the 190 expiry date then run `rclone backend cleanup b2:bucket -o max-age=1h` 191 to remove all unfinished large file uploads older than one hour, leaving 192 old versions intact. 193 194 If you wish to remove all the old versions, leaving current files and 195 unfinished large files intact, then you can use the 196 [`rclone backend cleanup-hidden remote:bucket`](#cleanup-hidden) 197 command. You can also supply a path and only old versions under that 198 path will be deleted, e.g. 199 `rclone backend cleanup-hidden remote:bucket/path/to/stuff`. 200 201 When you `purge` a bucket, the current and the old versions will be 202 deleted then the bucket will be deleted. 203 204 However `delete` will cause the current versions of the files to 205 become hidden old versions. 206 207 Here is a session showing the listing and retrieval of an old 208 version followed by a `cleanup` of the old versions. 209 210 Show current version and all the versions with `--b2-versions` flag. 211 212 ``` 213 $ rclone -q ls b2:cleanup-test 214 9 one.txt 215 216 $ rclone -q --b2-versions ls b2:cleanup-test 217 9 one.txt 218 8 one-v2016-07-04-141032-000.txt 219 16 one-v2016-07-04-141003-000.txt 220 15 one-v2016-07-02-155621-000.txt 221 ``` 222 223 Retrieve an old version 224 225 ``` 226 $ rclone -q --b2-versions copy b2:cleanup-test/one-v2016-07-04-141003-000.txt /tmp 227 228 $ ls -l /tmp/one-v2016-07-04-141003-000.txt 229 -rw-rw-r-- 1 ncw ncw 16 Jul 2 17:46 /tmp/one-v2016-07-04-141003-000.txt 230 ``` 231 232 Clean up all the old versions and show that they've gone. 233 234 ``` 235 $ rclone -q cleanup b2:cleanup-test 236 237 $ rclone -q ls b2:cleanup-test 238 9 one.txt 239 240 $ rclone -q --b2-versions ls b2:cleanup-test 241 9 one.txt 242 ``` 243 244 #### Versions naming caveat 245 246 When using `--b2-versions` flag rclone is relying on the file name 247 to work out whether the objects are versions or not. Versions' names 248 are created by inserting timestamp between file name and its extension. 249 ``` 250 9 file.txt 251 8 file-v2023-07-17-161032-000.txt 252 16 file-v2023-06-15-141003-000.txt 253 ``` 254 If there are real files present with the same names as versions, then 255 behaviour of `--b2-versions` can be unpredictable. 256 257 ### Data usage 258 259 It is useful to know how many requests are sent to the server in different scenarios. 260 261 All copy commands send the following 4 requests: 262 263 ``` 264 /b2api/v1/b2_authorize_account 265 /b2api/v1/b2_create_bucket 266 /b2api/v1/b2_list_buckets 267 /b2api/v1/b2_list_file_names 268 ``` 269 270 The `b2_list_file_names` request will be sent once for every 1k files 271 in the remote path, providing the checksum and modification time of 272 the listed files. As of version 1.33 issue 273 [#818](https://github.com/rclone/rclone/issues/818) causes extra requests 274 to be sent when using B2 with Crypt. When a copy operation does not 275 require any files to be uploaded, no more requests will be sent. 276 277 Uploading files that do not require chunking, will send 2 requests per 278 file upload: 279 280 ``` 281 /b2api/v1/b2_get_upload_url 282 /b2api/v1/b2_upload_file/ 283 ``` 284 285 Uploading files requiring chunking, will send 2 requests (one each to 286 start and finish the upload) and another 2 requests for each chunk: 287 288 ``` 289 /b2api/v1/b2_start_large_file 290 /b2api/v1/b2_get_upload_part_url 291 /b2api/v1/b2_upload_part/ 292 /b2api/v1/b2_finish_large_file 293 ``` 294 295 #### Versions 296 297 Versions can be viewed with the `--b2-versions` flag. When it is set 298 rclone will show and act on older versions of files. For example 299 300 Listing without `--b2-versions` 301 302 ``` 303 $ rclone -q ls b2:cleanup-test 304 9 one.txt 305 ``` 306 307 And with 308 309 ``` 310 $ rclone -q --b2-versions ls b2:cleanup-test 311 9 one.txt 312 8 one-v2016-07-04-141032-000.txt 313 16 one-v2016-07-04-141003-000.txt 314 15 one-v2016-07-02-155621-000.txt 315 ``` 316 317 Showing that the current version is unchanged but older versions can 318 be seen. These have the UTC date that they were uploaded to the 319 server to the nearest millisecond appended to them. 320 321 Note that when using `--b2-versions` no file write operations are 322 permitted, so you can't upload files or delete them. 323 324 ### B2 and rclone link 325 326 Rclone supports generating file share links for private B2 buckets. 327 They can either be for a file for example: 328 329 ``` 330 ./rclone link B2:bucket/path/to/file.txt 331 https://f002.backblazeb2.com/file/bucket/path/to/file.txt?Authorization=xxxxxxxx 332 333 ``` 334 335 or if run on a directory you will get: 336 337 ``` 338 ./rclone link B2:bucket/path 339 https://f002.backblazeb2.com/file/bucket/path?Authorization=xxxxxxxx 340 ``` 341 342 you can then use the authorization token (the part of the url from the 343 `?Authorization=` on) on any file path under that directory. For example: 344 345 ``` 346 https://f002.backblazeb2.com/file/bucket/path/to/file1?Authorization=xxxxxxxx 347 https://f002.backblazeb2.com/file/bucket/path/file2?Authorization=xxxxxxxx 348 https://f002.backblazeb2.com/file/bucket/path/folder/file3?Authorization=xxxxxxxx 349 350 ``` 351 352 {{< rem autogenerated options start" - DO NOT EDIT - instead edit fs.RegInfo in backend/b2/b2.go then run make backenddocs" >}} 353 ### Standard options 354 355 Here are the Standard options specific to b2 (Backblaze B2). 356 357 #### --b2-account 358 359 Account ID or Application Key ID. 360 361 Properties: 362 363 - Config: account 364 - Env Var: RCLONE_B2_ACCOUNT 365 - Type: string 366 - Required: true 367 368 #### --b2-key 369 370 Application Key. 371 372 Properties: 373 374 - Config: key 375 - Env Var: RCLONE_B2_KEY 376 - Type: string 377 - Required: true 378 379 #### --b2-hard-delete 380 381 Permanently delete files on remote removal, otherwise hide files. 382 383 Properties: 384 385 - Config: hard_delete 386 - Env Var: RCLONE_B2_HARD_DELETE 387 - Type: bool 388 - Default: false 389 390 ### Advanced options 391 392 Here are the Advanced options specific to b2 (Backblaze B2). 393 394 #### --b2-endpoint 395 396 Endpoint for the service. 397 398 Leave blank normally. 399 400 Properties: 401 402 - Config: endpoint 403 - Env Var: RCLONE_B2_ENDPOINT 404 - Type: string 405 - Required: false 406 407 #### --b2-test-mode 408 409 A flag string for X-Bz-Test-Mode header for debugging. 410 411 This is for debugging purposes only. Setting it to one of the strings 412 below will cause b2 to return specific errors: 413 414 * "fail_some_uploads" 415 * "expire_some_account_authorization_tokens" 416 * "force_cap_exceeded" 417 418 These will be set in the "X-Bz-Test-Mode" header which is documented 419 in the [b2 integrations checklist](https://www.backblaze.com/b2/docs/integration_checklist.html). 420 421 Properties: 422 423 - Config: test_mode 424 - Env Var: RCLONE_B2_TEST_MODE 425 - Type: string 426 - Required: false 427 428 #### --b2-versions 429 430 Include old versions in directory listings. 431 432 Note that when using this no file write operations are permitted, 433 so you can't upload files or delete them. 434 435 Properties: 436 437 - Config: versions 438 - Env Var: RCLONE_B2_VERSIONS 439 - Type: bool 440 - Default: false 441 442 #### --b2-version-at 443 444 Show file versions as they were at the specified time. 445 446 Note that when using this no file write operations are permitted, 447 so you can't upload files or delete them. 448 449 Properties: 450 451 - Config: version_at 452 - Env Var: RCLONE_B2_VERSION_AT 453 - Type: Time 454 - Default: off 455 456 #### --b2-upload-cutoff 457 458 Cutoff for switching to chunked upload. 459 460 Files above this size will be uploaded in chunks of "--b2-chunk-size". 461 462 This value should be set no larger than 4.657 GiB (== 5 GB). 463 464 Properties: 465 466 - Config: upload_cutoff 467 - Env Var: RCLONE_B2_UPLOAD_CUTOFF 468 - Type: SizeSuffix 469 - Default: 200Mi 470 471 #### --b2-copy-cutoff 472 473 Cutoff for switching to multipart copy. 474 475 Any files larger than this that need to be server-side copied will be 476 copied in chunks of this size. 477 478 The minimum is 0 and the maximum is 4.6 GiB. 479 480 Properties: 481 482 - Config: copy_cutoff 483 - Env Var: RCLONE_B2_COPY_CUTOFF 484 - Type: SizeSuffix 485 - Default: 4Gi 486 487 #### --b2-chunk-size 488 489 Upload chunk size. 490 491 When uploading large files, chunk the file into this size. 492 493 Must fit in memory. These chunks are buffered in memory and there 494 might a maximum of "--transfers" chunks in progress at once. 495 496 5,000,000 Bytes is the minimum size. 497 498 Properties: 499 500 - Config: chunk_size 501 - Env Var: RCLONE_B2_CHUNK_SIZE 502 - Type: SizeSuffix 503 - Default: 96Mi 504 505 #### --b2-upload-concurrency 506 507 Concurrency for multipart uploads. 508 509 This is the number of chunks of the same file that are uploaded 510 concurrently. 511 512 Note that chunks are stored in memory and there may be up to 513 "--transfers" * "--b2-upload-concurrency" chunks stored at once 514 in memory. 515 516 Properties: 517 518 - Config: upload_concurrency 519 - Env Var: RCLONE_B2_UPLOAD_CONCURRENCY 520 - Type: int 521 - Default: 4 522 523 #### --b2-disable-checksum 524 525 Disable checksums for large (> upload cutoff) files. 526 527 Normally rclone will calculate the SHA1 checksum of the input before 528 uploading it so it can add it to metadata on the object. This is great 529 for data integrity checking but can cause long delays for large files 530 to start uploading. 531 532 Properties: 533 534 - Config: disable_checksum 535 - Env Var: RCLONE_B2_DISABLE_CHECKSUM 536 - Type: bool 537 - Default: false 538 539 #### --b2-download-url 540 541 Custom endpoint for downloads. 542 543 This is usually set to a Cloudflare CDN URL as Backblaze offers 544 free egress for data downloaded through the Cloudflare network. 545 Rclone works with private buckets by sending an "Authorization" header. 546 If the custom endpoint rewrites the requests for authentication, 547 e.g., in Cloudflare Workers, this header needs to be handled properly. 548 Leave blank if you want to use the endpoint provided by Backblaze. 549 550 The URL provided here SHOULD have the protocol and SHOULD NOT have 551 a trailing slash or specify the /file/bucket subpath as rclone will 552 request files with "{download_url}/file/{bucket_name}/{path}". 553 554 Example: 555 > https://mysubdomain.mydomain.tld 556 (No trailing "/", "file" or "bucket") 557 558 Properties: 559 560 - Config: download_url 561 - Env Var: RCLONE_B2_DOWNLOAD_URL 562 - Type: string 563 - Required: false 564 565 #### --b2-download-auth-duration 566 567 Time before the public link authorization token will expire in s or suffix ms|s|m|h|d. 568 569 This is used in combination with "rclone link" for making files 570 accessible to the public and sets the duration before the download 571 authorization token will expire. 572 573 The minimum value is 1 second. The maximum value is one week. 574 575 Properties: 576 577 - Config: download_auth_duration 578 - Env Var: RCLONE_B2_DOWNLOAD_AUTH_DURATION 579 - Type: Duration 580 - Default: 1w 581 582 #### --b2-memory-pool-flush-time 583 584 How often internal memory buffer pools will be flushed. (no longer used) 585 586 Properties: 587 588 - Config: memory_pool_flush_time 589 - Env Var: RCLONE_B2_MEMORY_POOL_FLUSH_TIME 590 - Type: Duration 591 - Default: 1m0s 592 593 #### --b2-memory-pool-use-mmap 594 595 Whether to use mmap buffers in internal memory pool. (no longer used) 596 597 Properties: 598 599 - Config: memory_pool_use_mmap 600 - Env Var: RCLONE_B2_MEMORY_POOL_USE_MMAP 601 - Type: bool 602 - Default: false 603 604 #### --b2-lifecycle 605 606 Set the number of days deleted files should be kept when creating a bucket. 607 608 On bucket creation, this parameter is used to create a lifecycle rule 609 for the entire bucket. 610 611 If lifecycle is 0 (the default) it does not create a lifecycle rule so 612 the default B2 behaviour applies. This is to create versions of files 613 on delete and overwrite and to keep them indefinitely. 614 615 If lifecycle is >0 then it creates a single rule setting the number of 616 days before a file that is deleted or overwritten is deleted 617 permanently. This is known as daysFromHidingToDeleting in the b2 docs. 618 619 The minimum value for this parameter is 1 day. 620 621 You can also enable hard_delete in the config also which will mean 622 deletions won't cause versions but overwrites will still cause 623 versions to be made. 624 625 See: [rclone backend lifecycle](#lifecycle) for setting lifecycles after bucket creation. 626 627 628 Properties: 629 630 - Config: lifecycle 631 - Env Var: RCLONE_B2_LIFECYCLE 632 - Type: int 633 - Default: 0 634 635 #### --b2-encoding 636 637 The encoding for the backend. 638 639 See the [encoding section in the overview](/overview/#encoding) for more info. 640 641 Properties: 642 643 - Config: encoding 644 - Env Var: RCLONE_B2_ENCODING 645 - Type: Encoding 646 - Default: Slash,BackSlash,Del,Ctl,InvalidUtf8,Dot 647 648 #### --b2-description 649 650 Description of the remote 651 652 Properties: 653 654 - Config: description 655 - Env Var: RCLONE_B2_DESCRIPTION 656 - Type: string 657 - Required: false 658 659 ## Backend commands 660 661 Here are the commands specific to the b2 backend. 662 663 Run them with 664 665 rclone backend COMMAND remote: 666 667 The help below will explain what arguments each command takes. 668 669 See the [backend](/commands/rclone_backend/) command for more 670 info on how to pass options and arguments. 671 672 These can be run on a running backend using the rc command 673 [backend/command](/rc/#backend-command). 674 675 ### lifecycle 676 677 Read or set the lifecycle for a bucket 678 679 rclone backend lifecycle remote: [options] [<arguments>+] 680 681 This command can be used to read or set the lifecycle for a bucket. 682 683 Usage Examples: 684 685 To show the current lifecycle rules: 686 687 rclone backend lifecycle b2:bucket 688 689 This will dump something like this showing the lifecycle rules. 690 691 [ 692 { 693 "daysFromHidingToDeleting": 1, 694 "daysFromUploadingToHiding": null, 695 "fileNamePrefix": "" 696 } 697 ] 698 699 If there are no lifecycle rules (the default) then it will just return []. 700 701 To reset the current lifecycle rules: 702 703 rclone backend lifecycle b2:bucket -o daysFromHidingToDeleting=30 704 rclone backend lifecycle b2:bucket -o daysFromUploadingToHiding=5 -o daysFromHidingToDeleting=1 705 706 This will run and then print the new lifecycle rules as above. 707 708 Rclone only lets you set lifecycles for the whole bucket with the 709 fileNamePrefix = "". 710 711 You can't disable versioning with B2. The best you can do is to set 712 the daysFromHidingToDeleting to 1 day. You can enable hard_delete in 713 the config also which will mean deletions won't cause versions but 714 overwrites will still cause versions to be made. 715 716 rclone backend lifecycle b2:bucket -o daysFromHidingToDeleting=1 717 718 See: https://www.backblaze.com/docs/cloud-storage-lifecycle-rules 719 720 721 Options: 722 723 - "daysFromHidingToDeleting": After a file has been hidden for this many days it is deleted. 0 is off. 724 - "daysFromUploadingToHiding": This many days after uploading a file is hidden 725 726 ### cleanup 727 728 Remove unfinished large file uploads. 729 730 rclone backend cleanup remote: [options] [<arguments>+] 731 732 This command removes unfinished large file uploads of age greater than 733 max-age, which defaults to 24 hours. 734 735 Note that you can use --interactive/-i or --dry-run with this command to see what 736 it would do. 737 738 rclone backend cleanup b2:bucket/path/to/object 739 rclone backend cleanup -o max-age=7w b2:bucket/path/to/object 740 741 Durations are parsed as per the rest of rclone, 2h, 7d, 7w etc. 742 743 744 Options: 745 746 - "max-age": Max age of upload to delete 747 748 ### cleanup-hidden 749 750 Remove old versions of files. 751 752 rclone backend cleanup-hidden remote: [options] [<arguments>+] 753 754 This command removes any old hidden versions of files. 755 756 Note that you can use --interactive/-i or --dry-run with this command to see what 757 it would do. 758 759 rclone backend cleanup-hidden b2:bucket/path/to/dir 760 761 762 {{< rem autogenerated options stop >}} 763 764 ## Limitations 765 766 `rclone about` is not supported by the B2 backend. Backends without 767 this capability cannot determine free space for an rclone mount or 768 use policy `mfs` (most free space) as a member of an rclone union 769 remote. 770 771 See [List of backends that do not support rclone about](https://rclone.org/overview/#optional-features) and [rclone about](https://rclone.org/commands/rclone_about/) 772 773