Synchronize OneDrive files locally
A common feature that people request is to synchronize their cloud drives with the local filesystem on Zorin. This how-to guide covers how to synchronize Microsoft's OneDrive using a command line utility promptly called onedrive
. It is a flexible OneDrive client that supports two-way or one-way synchronization, with a ridiculous number of configurable options.
Installation
These instructions apply to any version of Zorin 16.x, based on Ubuntu 20.04. Check the project's documentation for the exact instructions for older or later versions.
Start by adding the OpenSuSE Build Service repository to your system, by running the following commands one at the time:
wget -qO - https://download.opensuse.org/repositories/home:/npreining:/debian-ubuntu-onedrive/xUbuntu_20.04/Release.key | sudo apt-key add -
echo 'deb https://download.opensuse.org/repositories/home:/npreining:/debian-ubuntu-onedrive/xUbuntu_20.04/ ./' | sudo tee /etc/apt/sources.list.d/onedrive.list
And update your cache to make sure you install the latest version, and then install it:
sudo apt update
sudo apt install onedrive
Initial Setup
To link to your OneDrive account you must run the onedrive
command as is:
onedrive
This will prompt you to follow a URL that will take you to the OneDrive page. Once you login, you will see a confirmation window asking for authorization to let onedrive
access your files.
Once you click "Yes" you will be taken to a blank screen; take note of the url on that window, copy it and paste back in the terminal.
You should see then a message indicating that the application has been successfully authorized.
Synchronize files
To start synchronizing files you can run the same command passing the --synchronize flag, which will do exactly that.
onedrive --synchronize
By default, it will create a new folder in your home directory called OneDrive and synchronize your files from OneDrive to that local directory. This is a one-time command: you run it, it synchronizes your files, and it's done it will not continue to watch your files for changes. Therefore you will need to re-run it whenever you want to keep your local and remote files in sync.
Hint: You can drag and drop the OneDrive folder (you can do this with any folder) to the sidebar on the explorer, to create a shortcut available from any location on the explorer.
Some useful flags that you can provide to this command are --download-only
to perform a one-way data synchronization from the cloud to your computer, or --upload-only
to perform the reverse action, from your computer to the cloud.
To create a continuous process that keeps running and watching for changes, pass in the --monitor
flag.
onedrive --monitor
TIP: End the command with an ampersand to send the process to the background. This way you can close the terminal window and the process will quietly continue to run. E.g.:
onedrive --monitor &
As expected this will continue to watch for changes to the local directory and immediately synchronize them with your OneDrive account. Keep in mind that changes made on the cloud however are not in real time. Instead, the onedrive
client is polling the server every 300 seconds. You can change this time interval when running the command by providing the --monitor-interval SECONDS
. I'd recommend considering changing this option only when you actually need it to avoid performance issues.
Run on system startup automatically
Follow this step only after you've setup and confirmed that
onedrive
is working correctly.
It would be quite useful to have this process running automatically without any user interaction. To achieve this, make sure that your onedrive
client is up and running and from the terminal run the following commands.
sudo systemctl enable onedrive@<username>.service
sudo systemctl start onedrive@<username>.service
Where username
is the name of the current user running on your system. It should appear right at the beginning of the prompt, or by running the command whoami
.
Diagnose Problems
There are a couple of useful commands that you can run to diagnose any problems. First, to check on the status of the service (this will tell you if it's even running and/or why it stopped):
sudo systemctl status onedrive@<username>.service
You can also read the logs that the application creates by running (again, use the correct username):
sudo journalctl --unit=onedrive@<username> -f
Alternatives
Before installing additional OneDrive clients, please save any configuration files that you may have and uninstall
onedrive
or whatever other client you may have already installed.
I wrote this guide as I found that onedrive
was very heavy on the command line and thus not so easy to follow for someone with not much experience working at the terminal prompt.
If you are still not convinced and would like a more user-friendly alternative you can try onedriver instead (yes, very similar name...). It works very much in the same way except it technically does not sync files, but instead downloads them on demand which is actually very efficient. The setup and usage is also much easier thanks to the graphical interface that it provides.
It seems, though I'm not sure, that it does not have a lot of the customization options that onedrive
has, but these are not really necessary to get things working. I encourage you to try both and decide for yourself which one is better for you.