OneDrive Sync On Linux With RCLONE

In my quest to move to Linux as a daily driver it was important for me that I could continue to use Microsoft’s OneDrive cloud storage. Unsurprisingly, Windows 10 comes bundled with a OneDrive sync client. There is no official Linux support though, so I had to resort to a 3rd party tool. Luckily, there is a very powerful utility called rclone that does almost exactly what I want and I’ll explain how I have it set up to suit my needs.

Spoiler: it’s not as convenient as Microsoft’s sync client, but it has other things going for it.

When you look at the rclone website you’ll notice that it has support for a ton of storage backends, many of which I have never heard of. I’ll be focusing on OneDrive as that is what I require. I assume that general usage is very similar across all services once the application has been configured.

Installation is simple and should be similar for most distributions.

sudo apt install rclone

The next step is to run rclone config which will start the (text based) configuration wizard that guides you through the process of connecting rclone to our OneDrive. You can read more about that on linuxuprising.com where you will find pictures of each step as well as some explanations. They also provide steps to mount your OneDrive storage locally, which is something I did not do. More on that later.

Note that rclone registers itself as an app in your Microsoft account that has full access to your OneDrive. You can review and revoke the access of rclone in your account’s security setting page (which is very well hidden, Microsoft; not good).

If you frequently change the Linux distribution or are using multiple computers you can copy the rclone config to each of those machines and start using it. No need for executing the config wizard again. Run rclone config file to find out where rclone stores the file.

$ rclone config file
Configuration file is stored at:
/home/rl/.config/rclone/rclone.conf

Now on to how I use rclone. It is very flexible and it’s up to the user to decide what you want to do. Unlike the sync client built into Windows, rclone does not run in the background and sync every change you make, either remote or locally.

As mentioned earlier, rclone has a mounting feature. Bear in mind though, that mounting isn’t a sync. If you mount your OneDrive root or a sub folder the remote storage is made available locally. It is not copied over. This is important to know. Everything you do is sent over the wire(less) and you never have any data on your computer. It’s like mounting a network share. Of course, this has advantages as well as drawbacks. For one, your data only exists in the cloud. I wouldn’t want that which is why I don’t do it. On a positive note: you can use this feature on computers with a limited storage capacity or preconfigured on a USB stick to have it with you all the time.

I am using the sync functionality to keep individual folders in sync. That’s one of the things I like about rclone. You don’t have to sync your whole cloud storage every time. You can limit it to individual folders and subfolders and maybe even files. I haven’t tried that. What I am doing is to sync folders by top-level topic. This is basically the same folder structure every operating system now preconfigures for its users.

  • Documents
  • Music
  • Pictures
  • etc.

The most changes for me happen in Documents, so that is what I’ll be syncing the most. There is no need to also check the other folders with thousands of files everytime I add a new Document.

WARNING There is one important thing know: the sync is one-directional.

That means you either sync from your computer to the cloud or the other way around. It is does not do both at the same time. As a result, you have to be very careful where you change files and in which order you sync. For example: you have modified a spreadsheet in the cloud using the web applications of Office. Then you get to your computer and start working on a document. Now you want to sync both, but you have changes in both locations. If you sync from the cloud first you will delete your local file because rclone can’t find it on the remote. If you sync from your computer first you will overwrite the spreadsheet in the cloud with the old data you have on your computer. To avoid this, always sync first from where you’ve last made a change. In some way it’s like a code repository, only without a merge.

Note: rclone provides several other options to copy data to and from the cloud. If sync isn’t your jam, maybe another command suits your needs better.

I am using the following commands.

  • Sync FROM OneDrive: rclone sync -P onedrive:Files ~/Documents/
  • Sync TO OneDrive: rclone sync -P ~/Documents/ onedrive:Files

Analogue for music files.

  • Sync FROM OneDrive: rclone sync -P onedrive:Music ~/Music/
  • Sync TO OneDrive: rclone sync -P ~/Music/ onedrive:Music

-P prints a nice progress.

Transferred:        6.747k / 6.747 kBytes, 100%, 108 Bytes/s, ETA 0s
Errors:                 0
Checks:               429 / 429, 100%
Transferred:            1 / 1, 100%
Elapsed time:      1m3.8s

I have a small cheat sheet that I created when I switched to Linux. It contains a list of issues I found that I may want to write about and also some useful commands, so I don’t have to think about it when I need them. For the first month I have copied these commands from my cheat sheet to the console to execute them. It worked and it was fast enough, so I hadn’t bothered to improve the workflow. In order to write this blog post, I wanted a better solution because, let’s be honest, copying commands from a file to the terminal over and over again is a waste of time.

So, I configured myself some aliases and now it’s merely a few keystrokes in the terminal – autocomplete included.

# Files
pushdocs
pulldocs

# Music
pushmusic
pullmusic

Being a programmer and Git user, I called syncing to OneDrive push* and getting the latest data from the cloud pull*. I still need to open a terminal every time I want to perform a sync, but it’s much quicker now and something that deserves the name "solution".

When it comes to configuring aliases, I opened ~\.bashrc and noticed a comment that recommends to store custom alias definitions in ~/.bash_aliases instead.

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

So I did just that and this is how it looks.

alias pushdocs='rclone sync -P ~/Documents/ onedrive:Files'
alias pulldocs='rclone sync -P onedrive:Files ~/Documents/'

alias pushmusic='rclone sync -P ~/Music/ onedrive:Music'
alias pullmusic='rclone sync -P onedrive:Music ~/Music/'

That’s all there is to it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.