Setting Up rClone on Ubuntu 21.04

In this post we'll be setting up rclone on Ubuntu server 21.04, this should be a very similar process for most Ubuntu versions.

First we'll do a quick update and install rclone.

sudo apt update
sudo apt install rclone

Now we'll configure our remote for rclone.  This is where you'll be sending your data to.  For now we'll input the base config using Google Drive as an example.

rclone config

You should be prompted with the following.

TestyContainer:~# rclone config
2022/01/04 19:11:59 NOTICE: Config file "/root/.config/rclone/rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q>

Here we'll use option "n" to create a new remote.  Once you select this option you will be walked through the basic config for a new remote, you'll be faced with the following prompts.

# This will be the identifying name of your remote.
Name>

# This lets you select the remote service you're using. In this example, we
# use option 13 for Google Drive.
Storage>

# Next we'll follow the instructions provided by rclone 
# (https://rclone.org/drive/#making-your-own-client-id) to create a service 
# account which will be used to authenticate.
# Once you've followed the instructions and have your client_id and 
# client_secret, input them in their respective prompts.
client_id>
client_secret>

# Option 1 will give it full access to the Google Drive root folder.
Scope>

# We'll hit enter here to select the default.
root_folder_id>

# We'll hit enter here to keep the default as we're using OAuth2.0 to 
# authenticate.
service_account_file>

# We'll select no as we do not need to mess with this.
Edit advanced config?>

# Here we'll select no as we're running this on a headless machine. Copy the 
# link generated by rclone, open it in your browser, sign in and authorize 
# rclone for access. Copy the verification code provided once authorized and 
# paste it into terminal.
Remote Config
Use auto config?>

# We'll hit enter here to select the default.
Configure this as a team drive?>

Lastly, we'll be prompted to review the config and save, edit or delete the config. We'll say yes in order to save the remote config, and q to quit the main menu.

Next we'll use the wonderful crontab to ensure our this task runs during our desired time.

crontab -e

Next you'll be prompted to select a default text editor. As I use nano, I'll select option 1.  From here we'll enter a time where we'd like the sync to happen. This will ultimately be up to you and your needs.

For the sake of this post we'll say we want to save my super sensitive and empty Test over to Google Drive using the rclone remote we configured earlier, and we want it to sync every 15 minutes.


*/15 * * * * rclone sync /home/Miggy/SuperSecretTings/ GoogleDriveRemote:rclone/GhostBlogTest/

The "*/15 * * * *" section of this entry tells cron to run the following command every 15 minutes.

"rclone sync" is the command we'll use to sync a local folder to the remote folder.

Following "rclone sync" we add the local directory and then the rclone remote you created followed by the folder on Google Drive you'd like to sync to.

Save the crontab, in nano we hit Ctrl+O and then enter. Lastly, we'll reload the cron service.

sudo systemctl restart cron

I HIGHLY suggest reading through this article from DigitalOcean on all the different ways you can use cron tab: How To Use Cron to Automate Tasks on Ubuntu 18.04. Even though its written around release 18.04, the information is still valid.


Stay tuned for the next part of this where we'll be using the same remote, but encrypting the files prior to uploading them to Google Drive.  You know, in case you actually do have super secret tings you'd like to keep, secret =).


~~~WIP Will finish sometime this week!~~~