Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I backup to google drive using duplicity?

I have been trying to get duplicity to backup to google drive. But it looks like it is still using the old client API.

I found some thread saying that the new API should be supported but not much details on how to get it to work.

I got as far as compiling and using duplicity 7.0.3 but then I got this error:

BackendException: GOOGLE_DRIVE_ACCOUNT_KEY environment variable not set. Please read the manpage to fix.

Has anyone set up duplicity to work with Google Drive and know how to do this?

like image 613
AxelOmega Avatar asked Jul 12 '15 16:07

AxelOmega


1 Answers

Now that Google has begun forcing clients to use OAuth, using Google Drive as a backup target has actually gotten very confusing. I found an excellent blog post that walked me through it. The salient steps are:

Install PyDrive

PyDrive is the library that lets Duplicity use OAuth to access Drive.

pip install pydrive

should be sufficient, or you can go through your distribution's package manager.

Create an API token

Navigate to the Google Developer Console and log in. Create a project and select it from the drop-down on the top toolbar.

Choosing duplicity project

Now select the "Enable APIs and Services" button in the Dashboard, which should already be pulled up, but if not, is in the hamburger menu on the left.

Search for and enable the Drive API. After it's enabled, you can actually create the token. Choose "Credentials" from the left navigation bar, and click "Add Credential" > "OAuth 2.0 Client ID." Set the application type to "Other."

Creating credential

After the credential is created, click on it to view the details. Your Client ID and secret will be displayed. Take note of them.

Credential screen

Configure Duplicity

Whew. Time to actually configure the program. Paste the following into a file, replacing your client ID and secret with the ones from the Console above.

client_config_backend: settings  
client_config:  
   client_id: <your client ID>.apps.googleusercontent.com
   client_secret: <your client secret>
save_credentials: True
save_credentials_backend: file
save_credentials_file: gdrive.cache
get_refresh_token: True

(I'm using the excellent Duply frontend, so I saved this as ~/.duply/<server name>/gdrive).

Duplicity needs to be given the name of this file in the GOOGLE_DRIVE_SETTINGS environment variable. So you could invoke duplicity like this:

GOOGLE_DRIVE_SETTINGS=gdrive duplicity <...>

Or if you're using Duply, you can export this variable in the Duply configuration file:

export GOOGLE_DRIVE_SETTINGS=gdrive

Running Duplicity for the first time will begin the OAuth process; you'll be given a link to visit, which will ask permission for the app you created earlier in the Console to access your Drive account. Accept, and it will give you another authentication token to paste back into the terminal. The authorization info will be saved in a .cache file alongside the gdrive settings file.

At this point you should be good to go, and Duplicity should behave normally. Good luck!

like image 153
George Hilliard Avatar answered Sep 28 '22 11:09

George Hilliard