This tutorial covers backing up to Google Drive on Linux using Rclone. We will do our best to make sure you understand this guide. I hope you will like this blog How to Backup to Google Drive on Linux Using Rclone. If your answer is yes, please share after reading this.
Check out how to backup to Google Drive on Linux using Rclone
Rclone is a command line utility for managing files in cloud storage. It supports over 40 cloud storage products including top cloud storage services from Google, Amazon, Dropbox, Mega, Microsoft, Zoho, and pCloud. Available for Linux, Windows, macOS, Debian, OpenBSD, and several other operating systems, Rclone is a Swiss army knife for cloud storage. It’s a versatile tool, but the most common function of Rclone is to act as a bridge between different cloud storage providers so that you can easily move, copy, and sync files between providers.
So far Google has not released an official backup / sync client for Linux and as a frequent user of WSL2 I was looking for a solution that would allow automatic backups of WSL2 Linux distribution / files system to Google Drive . Linux and the advancement of WSL2 (with a real Linux kernel) make it easier to work in a near ârealâ Linux environment without the need for third-party virtualization software. Using rclone with WSL2 allows me to restore project files from a recent backup in case I accidentally throw my WSL2 Linux distribution into the trash, the only restriction is that no file can exceed 5TB) .
Download / install rclone:
To download / install rclone:
- $ cd $ HOME
- $ curl https://rclone.org/install.sh | bash sudo
- rclone v1.53.1 has been installed successfully.
Before we can configure rclone access to our target Google Drive account, we need to enable the Google Drive API and create the correct credentials.
Activate the Google Drive API:
- Sign in with your Google account at: https://console.cloud.google.com to begin the API activation process.
- Go to âAPI and Servicesâ â âLibraryâ.
- Find and activate “Google Drive API”.
- Choose “Create Credentials” and continue to the next section to configure the Oauth consent screen.
Create the Google Drive API credentials for rclone:
In the left panel of the cloud console, choose âOauth consent screenâ and configure using the following settings.
- User type: External -> Create.
- Application name: rclone.
- Support email – Enter your Google account email.
- Add scopes: âGoogle Drive APIâ -> ââ¦ / auth / driveâ.
In the left panel, choose “Create credentials”
- Click on the “+ Create identifiers” menu and select “Oauth client ID”.
- Application type: desktop application.
- Name: rclone.
- Click on “Create”.
- A client ID and a client secret will be generated. Make note of these as they are required during the rclone setup process.
Start the rclone configuration by running:
Throughout the setup process, choose / enter the following options:
- n to add a new remote control.
- name: gdrive.
- In the list of storage providers, choose the number / option corresponding to Google Drive “drive”.
- Google App Client ID – As specified in Google settings.
- client secret: as indicated in Google settings.
- scope: 1 / Full access to all files except the application data folder. “to drive”.
- root_folder_id: leave empty.
- service_account_file: leave empty.
- modify the advanced parameters: N.
- remote configuration uses automatic configuration: Y.
- Open the generated URL link with your browser and complete the authentication process.
- After you have successfully authenticated and granted permissions for rclone, return to the rclone shell terminal session to continue with the configuration.
- equipment unit: n
- And to confirm that the settings are correct.
- Choose q to complete the setup.
Choose an appropriate rclone command: copy or synchronize
Depending on your backup needs, you can choose from several different command options. Among these are copying, synchronization.
- recloning the copy
source: path source destination: path dest
- recloning the copy
The following command:
- $ rclone copy âtransfert 20 âretries 5 â/ home / dev / gâ âgdrive: / mybackupâ
can be used to back up the contents of the local / home / dev / g subdirectory to the location of the google drive gdrive: / mybackup, where gdrive is the reference to our google drive alias as provided during the installation process of rclone, and / mybackup is the destination location in our Google Drive root directory. The flags chosen in the previous command result in the following:
- -transfers: number of file transfers to be performed in parallel (20)
- âRetries: number of attempts to retry failed operations (5)
- rclone synchronization
ORIGIN remotely: DESTINATION
- rclone synchronization
For the automation example that follows, we’ll use the rclone copy option. Be careful if you decide to use the sync option. Failure to understand how the synchronization control works can potentially lead to data loss.
Automate the rclone command with flock and cron
The rclone copy command from the previous section can be implemented as a cron job, scheduled to run at desired intervals. Before we move on to scheduling, we need to resolve the case where a backup might still be running while the next scheduled instance needs to start. A simple approach to handling this scenario would be to use the concept of locking herd notification records. According to the flock man page, we can use a single flock command line to implement our rclone backup.
- $ flock -n /tmp/google_drv_sync.lock/usr/bin/rclone copy âtransfers 20 âretries 5 â/ home / dev / gâ âgdrive: / mybackupâ
The above flock command will create the google_drv_sync.lock file (if it does not already exist) and acquire an exclusive (write) lock on the file during the rclone backup. The -n option tells flock that if the lock cannot be acquired (that is, the old backup is still running), immediately exit with return code 1 (c ‘ i.e. do not wait for the lock to be released).
Final Words: How to Backup to Google Drive in Linux Using Rclone
hope you will understand this item How to Backup to Google Drive on Linux Using Rclone, if your answer is no, you can request anything through the contact forum section linked to this article. And if your answer is yes, then share this article with your family and friends.