Table of Contents
This tip is about the how to Back Up to Google Drive on Linux Using With Rclone. So read this free guide, How to Back Up to Google Drive on Linux Using With Rclone step by step. If you have query related to same article you may contact us.
How to Back Up to Google Drive on Linux Using With Rclone – Guide
Rclone is a command line utility for managing files on cloud storage. It supports 40+ cloud storage products, including the best cloud storage services from Google, Amazon, Dropbox, Mega, Microsoft, Zoho and pCloud. Available for Linux, Windows, macOS, Debian, OpenBSD and many other operating systems, Rclone is a Swiss Army knife for cloud storage. It’s a versatile tool, but Rclone’s most common function is to act as a bridge between different cloud storage providers so you can easily move, copy and sync files between providers.
Until now Google has not released an official backup / sync client for Linux and as a frequent WSL2 user I was looking for a solution that would allow automatic backups of the WSL2 Linux file system / distribution to Google Drive. Linux and the advancement of WSL2 (with a real Linux kernel) make it easier to work in an almost “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 in the trash; the only restriction is that no file can exceed 5TB).
Download / install rclone:
To download / install rclone:
Before we can set up rclone access to our destination Google Drive account, we need to enable the Google Drive API and create the proper credentials.
Activate the Google Drive API:
Create Google Drive API credentials for rclone:
In the left pane of the cloud console, choose “Oauth Consent Screen” and perform the configuration using the following values.
In the left pane, choose “Create credentials”
configuring rlone
Start rclone setup by running:
Throughout the configuration process, choose / enter the following options:
Choosing an appropriate rclone command: copy or sync
Depending on your backup requirements, you can choose from several different command options. Among them are copy, sync.
copy of
The following command:
can be used to backup the contents of the local subdirectory /home/ dev / g to the Google drive location gdrive: / mybackup, where gdrive is the reference to our Google drive alias as provided during the rclone setup process, and / mybackup is the destination location in our Google drive root directory. The flags chosen in the command above translate into the following:
Synchronize
For the automation example below, we will use the rclone copy option. Tread carefully if you decide to use the sync option. A misunderstanding of how the sync command works can lead to data loss.
Automating the rclone command with flock and cron
The rclone copy command in the previous section can be implemented as a cron job, scheduled to run at desired intervals. Before we get into scheduling, we need to deal with the situation where a backup might still be running while the next scheduled instance is about to start. A simple approach to managing this scenario would be through the concept of herd warning file blocking. According to the flock manpage, we can use a one-line flock command to implement our rclone backup.
The flock command above will create the google_drv_sync.lock file (if it doesn’t already exist) and get an exclusive (write) lock on the file during rclone backup. The -n option tells flock that, in the case where the lock cannot be acquired (ie the previous backup is still running), exit immediately with return code 1 (ie don’t expect the lock to be released).
Final note
I hope you like the guide How to Back Up to Google Drive on Linux Using With Rclone. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.