How to Use rclone to Back Up to Google Drive on Linux

How to Use rclone to Back Up to Google Drive on Linux

All

Linux Articles / All 47 Views comments

The Google Drive logo on a terminal window-colored background.
Google

There’s nonetheless no official Linux shopper for Google Drive, however you'll be able to again as much as your Google Drive utilizing the rclone utility proper from the command line. We present you ways.

The place’s Google Drive on Linux?

Regardless of promising Linux support “coming soon” back in 2012, there’s no indication that Google will ever produce a local Linux shopper for Google Drive. There are a number of unofficial third-party options, reminiscent of InSync, overGrive and ODrive, and a few file browsers permit integration together with your Google Drive, corresponding to Files in GNOME.

The third-party purposes are business merchandise, requiring both an outright buy or a subscription. They work properly they don’t value a lot, and actually, overGrive does have a free model, providing restricted performance for no value.

However what if you wish to create and run backups from the command line? Or to include that performance into scripts? That’s all potential because of a tremendous software referred to as rclone. In reality, with rclone you possibly can back up, download, and synchronize files to over forty different cloud solutions. It’s like rsync for clouds.

Putting in rclone

rclone virtually definitely gained’t be put in in your Linux pc by default. Fortunately, there’s an set up script that ought to work on all distributions. The set up course of makes use of curl. On the computer systems used to analysis this text, Fedora 31 and Manjaro 18.1.zero already had curl put in however  curl needed to be put in on Ubuntu 18.04 LTS.

On Ubuntu, run this command to put in it:

sudo apt-get set up curl

sudo apt-get install curl in a terminal window

As soon as curl has been put in, set up rclone with this command:

curl https://rclone.org/set up.sh | sudo bash

curl https://rclone.org/install.sh | sudo bash in a terminal window

When the rclone set up has completed, you’ll see a hit message.

Success message from the rclone installtion script in a terminal window

This has put in the rclone program in your Linux pc. The subsequent step is to run by means of the setup course of and authenticate rclone to entry your Google Drive.

Creating an rclone Distant Connection

Connections to distant cloud providers are referred to as “remotes” within the rclone world. We have to create one for Google Drive. Begin the rclone configuration course of with this command:

rclone config

rclone config in a terminal window

There are a whole lot of questions within the configuration course of. However don’t be disheartened, lots of them could be left at their default values and easily accepted by urgent “Enter.”

rclone tells us there are not any remotes configured. Press “n” and press “Enter” to create a brand new distant. It should immediate you for a reputation. We’re going to name it “google-drive.” Use no matter identify you want.

rclone menu to create a new remote, in a terminal window

An extended menu lets you select the kind of storage you’re making a distant connection to.

rclone remote connection type menu in a terminal window

Scroll via the record till you see the entry for Google Drive, and make a remark of its quantity.

rclone config in a terminal window

We will see that on this occasion, it's quantity 13. Enter this because the storage sort and press “Enter.”

Setting the rclone storage type in a terminal window

You’re prompted for a Google Software Shopper ID. Press “Enter” to simply accept the default.

Prompt for a Google application client id in a terminal window

You’re then prompted for a Google Software Shopper Secret.

prompt for a Google application client secret in a terminal window

Once more, simply press “Enter.” You’re requested to offer the scope that rclone may have when it's working in your Google Drive. Press “1” after which press “Enter.”

providing the scope for rclone in a terminal window

For the “ID of the basis folder”, simply press “Enter.”

prompt for root folder ID ina terminal window

On the “Service Account Credentials” immediate, press “Enter.”

Prompt for Service Account Credentials in a terminal window

On the “Edit superior config”  immediate, simply press “Enter.” On the “Use auto config” menu, press “y” after which press “Enter.”

The "use auto config" menu in a terminal window

This causes rclone to speak to your Google Drive, and to launch your browser to help you give permission for rclone to work together together with your Google Drive.

rclone about to launch a browser, in a terminal window

In your browser window, click on on the Google account you want to use.

Choosing the Google account to use in a browser window

Click on the “Permit” button to permit rclone to have entry to your Google Drive.

Allowing rclone to work with Google Drive in a terminal window

When authenticate has accomplished, you’ll see a “Success!” message within the browser window. You'll be able to shut the browser and return to the terminal window.

Success message in a browser window

On the “Configure this as a staff drive” immediate, sort “n” after which press “Enter.”

The rclone "configure this as a team drive" prompt in a terminal window

On the “Sure, Edit, Delete” menu sort “y” after which press “Enter.”

The rclone "yes,edit, delete" menu in a terminal window

On the remaining menu, sort “q” and press “Enter.”

