How to use Rclone to Back Up to Google Drive on Linux
Rclone is a command-line tool for managing and synchronizing files between different storage services, including Google Drive. Here are the steps to use rclone to back up to Google Drive on Linux:
1 . Installing rclone
On Ubuntu, run this command to install it:
# apt install curl
Once curl has been installed, install rclone with this command
# curl https://rclone.org/install.sh | sudo bash
When the rclone installation has finished, you’ll see a success message
This has installed the rclone program on your Linux computer. The next step is to run through the setup process and authenticate rclone to access your Google Drive.
2. Creating an rclone Remote Connection
Connections to remote cloud services are called “remotes” in the rclone world. We need to create one for Google Drive. Start the rclone configuration process with this command
# rclone config
There are a lot of questions in the configuration process. But don’t be disheartened, many of them can be left at their default values and simply accepted by pressing “Enter.”
rclone tells us there are no remotes configured. Press “n” and press “Enter” to create a new remote. It will prompt you for a name. We’re going to call it “google-drive.” Use whatever name you like.
A long menu allows you to choose the type of storage you’re creating a remote connection to.
Scroll through the list until you see the entry for Google Drive, and make a note of its number.
We can see that in this instance, it is number 18. Enter this as the storage type and press “Enter.”
You’re prompted for a Google Application Client ID. Press “Enter” to accept the default.
You’re then prompted for a Google Application Client Secret.
Again, just press “Enter.” You’re asked to provide the scope that rclone will have when it is operating on your Google Drive. Press “1” and then press “Enter.”
At the “Service Account Credentials” prompt, press “Enter.”
At the “Edit advanced config” prompt, just press “Enter.” At the “Use auto config” menu, press “y” and then press “Enter.”
This causes rclone to communicate to your Google Drive, and to launch your browser to allow you to give permission for rclone to interact with your Google Drive.
In your browser window, click on the Google account you wish to use.
Click the “Allow” button to allow rclone to have access to your Google Drive
When authenticate has completed, you’ll see a “Success!” message in the browser window. You can close the browser and return to the terminal window.
At the “Configure this as a team drive” prompt, type “n” and then press “Enter”
At the “Yes, Edit, Delete” menu type “y” and then press “Enter”
That’s it, you can now test with the directory listing command in the remote connection:
# rclone listremotes
3. Mount Google Drive Locally Using Rclone
In order to access the contents of Google drive from your file manager, you need to mount it first.
Create a mount point to mount your google drive. I am going to create a new mount point named gdrive
# mkdir ~/gdrive
# chmod 775 ~/gdrive/
Next, mount the Google drive using Rclone as shown below:
# rclone mount Greencloud: ~/gdrive/
Here, “Greencloud” is the remote name and “gdrive” is the mount point name. Replace them with your own values.
Click on it to access the contents of your Google drive.
Check it out on your Google Drive and see what happened in our cloud storage.
From now on, you can create, copy, move, rename and delete files/folders as the way you do in your local file manager. Anything you put in the local mount folder (i.e. ~/gdrive folder) will be uploaded to your Google drive.
You can also mount a specific directory/file from the google drive like below.
# rclone mount remote:path/to/files /path/to/local/mount
You can do everything from commandline as well.
4. List google drive contents
To view all files in your Google drive from commandline, run:
# rclone ls Greencloud:
Again, replace “Greencloud” using your own remote name.
To list all directories in the top level, run:
# rclone lsd Greencloud:
5. Copy files and directories to Google drive
For example, to copy a directory from your local system, say “~/test” to a directory called “ostechnix” in your Google drive, run:
# rclone copy ~/test Greencloud:ostechnix
6. Sync files with Google drive
You should use this command with caution. Because, the Destination is updated to match Source, including deleting files if necessary.
Since Synchronization involves deletion on destination, it is always a best practice to first test the Synchronization operation with the –dry-run or the –interactive/-i flag to avoid data loss.
# rclone sync -i SOURCE remote:DESTINATION
Rclone has many other command line options. We will cover them in a separate guide soon.
7. Unmount Google drive
To unmount the Google drive, go to the Terminal window where you run the “
rclone mount” command and simply press
"CTRL+c" to stop the mount.
You can also do it from the file manager as well. From the file manager, right click on the mount point i.e. “gdrive” and click Unmount.
The umount operation may fail, for example when the mount point is busy. When that happens, you can stop the mount manually using command:
# fusermount -u ~/gdrive
In this guide, we looked at how to mount Google drive locally with Rclone in Linux, and two basic operations – how to copy and sync the files from local drive to Google drive.