Using Duplicity With Google Drive for Backup on macOS

Duplicity uses librsync for incremental backup which is space efficient. When I installed duplicity from homebrew and tried to backup to Google Drive with pydrive, there was always an error that httplib2 module could not be found, even if it was installed already. So I installed duplicity manually and this article records a brief process of configuring and using duplicity with Google Drive on macOS High Sierra.

Install pydrive

As python already comes with macOS, we will just install pip.

$ python -m ensurepip --user
$ python -m pip install --user --upgrade pip
$ python -m pip install --user --upgrade pydrive

Install Duplicity

$ curl -O https://code.launchpad.net/duplicity/0.7-series/0.7.17/+download/duplicity-0.7.17.tar.gz
$ tar xzf duplicity-0.7.17.tar.gz && cd duplicity-0.7.17
$ python -m pip install --user --upgrade -r requirements.txt
$ python setup.py build
$ python setup.py install --user
$ echo "export PATH=$PATH:/Users/$USER/Library/Python/2.7/bin" >> ~/.bash_profile

Configure Google Drive API

Go to Google developer console and create a new project. Next, go to the API overview and enable the Google Drive API. After enabling the Drive API, you will be forwarded to the overview of this API. Click on credentials on the left hand side and configure the OAuth consent screen to your liking. Next, we create a new OAuth Client ID, select other and insert the name for our client. Now, we are presented with a client-id and a client secret.

Configure pydrive

$ touch ~/.pydrive.conf

Add following content to ~/.pydrive.conf.

client_config_backend: settings
client_config:
    client_id: <Client ID>
    client_secret: <Client secret>
save_credentials: True
save_credentials_backend: file
save_credentials_file: ~/.pydrivecreds.json
get_refresh_token: True

Then export pydrive.conf environment variable.

$ export GOOGLE_DRIVE_SETTINGS=/Users/$USER/.pydrive.conf

Now we can use duplicity to backup to Google Drive.

$ duplicity <source_dir> pydrive+gdocs://developer.gserviceaccount.com/<target_dir>
 
comments powered by Disqus