The rclone final menu in a terminal window

The rclone Again Up Script

The rclone software could be very feature-rich. That’s nice, nevertheless it does imply there are a lot of options. The command we’re going to take a look at under copies information out of your native pc to your Google Drive. This can be a one-way copy to the cloud; it isn’t a two-way synchronization between your Google Drive and your native pc—though rclone can do this. We’re utilizing this as a primary type of off-site backup.

Sort (or copy and paste) this right into a textual content editor and reserve it to your pc. We referred to as it gbk.sh. You possibly can name it no matter is sensible to you.

#!/bin/bash

/usr/bin/rclone copy --update --verbose --transfers 30 --checkers eight --contimeout 60s --timeout 300s --retries three --low-level-retries 10 --stats 1s "/residence/dave/Paperwork" "google-drive:LinuxDocs"

Right here’s what the parameters imply:

  • copy: Copy the information from the native pc to the distant storage, skipping over information which are already current on the distant storage.
  • –replace: Skip any information which might be on the distant storage which have a modified time that's newer than the file on the native pc.
  • –verbose: Provides details about each file that's transferred.
  • –transfers 30: This units the variety of information to repeat in parallel.
  • –checkers eight: What number of “checkers” to run in parallel. Checkers monitor the transfers which are in progress.,
  • –contimeout 60s: The connection timeout. It units the time that rclone will attempt to make a connection to the distant storage.
  • –timeout 300s: If a switch turns into idle for this period of time, it's thought-about damaged and is disconnected.
  • –retries three: If there are this many errors, all the copy motion can be restarted.
  • –low-level-retries 10: A low-level retry tries to repeat one failing operation, similar to a single HTTP request. This worth units the restrict for the variety of retries.
  • –stats 1s: rclone can present statistics on the transferred information. This units the frequency of replace of the statistics to at least one second.
  • “/residence/dave/Paperwork”: The native listing to we’re going to repeat to the distant storage.
  • “google-drive:LinuxDocs”: The vacation spot listing within the distant storage. Notice using “google-drive”, which is the identify we gave to this distant connection through the the rclone config sequence. Additionally observe the colon “:” that's used as a separator between the distant storage identify and the listing identify. Subdirectories are separated by the standard “/” ahead slash. If the vacation spot listing doesn't exist, it is going to be created.

A few of these values are the defaults, however we’ve included them right here in order that we will talk about them. That method, if you could change a worth, you already know which parameter to regulate.

Make the script executable with this command:

chmod +x gbk.sh

Operating the Again Up Script

Our again up script goes to repeat our Paperwork folder to our Google Drive. In our Paperwork folder, we’ve acquired a set of sheet music.

Collection of sheet music in ~/Documents in a file browser

We will launch the again up script with this command:

./gbk.sh

./gbk.sh in a terminal window

We requested for statistics updates each one second (--stats 1s), and we additionally requested for verbose output (--verbose). It’ll come as no shock then that we get plenty of display output. It’s often a superb choice to activate verbose output for brand spanking new performance as a way to spot issues. You'll be able to flip down the quantity of output when you’re completely satisfied issues are operating easily.

rclone output in a terminal window

We get a last abstract telling us 60 information have been transferred with no errors. The switch took roughly 24 seconds.

Let’s examine on our Google Drive and see what occurred in our cloud storage.

LinuxDocs folder in Google Drive

A “LinuxDocs” listing has been created, so that appears promising. If we double-click it to have a look inside, we will see that the information have all been transferred to our Google Drive.

Files in "LinuxDocs" on Google Drive

Utilizing rclone to View Information On Google Drive

We will use rclone to peek into the folder on Google Drive, proper from the terminal window:

rclone ls google-drive:/LinuxDocs

rclone ls google-drive:/LinuxDocs in a terminal window

The Tip of the Iceberg

That’s nice that we will carry out such a copy straight from the command line. We will incorporate using our cloud storage into scripts, and we might schedule the execution of back up scripts utilizing cron.

rclone has an absolute wealth of instructions, you’re inspired to check out their documentation and excellent website. We’ve barely scratched the floor right here, and a little bit of studying and enjoying with rclone can pay again the trouble many occasions over.

Strictly talking, this isn’t a real backup. It's an off-site, distant copy of your information and knowledge, which is certainly an excellent factor to have, however it's only a copy of information. It doesn’t supply versioning or different options that true backup options would supply.

So use rclone at the side of different backup methods. As one other layer to an present backup regime rclone is a simple solution to get your knowledge saved in a location that's geographically faraway from your own home or workplace. And that’s acquired to be an excellent factor.

Comments