OneDrive Sync On Linux Part 3, With abraunegg/onedrive As Daemon

In a previous blog post, I showed another way of syncing OneDrive folders on Linux as an alternative to using RCLONE. It was the Open-Source project “onedrive” by Github user “abraunegg” (a fork of an abandoned project by user “skilion”). One thing I was having trouble with was the installation as a daemon. I used an @reboot crontab workaround to achieve my goal instead. However, I was not satisfied, so I went back to the documentation to see if I missed something. And miss I did. To my defense, other steps I had tried are omitting a necessary detail required to make it work.

I have mentioned the installation in the other post, but I also left out a thing or two that I came across. That is why I will include the setup process again, this time in more detail, and refer you to the other blog post for configuration tips. That is the part I will skip here.

My test system is the same Fedora 34 distribution, and I have also tested the steps on Pop!_OS, which means it should work on the other Ubuntu derivates.

Installation

$ sudo dnf install onedrive

Nothing special here, so I will move right along to…

Authorization

For this tool to work, you need to grant it access to your OneDrive account. To do that, you run it without parameters.

$ onedrive

It will print a URL on the command line that you must visit in a web browser. It is a Microsoft login page, and after you have authenticated yourself, you will be left with a white website. This is the part that confused me because I expected some output. Instead, you copy the URL from your browser’s address bar and enter that on the command line where onedrive asks you for the “response uri”. It is not the most user-friendly process but preferred over giving it your plain-text credentials. Now, those secrets are not stored somewhere on the file system. Instead, onedrive receives an authentication token and stores it in ~/.config/onedrive/refresh_token.

Test Sync

You can test every command and verify the output before you commit to the action. Add --dry-run to the list of parameters, and onedrive will simulate the operation.

$ onedrive --dry-run --verbose --synchronize --single-directory Code

Note: You can perform a test before authentication, and it will ask you to authorize it before doing anything. Since it is a dry-run, it will not only not up- or download anything but also not store the authentication token. I was going crazy trying to figure out why it continued to ask for a login every time I tried to start the daemon.

Install Daemon

In my first attempt to install the daemon, I focused on using systemctl --user because I wanted a user-centric installation. If I am honest, though, I do not exactly know what that does and how it is different from installing the service with @username. I should have spent more time understanding the differences. Be that as it may, I missed a crucial point in the documentation. This is a feature that is not available on Fedora systems, which is why it failed for me.

Note: systemctl –user directive is not applicable for Red Hat Enterprise Linux (RHEL) or CentOS Linux platforms – see below.

What you use instead is the way with the @ sign, like so.

$ sudo systemctl enable onedrive@rlo.service
    Created symlink /etc/systemd/system/multi-user.target.wants/onedrive@rlo.service → /usr/lib/systemd/system/onedrive@.service.

Another important piece that is missing from the documentation is sudo or any other method that gives you root privileges. This setup will only work with root access.

As you can see from the output, it uses the configuration located in /usr/lib/systemd/system/onedrive@.service if you want to change the command line.

What is left to do is start the service.

sudo systemctl start onedrive@rlo.service
sudo systemctl status onedrive@rlo.service
    ● onedrive@rlo.service - OneDrive Free Client for rlo
        Loaded: loaded (/usr/lib/systemd/system/onedrive@.service; enabled; vendor preset: disabled)
        Active: active (running) since Fri 2021-07-09 18:17:41 CEST; 5s ago
        Docs: https://github.com/abraunegg/onedrive
    Main PID: 4249 (onedrive)
        Tasks: 4 (limit: 9498)
        Memory: 8.8M
            CPU: 112ms
        CGroup: /system.slice/system-onedrive.slice/onedrive@rlo.service
                └─4249 /usr/bin/onedrive --monitor --confdir=/home/rlo/.config/onedrive --single-directory Documents
    Jul 09 18:17:43 fedora onedrive[4249]: Creating local directory: Documents
    Jul 09 18:17:43 fedora onedrive[4249]: Creating local directory: Documents/Shadow of the Tomb Raider
    Jul 09 18:17:43 fedora onedrive[4249]: Creating local directory: Documents/My Games
    Jul 09 18:17:44 fedora onedrive[4249]: Downloading file Documents/Shadow of the Tomb Raider/SOTTR_X_2021-05-15_12.39.21.txt ... done.
    Jul 09 18:17:44 fedora onedrive[4249]: Downloading file Documents/Shadow of the Tomb Raider/SOTTR_X_2021-05-15_12.43.24.txt ... done.
    Jul 09 18:17:45 fedora onedrive[4249]: Downloading file Documents/Shadow of the Tomb Raider/SOTTR_X_2021-05-15_12.47.21.txt ... done.
    Jul 09 18:17:45 fedora onedrive[4249]: Downloading file Documents/Shadow of the Tomb Raider/SOTTR_X_2021-05-16_09.52.19.txt ... done.
    Jul 09 18:17:46 fedora onedrive[4249]: Downloading file Documents/Shadow of the Tomb Raider/SOTTR_X_2021-05-16_09.55.13.txt ... done.
    Jul 09 18:17:46 fedora onedrive[4249]: Downloading file Documents/Shadow of the Tomb Raider/SOTTR_X_2021-05-18_20.14.30.txt ... done.
    Jul 09 18:17:46 fedora onedrive[4249]: Downloading file Documents/Shadow of the Tomb Raider/SOTTR_X_frametimes_2021-05-16_09.52.19.txt ... done.

Looking at the folders that the onedrive daemon creates, user and group are set correctly to my user, which is exactly what I want.

ls -la OneDrive/Documents/
total 0
drwx------. 1 rlo users  170 Jul  9 18:18  .
drwx------. 1 rlo rlo     26 Jul  9 18:17  ..
drwx------. 1 rlo users   30 Jul  9 18:18 "Assassin's Creed Valhalla"
drwx------. 1 rlo users   30 Jul  9 18:18 'Battlefield 4'
drwx------. 1 rlo users   42 Jul  9 18:18  BioWare
drwx------. 1 rlo users   44 Jul  9 18:17 'My Games'
drwx------. 1 rlo users   20 Jul  9 18:18  Respawn
drwx------. 1 rlo users 1348 Jul  9 18:18 'Shadow of the Tomb Raider'

Now I am happy. I think this is probably the last post about syncing OneDrive on Linux. Unless Microsoft ports their sync client to Linux, this seems to be the best solution so far.

I hope this helps and thank you for reading.

3 thoughts on “OneDrive Sync On Linux Part 3, With abraunegg/onedrive As Daemon

Leave a comment

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