How to use OneDrive Free Client Fork to synchronize OneDrive with folders on Linux

A drive It is a file hosting and synchronization service provided by Microsoft, similar to Dropbox, Google Drive, MEGA, etc. There is no official Microsoft OneDrive client for Linux, but you can still keep OneDrive files in sync through the folders on the Linux machine (with real-time file monitoring function), this article will show you how to use OneDrive Free Client branch Still maintained (command line OneDrive client for Linux).

Not long ago, I wrote about using Rclone to install OneDrive on Linux (supporting both corporate and personal accounts). Some users may prefer to keep their OneDrive files in sync with the folders on the Linux computer (save the files on disk after performing synchronization, allowing access even if the computer is offline), and only upload/download changes instead of mounting OneDrive , And in this article, we will use OneDrive Free Client branch.
of The original OneDrive Free Client Was abandoned in the fall of 2018, but the tool is Bifurcation A few months later, it was named after the same name, and it has been continuously developing ever since.
The OneDrive Free Client branch is a complete tool for interacting and synchronizing OneDrive on Linux, with:

  • State cache
  • Use Inotify for real-time file monitoring
  • File upload/download verification to ensure data integrity
  • http
  • Support OneDrive for Business (part of Office 365)
  • Shared folder (OneDrive Personal Edition)
  • SharePoint / Office 365 shared library
  • Desktop notification via libnotify
  • Dry run function to test configuration changes
  • Prevent major OneDrive accidental data deletion after configuration changes

Like the original project, the OneDrive Free Client branch does not have a graphical user interface, so it must be used from the command line, although it does have desktop notifications that will let you know about synchronization status and any synchronization errors that have occurred.
It’s also important to note that when local changes are immediately uploaded to the linked Microsoft OneDrive account, remote changes will be delayed until the next synchronization when in use --monitor (This “monitoring” mode allows OneDrive Free Client to continuously monitor changes in the local file system and upload them when it detects them). E.g. When running this tool as a service, the monitoring interval for OneDrive Free Client is 45 seconds, so it may take up to 45 seconds to synchronize remote changes to the local drive.
For shared folders, for OneDrive personal accounts, all you have to do is add them to OneDrive. To do this, go to the OneDrive website and log in to your account, then go to the “Shared Files” list, right-click the folder you want to sync, and click OK. Add to my OneDrive. For OneDrive Business or Office 365 accounts, shared folders are currently not supported.The OneDrive Free Client (fork) documentation for Linux mentions that the tool can be found in the Fedora repository at: AUR for Arch Linux/Manjaro, On Slackbuilds.org for Slackware, And in the unstable channel of NixOS. Even if the tool is not mentioned in the documentation, it can be used in the official Debian and Ubuntu repositories (Edit: the documentation has been updated to reflect this). For Ubuntu, the fork is only available in Ubuntu 19.04, 19.10 and 20.04, while Ubuntu 18.04 still has the old, unmaintained OneDrive Free Client (I’m not sure if it still works, but even if it still exists, there are many The error will never be fixed). As for Debian, this OneDrive package is available in Sid and Bullseye.
So, to install OneDrive Free Client (fork) from the official repositories on Fedora, Debian/Ubuntu, use:

  • Install OneDrive Free Client (fork) on Fedora:
sudo dnf install onedrive
  • Install OneDrive Free Client (fork) on Solus OS:
sudo eopkg install onedrive
  • Install OneDrive Free Client (fork) on Debian Sid or Bullseye / Ubuntu 20.04, 19.10 or 19.04 and Linux distributions based on these Ubuntu versions (such as Pop!_OS 19.10 or 19.04) / Raspbian Testing / Kali Linux.
sudo apt install onedrive

The developer recommends even installing the latest version from source on Ubuntu 19.10, because the version in the repository is quite old. As for Debian Buster and Ubuntu 18.04 (and Pop!_OS 18.04, Linux Mint 19. *, basic OS 5 or 5.1, etc.), you need to build OneDrive Free Client (branch) from source code. As stated on its wiki, Because the version in the repository is an old, unused application.
For other Linux distributions, please check if the “onedrive” package is in the repository and install it, or Build from source.
OneDrive Free client (fork) Docker image It is also possible.

How to use OneDrive Free Client (fork) to synchronize Microsoft OneDrive with folders on a Linux computer

1. Use your Microsoft OneDrive account to authorize OneDrive Free Client (fork) for Linux.
For Office365/Access to the Sharepoint group drive in Office 365 commercial or educational version, please refer to the following instructions: This page.
For personal accounts, please open a terminal and run:

onedrive

When the application is run for the first time, the terminal running “onedrive” will display a message about authorizing this application through the access link. Copy the link displayed in the terminal and paste it into the web browser. After logging in to your Microsoft account, you should see a page asking if you want this application to access your information-click Yes.
After clicking Yes, You will enter a blank page. It doesn’t matter, it should be like this. Now, you need to copy the URL of the blank page and paste it into the terminal where you use the OneDrive account to authorize the onedrive tool.
After that, you will see a message in the terminal saying No OneDrive sync will be performed without either of these two arguments being present. This is because we did not try to sync any files, we just authorized the onedrive app with your OneDrive account, so we ignored it. 2. The first synchronization between OneDrive and the local file system.
After authorization, you can synchronize cloud OneDrive files to your local disk. The onedrive command line tool can download all OneDrive files to ~/OneDrive (A OneDrive folder is located in your home directory). You don’t need to create this folder because the onedrive tool will create it for you.
Let’s perform a trial run (trial synchronization) without any actual changes to ensure that this OneDrive Free Client for Linux can work normally in the following ways:

onedrive --synchronize --verbose --dry-run

