
Guide: Sync Unraid or your Linux distro of choice with Google Drive
CheckMag
Thanks to Valve and Proton, Linux is becoming a much more viable platform for work and play, but first party support for syncing common cloud services like OneDrive and Google Drive is none existent and unlike TruNAS and Synology this feature isn't built in. However, there is a reliable and relatively straightforward solution. Here's how it works.David Devey 👁 Published 🇫🇷 🇪🇸 ...
This all started with trying to figure out a way to sync Unraid with Google Drive. Having migrated from Synology (available on Amazon.com) to TrueNAS (both of which have native implementations for syncing your disks directly to Google Drive), this is a feature that is sorely missing from Unraid. Reddit is flooded with similar questions with a multitude of potential solutions, however the common solution is often the best (even if it isn't that easy), and this particular solution also works with any Linux distro, not just Unraid.
One of the key criteria for my solution was leaving readable files on Google Drive as opposed to an encrypted backup. While this isn't a backup solution per se, the convenience of having the files readable directly from Google Drive was appealing. This eliminates MSP360 (Formerly CloudBerry), Duplicati and Duplicacy as options, however, one name that consistently appeared in the various threads was Rclone.
Users call Rclone "The Swiss army knife of cloud storage", and there is good reason for that. It supports mounting of almost every cloud storage provider you can think of, and offers a range of copy and sync commands for either mirroring changes between drives or one way backups. While it does have a native Unraid plugin, Rclone can be installed on pretty much any Linux distribution out there. In this tutorial we'll look at Ubuntu, but the process for mounting cloud drives and syncing or copying files is almost identical regardless of the system of choice. It is predominantly driven by the command line, but despite my initial apprehension, this is by far the most reliable solution I have found. Once set up, you can basically forget it, and Rclone will happily sync or copy your files to a schedule.
Installation
To install Rclone, open a terminal window and type:
sudo apt-get install rclone
You may need to adjust the command depending on your distribution.
Once installed, type:
rclone config
This will launch the interactive installer, and you should choose "New Remote". Enter a name for your remote connection, this can be anything but should ideally reflect your provider of choice - in this case, "Google". Once you have chosen the name, you should start to get some idea of just how many cloud providers Rclone supports.
Type "18" to select Google Drive as your provider. From there, you will be asked to enter a client ID. At this point, it is time to move to the Google API Console to create an application that will allow Rclone to access your Google Drive.
Creating a Google API for granting Rclone access to Drive
The instructions provided on the Rclone site are pretty comprehensive, however, when you are asked to "Add Scopes" as can be found under "Data Access", "Add or Remove Scopes" some confusion may arise.
You can add all the scopes one by one, or all at once, by pasting the following into the box called "Manually add scopes":
www.googleapis.com/auth/docs,
www.googleapis.com/auth/drive,
www.googleapis.com/auth/drive.metadata.readonly
From there, the instructions differ slightly to what we see in Google API, so click "Clients" on the left-hand side and create a "Desktop App" called "Rclone" or whatever you like. Make a note of the client ID, and you can get the client secret by clicking on the client name.
Once you have these, click "Audience" on the left-hand side and publish your app. Technically, Google requires you to verify your app, which can take time. However, you are free to go ahead and start using it without verification. You can leave it in "Testing" and not publish, but you will have to refresh any grants weekly, which isn't practical. Now that we have the client ID and client secret, you can go back to your terminal window to enter these credentials.
Choose "1" as the scope to allow full access to all files, and you can leave the next section "Option service_account file" blank. Choose "No" for the advanced config, and "Yes" to use the auto config. This is useful because it will open a browser to allow you to authenticate Rclone with your Google Account. The easiest way to do this on Unraid when setting up your machine is to plug in a monitor and use the GUI mode when going through the initial setup, but you can also do this on a headless machine by selecting "No" - please note this process is somewhat more involved.
Our Google Drive is not a shared drive, so we can click "No" at the next step, then you just need to confirm to save the connection.
Mounting our Google Drive
Once that is completed, we need to create a location to mount the drive. Create a folder in which to mount your drive by typing:
mkdir -p ~/gdrive
Then mount the drive to that location by typing:
rclone mount google: ~/gdrive
You can now drag and drop any files you need into that folder, and they will automatically appear in your Google Drive. Similarly, any files you create or add to the web version of Google Drive will also appear in that folder.
Now that you have been able to mount your Google Drive, it's time to add it to crontab, so it will survive a reboot. We can also use crontab to schedule copying or syncing to your Google Drive.
Surviving a reboot and scheduling a sync
To edit crontab, type crontab -e and choose "nano" as the editor. Once you are in crontab, paste the following:
@reboot rclone mount google: /home/YOURUSERNAME/gdrive
The crontab file is where you can also schedule copy or sync commands to happen between folders and your Google Drive at specific days or weeks.
A complete list of Rclone commands can be found here, but the key ones include:
- "copy" - copy any files from one directory to another, skipping any files that do not have any changes, or already exist.
- "sync" - will make the source and destination the same, modifying the destination only.
- "bisync" - will perform a bidirectional sync between two paths.
You can build sync or copy commands into your crontab file. Use Crontab Guru to calculate the frequency and copy and paste the directories you want to sync.
*/5 * * * * rclone copy /home/YOURUSERNAME/Documents google:Documents
So the above cron will copy the contents of the Documents folder to a folder called Documents in your Google Drive every 5 minutes. You can add as many jobs as you like, with different frequencies and folders.
While not the simplest to set up, having tried a number of both paid and free solutions, Rclone has been the most reliable "set and forget solution" I have found so far.
Rclone supports so many cloud storage providers, and has many more commands and use cases not covered here, whether you are an Unraid user utilising the Unraid plugin, or a Linux user just wanting to sync or backup specific directories on your Linux box, Rclone really is the "The Swiss army knife of cloud storage".