Get the Command-Line Tool

Now that you have created an account, you're ready to get the command-line tool that gives easy access to all of the capabilities of B2 Cloud Storage

The B2 command-line tool is available from the Python Package Index (PyPI) using the standard pip installation tool. Your first step is to make sure that you have either Python 2 (2.6 or later) or Python 3 (3.2 or later) installed.

Installing on Mac (OSX)

You're lucky. Python is already installed by Apple. If you haven't already installed the pip installation tool, you need to install it:

  1. sudo easy_install pip

You'll also need setuptools version 20.2 or higher:

  1. sudo pip install "setuptools>=20.2" --ignore-installed

Once you have Python, the setuptools and the pip command, installation is simple:

  1. sudo pip install --upgrade b2

If you see a message like this, it's because Apple installs a really old version of one of the Python libraries that B2 uses:

  1. OSError: [Errno 1] Operation not permitted: '/tmp/pip-BMa2Su-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info'

You can work around this with the --ignore-installed option:

  1. sudo pip install --upgrade --ignore-installed b2

Installing on Windows

To install Python2, pip, and the B2 command-line tool on Windows:

  1. Go to Python Releases for Windows and select the "Latest Python 2 Release".
  2. Download the "Windows x86-64 MSI installer" or "Windows x86 MSI installer" depending on your Windows operating system.
  3. Run the installer, by default it will install Python to C:\Python27
  4. Edit your PATH environment variable to include C:\Python27\;C:\Python27\Scripts\
  5. Open a command window and type pip install --upgrade b2

Alternative Method

The alternative installation procedure is first make sure that you have Python installed, and then download the latest version of the source code from Github:

  1. git clone https://github.com/Backblaze/B2_Command_Line_Tool.git
  2. cd B2_Command_Line_Tool
  3. python setup.py install

Usage

Once you have the b2 command-line tool installed, you can type "b2" on the command-line to see all of the options.

  This program provides command-line access to the B2 service.

  Usages:

      b2 authorize-account [<applicationKeyId>] [<applicationKey>]
      b2 cancel-all-unfinished-large-files <bucketName>
      b2 cancel-large-file <fileId>
      b2 clear-account
      b2 copy-file-by-id [--metadataDirective [copy|replace]] [--contentType <contentType>] \
               [--info <key>=<value>]* [--range start,end] \
               <sourceFileId> <destinationBucketName> <b2FileName>
      b2 create-bucket [--bucketInfo <json>] [--corsRules <json>] [--lifecycleRules <json>] <bucketName> [allPublic | allPrivate]
      b2 create-key [--duration <validDurationSeconds>] [--bucket <bucketName>] [--namePrefix <namePrefix>] <keyName> <capabilities>
      b2 delete-bucket <bucketName>
      b2 delete-file-version [<fileName>] <fileId>
      b2 delete-key <applicationKeyId>
      b2 download-file-by-id [--noProgress] <fileId> <localFileName>
      b2 download-file-by-name [--noProgress] <bucketName> <fileName> <localFileName>
      b2 get-account-info
      b2 get-bucket [--showSize] <bucketName>
      b2 get-download-auth [--prefix <fileNamePrefix>] [--duration <durationInSeconds>] <bucketName>
      b2 get-download-url-with-auth [--duration <durationInSeconds>] <bucketName> <fileName>
      b2 get-file-info <fileId>
      b2 help [commandName]
      b2 hide-file <bucketName> <fileName>
      b2 list-buckets
      b2 list-file-names <bucketName> [<startFileName>] [<maxToShow>]
      b2 list-file-versions <bucketName> [<startFileName>] [<startFileId>] [<maxToShow>]
      b2 list-keys
      b2 list-parts <largeFileId>
      b2 list-unfinished-large-files <bucketName>
      b2 ls [--long] [--versions] [--recursive] <bucketName> [<folderName>]
      b2 make-url <fileId>
      b2 sync [--delete] [--keepDays N] [--skipNewer] [--replaceNewer] \
          [--compareVersions <option>] [--compareThreshold N] \
          [--threads N] [--noProgress] [--dryRun ] [--allowEmptySource ] \
          [--excludeRegex <regex> [--includeRegex <regex>]] \
          [--excludeDirRegex <regex>] \
          [--excludeAllSymlinks ] \
          <source> <destination>
      b2 update-bucket [--bucketInfo <json>] [--corsRules <json>] [--lifecycleRules <json>] <bucketName> [allPublic | allPrivate]
      b2 upload-file [--sha1 <sha1sum>] [--contentType <contentType>] \
          [--info <key>=<value>]* [--minPartSize N] \
          [--noProgress] [--threads N] <bucketName> <localFilePath> <b2FileName>
      b2 version

  The environment variable B2_ACCOUNT_INFO specifies the sqlite
  file to use for caching authentication information.
  The default file to use is: ~/.b2_account_info

  For more details on one command: b2 help <command>

  When authorizing with application keys, this tool requires that the key
  have the 'listBuckets' capability so that it can take the bucket names
  you provide on the command line and translate them into bucket IDs for the
  B2 Storage service.  Each different command may required additional
  capabilities.  You can find the details for each command in the help for
  that command.

Now that you have the command-line tool, you're ready to make a bucket to hold your files.