CWP Integration with Google Drive
There's still no official Linux client for Google Drive, but you can back up to your Google Drive using the rclone
utility right from the command line.
We show you how.
Where is Google Drive on Linux?
Despite promising Linux support 'coming soon' back in 2012, there's no indication that Google will ever produce a native Linux client for Google Drive.
There are several unofficial third-party solutions, such as InSync, overGrive and ODrive, and some file browsers allow integration with your Google Drive, such as Files in GNOME.
The third-party applications are commercial products, requiring either an outright purchase or a subscription. They work well they don't cost much, and in fact, overGrive does have a free version, offering limited functionality for no cost.
But what if you want to create and run backups from the command line? Or to incorporate that functionality into scripts? That's all possible thanks to an amazing application called rclone
.
In fact, with rclone
you can back up, download, and synchronize files to over forty different cloud solutions.
Its like rsync for clouds.
The rclone
application is very feature-rich.
Thats great, but it does mean there are a lot of options.
How to Use rclone to Back Up to Google Drive on Linux
Installing rclone
rclone
almost certainly wont be installed on your Linux computer by default. Happily, with dnf, it's pretty simple.
To install rclone on CentOS 8.x, log in to your server instance with SSH as root user and run the commands as explained below:
(epel Repository must be Installed and Enabled)
Run: sudo dnf install rclone
When Complete you should see:
This has installed the rclone
program on your CentOS VPS/Server.
The next step is to run through the setup process and authenticate rclone
to access your Google Drive.
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 dont 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.
--
After this, you will see a long menu allows you to choose the type of storage youre creating a remote connection to.
(In this KB Article, we only cover Google Drive.)
Press "15" for Google Drive
--
After you will see:
You'll be prompted for a Google Application Client ID and OAuth Client Secret.
Press Enter to accept the default.
You'll be asked to provide the scope that rclone
will have when it is operating on your Google Drive.
Press 1 and then Press Enter for (Full access all files, excluding Application Data Folder.)
--
At the "ID of the root folder" prompt, Press Enter for the default.
--
--
At the "Edit advanced config" prompt, Press Enter for the default.
--
--
You will be prompted "Please go to the following link: https://accounts.google.com/o/oauth2/..." (Edited for security)
Log in and authorize rclone for access
Enter verification code.
--
Open a browser on your local computer, and paste the link from the SSH terminal window.
Select the Google account you want used.
--
Click the Allow button to allow rclone
to have access to your Google Drive.
--
Copy the code to paste into the SSH terminal window: "Enter verification code>"
--
At the "Configure this as a Shared Drive (Team Drive)" prompt, Press Enter for the default.
--
At the prompt, Press Enter for the default.
--
At the "Current remotes" prompt, Press q and then press Enter
You will be back to the system prompt.
You can view the list of configured remotes at any time by using the following command:
rclone listremotes
--
Mount Google Drive Locally As Virtual File System Using rclone
You can then use it like this, List directories in top level of your Google drive: rclone lsd google-drive:
Create a Local Directory mount point for Google Drive files: mkdir ~/site-backup
(Directory can be any name you want it to be.)
Create the directory on Google Drive: rclone mkdir google-drive:/site-backup/
Then, mount Google Drive using the command: rclone mount google-drive:/site-backup/ ~/site-backup/
To copy a local directory to a drive directory called backup: rclone copy /backup/daily/mysite google-drive:/backup/
By Default, CWP has all backups going to /backup.
rclone has many other command line options, but this is not the scope this guide.
For more details, refer to the rclone website.
For some other commands, they require FUSE to be installed.
Example: fusermount -u ~/site-backup
To install FUSE: dnf install fuse
Last Update: 25 June 2021