Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode
.pyc
.pyc
config.py
7 changes: 7 additions & 0 deletions config.py.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Update this file and rename to config.py
user = "username"
password = "password"
path = "/home/user/bitbucket-archive"

#Set this to true to download the .git repository instead using git clone. NOTE: Requires git to be installed
gitclone = False
23 changes: 17 additions & 6 deletions simple-bitbucket-backup.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import datetime
import os
import errno
import config
import subprocess

bbuser = "username"
bbpass = "password"
storage = "/home/user/bitbucket-archive/"
bbuser = config.user
bbpass = config.password
storage = config.path

now = datetime.datetime.now().strftime("%Y-%m-%d-%H%M")

Expand All @@ -22,7 +24,7 @@ def req(url):
request = urllib.request.Request(
url=url, headers=headers)
response = urllib.request.urlopen(request)
response_data = json.loads(response.read())
response_data = json.loads(response.read().decode('utf-8'))
response.close()
return response_data

Expand Down Expand Up @@ -87,6 +89,15 @@ def do_backup():
backup_path + full_name + '/',
branch + '-' + now + '.zip'
)


do_backup()
def do_clone():
print('cloning...')
repo_list = get_repo_list()
for full_name in repo_list.values():
print(full_name)
subprocess.run(["git", "clone", "https://"+bbuser+":"+bbpass+"@bitbucket.org:/"+full_name+".git", storage+"/"+full_name+".git"])

if config.gitclone:
do_clone()
else:
do_backup()