Software development teams rely on distributed revision control systems to keep from descending into unmanageable chaos. These days, teams often favor web-based revision control platforms offered as Software-as-a-Service (SaaS) products. The data stored on these repositories is the lifeblood of a company, so it's important to keep backups elsewhere. In this tutorial, we will outline a method for mirroring Bitbucket repositories and backing them up in CenturyLink Cloud Object Storage.

Tools Used

CenturyLink Cloud Object Storage offers enterprise-grade object storage. Our cloud servers store and manage your files in a highly-scalable, fault-tolerant, distributed datastore. For large-scale cloud applications, object storage is far more efficient than hierarchical file systems. Learn more about Object Storage.

Bitbucket is a web-based hosting service for software projects using Git or Mercurial revision control systems. It is part of Atlassian's powerful suite of SaaS tools for software development and project management.

Before You Start

If you don’t have a CenturyLink Cloud account yet, head over to our website and sign up for a free trial. You’ll need it to access CenturyLink Object Storage.

This tutorial assumes that you have a Bitbucket account with at least one Git repository to back up. If you don't already have a Bitbucket account, go to and sign up for free.

Install the Bitbucket Command Line Interface (CLI)

The Bitbucket CLI allows you to interact with Bitbucket without visiting the website. The CLI allows you to execute a number of useful operations, such as creating new repositories, managing repository access, or view metadata about your account.

  1. Run the following command to install the Bitbucket CLI.

    sudo pip install bitbucket-cli

  2. In a text editor, create a file called .bitbucket in your home directory.

  3. Edit $HOME/.bitbucket to look like the following, replacing "your-username" and "your-password" with your Bitbucket username and password.

    username = your-username
    password = your-password
  4. Run chmod 0600 $HOME/.bitbucket to restrict permissions on your configuration file.

Create a Bucket to Back Up Your Repositories

Before you can use Object Storage to back up your repositories, you need to add an Object Storage user and bucket.

  1. Go to your CenturyLink Cloud Control Portal at

  2. From the Navigation Menu, click Services > Object Storage.

    The Services pop-up menu

  3. Click the Users tab.

  4. Click Create User. Fill out the form.

    Create a new Object Storage user

    Note: Keep in mind that the email address you use will be unique across the Object Storage platform and cannot be changed or reused with a different CenturyLink Cloud account.

  5. Click save. You will return to the "Users" tab.

  6. Click on the name of the user you just created.

  7. The user screen displays the access key id and secret access key.

    Note: Save these for later! You will need them to configure S3cmd to access Object Storage.

    User information panel

  8. Click on the Buckets tab to create a new Object Storage bucket.

    The Create Bucket panel

  9. Click create bucket.

  10. From the Owner drop-down menu, select the user you created in Step 3.

  11. Record the bucket name, as you will need that to run your backup with S3cmd.

Endpoints, Regions, and Buckets

If you have never used Object Storage or other S3-compatible systems, some of the terminology might be unfamiliar.

  • An object is an individual digital asset. This can be any sort of data, from text to video to images.
  • A bucket is a resource for holding objects. Buckets have simple names consisting of letters, numbers, and some punctuation. Any characters that are valid in a DNS hostname should be valid in a bucket name. You can use new buckets to organize objects for different projects or for customized access control.
  • A region is a data center or cloud service area that hosts Object Storage buckets. One region contains any number of buckets.
  • An endpoint is a hostname that serves the Object Storage API for a region, like a REST API endpoint. Each region has one or more endpoints, and each endpoint belongs to a region.

Throughout this article, we will use the "Canada" region in the examples. However, if you choose to use US-East as the data center for your buckets, you will need to change all references to "" to "".

Object Storage service points and regions

Install and Configure the S3 CLI

We will use S3cmd to copy data into an Object Storage bucket. This handy command line utility was originally built to access Amazon Simple Storage Solution (S3), but it works with any compatible service. Before we configure it to interact with CenturyLike Cloud Object Storage, you will need to install it. Check out the S3cmd website for installation instructions for any Linux or OS X system.

For example, to install S3cmd on an Ubuntu 16.04 system, use the following command:

sudo apt install s3cmd

Next, we need to configure S3cmd to use Object Storage. Follow these instructions:

  1. Run the following command:

    s3cmd --configure

  2. Enter the key and secret key from the Object Storage user creation process.

  3. "Test access with supplied credentials?" appears. Type "no".

  4. "Save settings?" appears. Type "yes". This creates the file .s3cfg in your home directory.

  5. Open ~/.s3cfg in a text editor.

  6. Find the lines starting with host_base and host_bucket. Edit them to look like this:

    host_base =
    host_bucket = %(bucket)

    Configure the S3 CLI

Note: For an in-depth look at installing and configuring S3cmd, check out our Knowledge Base article on the topic.

Downloading Your Bitbucket Repositories

The next step is to mirror all of your Bitbucket repositories.

  1. Create a directory to hold your repository mirrors with the following commands:

    $ mkdir repo-mirrors
    $ cd repo-mirrors
  2. With a text editor, create a file called in the new directory and edit it to look like this:

        REPOS=$(bitbucket list -s git | awk '/git/ { print $3 }')
        for repo in $REPOS
            r=$(echo $repo | sed 's/\// /')
            bitbucket clone $r
  3. Run the new file as a script to mirror all of your Bitbucket repositories with this command:

    bash ./

Sync Your Mirror Directory With Object Storage

Finally, sync your backup directory with your Object Storage bucket.

Run the following command, replacing $MIRROR_DIR with the full path of the directory in which you mirrored your Bitbucket repositories. Replace $BUCKET with the name of your Object Storage bucket from step 12 of "Create a Bucket to Back Up Your Repositories":

s3cmd sync --delete-removed "$MIRROR_DIR" s3://$BUCKET/

Schedule Your Backup with Cron

You can schedule your backup to run automatically using Cron. The following example will schedule a backup to run every Sunday.

  1. Run the following command to open your default text editor and edit your crontab file:

    crontab -e

  2. Edit the file to look like the following example, replacing $MIRROR_DIR with the full path of the directory in which you mirrored your Bitbucket repositories, and $BUCKET with the name of your Object Storage bucket.

    # Backup Bitbucket repositories to Object Storage
    30 7 * * 0 s3cmd sync --delete-removed "$MIRROR_DIR" s3://$BUCKET/

If Cron isn't available on your system, you can use your favorite job scheduler to do something similar.

The Next Step

You have set up a basic backup scheme to mirror your Bitbucket repositories to Object Storage. Now you can customize the solution to address your particular requirements. A more sophisticated script might use all bare Git repositories, or might take advantage of the Bitbucket CLI to mirror both Git and Mercurial repositories.

S3cmd and the Bitbucket CLI are powerful tools for sharing data between cloud services. Be sure to explore our knowledge base and the tool documentation to learn how to unleash their full potential and leverage other hybrid cloud solutions.