Backup time: bitbucket backup script

Git is decentralised version control system but let's face it - most likely we use single remote repository. Most likely it's github or bitbucket.

Some people already have learnt the hard way that backups are necessary even for the thing we believe will never break, because, you know, nothing more permanent than temporary.

Recently I was reviewing my backups of important services and noticed that I don't really have a repeatable automated way to archive repositories on Bitbucket. Scaring myself of it I immediately rushed to write a script which does so.

So, requirements for the bitbucket backup script:

  • Must work on Linux(or may be even macos) without any extra dependencies. It must work using only bash + git + tar
  • Created archives should be bz2ipped
  • Backup script must not have write access to the repositories
  • It must include all repositories/teams I was contributing to

On Internet I found a few implementations of such backup scripts, mostly based on this script. Unfortunately, it uses file system for the string manipulation and doesn't archive the copies. I took it as a base and came up with my version:

Who said it's impossible to use bash in the functional style? :)

Configuration

  • BB_USER - your username
  • BB_PASS - application password. Never use your password, read below to see how to generate the application password with restricted permissions
  • DESTINATION - base folder for backups
  • SUFFIX - specific backup's folder name, by default it uses date like "bitbucket-2019-06-02_09:45"

Application Password

It's never good idea to put your actual password, especially in plaintext into the script. Same apply to backup script (even it's on encrypted drive)

To create it open Bitbucket > Settings and navigate to "App Passwords":

Make sure you have checked those checkboxes. Hit "Create" button and you'll get an app password

MacOS?

I'd like to hear if this script works on MacOS - let me know please.