/bitbucket_sync

Script for backup up bitbucket repositories that you have access to

Primary LanguagePythonApache License 2.0Apache-2.0

Bitbucket_sync.py

Script for automatic backup copy of the all repositories available to the script (based on OAuth permissions).

Requirements

  • Python requests library
  • Python 2.7+
  • git 1.6.5+

OAuth setup

This is required to grant read access for script to your repositories.

  1. Log in to bitbucket using account you want to back up
  2. Go to Bitbucket settings (in your profile)
  3. In Access Management choose OAuth configuration page
  4. Click Add Consumer and fill the form
    1. Any name, example: Bitbucket Sync
    2. Callback URL can be any url, since we are not using OAuth authorization based on code exchange
    3. Check This is a private consumer
    4. Required permissions are: Account.Read, Team membership.Read, Projects.Read, Repositories.Read
    5. Click Save and go back to OAuth configuration page
  5. Click on your new consumer and you will see Key and Secret credentials, remember them, we will need them to start the script. That's it!

Installation

You can set up requests library manually, using pip install requests command. If you system uses virtualenv, then you can create your virtual environment and target pip to requirements.txt file:

  1. cd path_where_you_store_virtual_env
  2. virtualenv bitbucket_sync_virtualenv
  3. source bitbucket_sync_virtualenv/bin/activate
  4. cd path/to/bitbucket_sync/
  5. pip install -r ./requirements.txt

Make sure that when you run the script the virtualenv is activated.

Run example

python bitbucket_sync.py "/home/user/projects_backup" OauthKey oAutHsEcrEt