If everything is ok, let us start syncing your OneDrive files locally ~/OneDrive folder. You can choose to synchronize all OneDrive files and folders with the local OneDrive folder (step 2A below), or you can synchronize only some files and folders (selective synchronization-step 2B below). 2A. To sync all OneDrive cloud files to the local disk (~/OneDrive), use:

onedrive --synchronize

This is only used for initial synchronization. To make OneDrive Free Client for Linux run in the background and synchronize files when changes are detected, see step 3 (Enable systemd service) below. 2B. Enable and use selective synchronization.
What if you want to synchronize multiple directories and files instead of all of them? Then, you will want to use the selective synchronization feature provided by this OneDrive Linux command line client.
Selective synchronization is a feature that allows you to specify files and directories to synchronize between OneDrive and the local file system, while skipping all other directories and files.
It is important to note that the Linux version of OneDrive Free Client will not delete any synchronized directories or files from the disk, in case you later exclude them through selective synchronization. Its role is to exclude them from future synchronization.
Example: If you only allow OneDrive to synchronize Folder1 and Folder2, and then add Folder3 to the OneDrive directory on your computer, the Folder3 will not be synchronized with your OneDrive account; however, if you have already combined Folder1, Folder2, and Folder3 with OneDrive Account synchronization, and then decide to allow only Folder1 and Folder2 to be synchronized, Folder3 will not be deleted from the OneDrive directory of the Linux computer, but any changes you make in this folder will be won. It will not sync with your OneDrive account.
You can enable selective sync for OneDrive Free Client by creating a file called sync_list In ~/.config/onedrive. Edit this sync_list File and add the relative path to the files and directories to be synchronized with OneDrive, each line is on a new line. All files and directories that do not match any line in the file will be skipped for synchronization.
example. Suppose I have many files and folders in my OneDrive account, but I only want to sync 2 directories (called backups and photos) and 3 files (named file1.ods, file2.odt and file3.odt respectively), all The 3 files are all in the document folder in my OneDrive account. under these circumstances ~/.config/onedrive/sync_list The file will need to contain the following lines:

Backup
Photos
Documents/file1.odt
Documents/file2.odt
Documents/file3.odt

Use selective synchronization for the first time, and each time ~/.config/onedrive/sync_list File, you must perform a full resynchronization using the following command --resync, like this:

onedrive --synchronize --resync

If the OneDrive Free Client systemd service is enabled (step 3 below) and the service is currently running, an error message will appear when trying to run this command, saying Initializing the Synchronization Engine ... A database statement execution error occurred: disk I/O error. Segmentation fault (core dumped). In this case, you will need to stop the onedrive systemd service, then run the resync command, and then start the service again, as shown below:

systemctl --user stop onedrive

onedrive --synchronize --resync

systemctl --user start onedrive

There are also options for skip directories, skip files, dot files, and symbolic links. These options are available through the OneDrive Free Client for Linux configuration file (see step 5 below).
Just like a full regular synchronization, this only applies to the initial synchronization. To make OneDrive Free Client for Linux run in the background and synchronize files when changes are detected, see step 3 below. Enable OneDrive Free Client for Linux system service.
To make OneDrive Free Client for Linux run as a service, so it will automatically start from your computer and constantly monitor for any changes to OneDrive, synchronize the changed files and folders, and let us enable its system service.
When used as a systemd service, this OneDrive command-line client for Linux runs in monitor mode (--monitor), so that you can continuously monitor file changes in the local file system. However, for many files, this may encounter problems caused by the local environment (cannot add new inotify monitoring). The solution is to create a maximum number of user views. This page Shows how to do this on Debian/RedHat or similar versions (Ubuntu, Fedora, etc.) and Arch Linux/Manjaro.
To enable and start the OneDrive systemd service (enable notifications) for the current (non-root) user, run:

systemctl --user enable onedrive

systemctl --user start onedrive

Use the following methods to check the OneDrive Free Client system service status:

systemctl status --user onedrive

Just check the log:

journalctl --user-unit onedrive -f

Related to systemd: chkservice is a Systemd Unit Manager with a terminal user interface (new version available)
For other ways to run the OneDrive service (via init.d as the root user), see Its filesPlease be careful not to delete ~/OneDrive (Or any path used by the OneDrive folder) folder, while running the OneDrive Free Client fork systemd service, because it will delete all files from OneDrive (you can still access files on the OneDrive website in Recycle Bin). 5. (Optional) Configuration options.
If you want to use a custom location for the OneDrive folder, change the changed file monitoring interval, and more other operations, you can use the OneDrive Free Client profile.
On Debian, Ubuntu and derivatives, you can find sample configurations in the following locations /usr/share/doc/onedrive/config. Another Linux distribution, or if you can’t find this configuration file, you can get it from the OneDrive Free Client GitHub project page- This is a direct link.
To change the default OneDrive Free Client for Linux configuration for your users, copy the configuration file to ~/.config/onedrive. E.g. In Debian/Ubuntu and other Linux distributions, this file is installed in /usr/share/doc/onedrive/configTo copy it to ~/.config/onedrive use:

cp /usr/share/doc/onedrive/config ~/.config/onedrive/

Now to change some OneDrive Free Client options, please open ~/.config/onedrive/config Open the file with a text editor. All of the options are commented out (they have # In front of them); to change one of the default values, uncomment the line and set the value to the value you want to use.
In most cases, the options in the configuration file should be self-explanatory. For help, see the onedrive man page (man onedrive).
For more information on using OneDrive Free Client on Linux, including how to use it with multiple OneDrive accounts, enable proxy support for the OneDrive systemd service, etc., please check OneDrive Free Client. Instructions for use.

Source

Sidebar