paint-brush
Automatic backup of git repositories to Dropbox with Pythonby@buklijas.sasa
747 reads
747 reads

Automatic backup of git repositories to Dropbox with Python

by Sasa BuklijasDecember 31st, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

I will show how to <strong>upload files to Dropbox from </strong><a href="https://hackernoon.com/tagged/python" target="_blank"><strong>Python</strong></a> code.
featured image - Automatic backup of git repositories to Dropbox with Python
Sasa Buklijas HackerNoon profile picture

Intro

I will show how to upload files to Dropbox from Python code.

Why do I need this?

Currently, I am only using WebFaction for all my web services and also as my private git server.

I wanted to make an automatic backup of my git repositories to Dropbox.

Dropbox App

I order to upload files to Dropbox you need to have an access token.

And for the access token, you need to register your app on DBX platform.

All of this must be done on Dropbox website.

The first step is to go to https://www.dropbox.com/developers/apps/ and press “Create App” button.

Step 1

Just click “Create app” button

Step 2

We will use Dropbox API.

We will choose “App folder” because we will just upload one backup to Dropbox, we do not need full access to all our files.

Name your app and click “Create App” button.

Step 3

We will use defaults settings, here we will get the access token so, click “Generate access token” button.

Step 4

Now you have your access token, you will need it in your code, so copy it.

Step 5

Now we have our “my_git_backup” Dropbox app.

pip install

pip install dropbox

pip install fabric

It is always recommended to use virtual environments inside python.

At least I use them always.

Code

For code sample please go to http://buklijas.info/blog/2017/12/01/automatic-backup-of-git-repositories-to-dropbox-with-python/

How I run this automatically


I personally run this command from crontab once per day35 02 * * * /home/user_name/code/venv/bin/fab -f /home/user_name/code/fabfile git_backup_to_dropbox

Conclusion

This can be used for backup of any folder as zip file automaticaly to Dropbox.

For any questions, please write them in comments.

Originally published at buklijas.info on December 1, 2017.