Post

Setup Google Drive in Linux using Rclone

Google Drive does not officially support a Linux client. There are several third party tools and one of them is rclone. It is free and open-source but uses command-line only and require some technical knowledge to setup and use. I’ll try to explain here the step-by-step on how to configure it and what are some basic commands to backup files in Linux to Google Drive.

Install the rclone client

First, install the rclone client.

1
sudo apt install rclone

You can also download and install direct from the rclone site.

Create a developer app in Google Cloud

Next, you need to create a developer app in Google Cloud. In this app, you will create and configure API keys, consent form, scopes of access and other details to basically tell your users, in this case just you, that you are allowing this app to access your Drive and your files. The point of the app is to be able to create API tokens that you can then configure in rclone so that it can access your Google Drive.

Enable the Google Drive API

  1. Login to the Google API Console.
  2. In the left hand navigation menu under Products select APIs & Services - Enabled APIs and Services.
  3. There is a tab labeled ”+ Enable APIs and Services”. Click it and search for the Google Drive API and enable it.
  1. Go to OAuth Consent Screen in the left hand panel.
  2. Click Get Started and add an app name e.g. rclone.
  3. In the support email, enter your email address.
  4. Then choose External in the Audience.
  5. Add another contact email and click Finish.

Create an OAuth Client

  1. In Clients create an OAuth 2.0 Client IDs.
  2. Choose Desktop app as the type.
  3. Name your client e.g. my-rclone-desktop.
  4. A pop-up will show the Client ID and Client Secret. Make a copy of them and save them somewhere else. These are the credentials you will use in rlcone config.

More details and references here.

Configure Google Drive in rclone

In rclone config choose Google Drive as the type of storage. Then follow the steps. It will ask you to use the web browser to authenticate. From there you will see the consent and the credentials will be used and configured.

Refer to this sample.

Test the connectivity

Now let’s test the connectivity with some basic rclone commands.

  1. Make a folder linuxmint in the home directory to store the backup files.

    1
    
     rclone mkdir gdrive:/linuxmint
    
  2. Create a dummy test file and upload in the backup folder.

    1
    2
    
     echo "testing google drive in rclone" > /tmp/my-notes.txt
     rclone copy /tmp/my-notes.txt gdrive:/linuxmint/
    
  3. Verify the backup folder contents.

    1
    2
    3
    4
    
     rclone ls gdrive:/linuxmint
     rclone copyto gdrive:/linuxmint/my-notes.txt /tmp/my-notes-copy.txt
     diff /tmp/my-notes.txt /tmp/my-notes-copy.txt
     cat /tmp/my-notes.txt /tmp/my-notes-copy.txt
    

    Sample output:

    1
    2
    3
    4
    5
    6
    7
    8
    
     rclone ls gdrive:/linuxmint
     $ rclone ls gdrive:/linuxmint
        31 my-notes.txt
     $ rclone copyto gdrive:/linuxmint/my-notes.txt /tmp/my-notes-copy.txt
     $ diff /tmp/my-notes.txt /tmp/my-notes-copy.txt
     $ cat /tmp/my-notes.txt /tmp/my-notes-copy.txt
     testing google drive in rclone
     testing google drive in rclone
    

For reference, here’s a list of rclone commands.

This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.