How to Sync OneDrive Business /Office 365 on Linux?
Ubuntu 18.04 and later
UPDATE:
The below instructions to install from apt
work, but the version in apt
is too out-of-date and fails to parse the authorization URI. Instead, following the INSTALL.md
doc to compile and install from source works:
https://github.com/abraunegg/onedrive/blob/master/docs/INSTALL.md
PREVIOUS:
There is a OneDrive client in the default Ubuntu repositories in Ubuntu 18.04 and later. OneDrive is the cloud storage system of Microsoft. This package provides the command line client specializing in synchronizing with OneDrive cloud storage.
Install it with:
sudo apt install onedrive
At first run, it asks you to authenticate with a link. After authentication you can enable the deamon with systemctl --user enable onedrive
and then systemctl --user start onedrive
.
It will monitor and sync OneDrive data locally in ~/OneDrive
.
Further explanations can be found in the manpage man onedrive
.
It's very easy to setup, and only takes about five minutes.
Currently the experimental onedrive-d is an open-source program that can sync only personal OneDrive accounts as it does not accept Microsoft Sharepoint links. Here is a method to sync OneDrive Business/Office 365 using GoodSync for Linux, which is free for personal use.
-
Install suitable version to your Linux machine eg:
./goodsync-linux-x86_64-release.run
Answer by no for both GoodSync Connect setup and GsServer Web UI.
- Open OneDrive in a web browser. select "Return to Classic OneDrive" on the right lower side.
- The web address in your browser will now look like:
https://xxxxxxx.sharepoint.com/xxxxxxxxxxx/Documents/Forms/All.aspx
and based on it get your syncing link which will beoffice365://xxxxxxx.sharepoint.com/xxxxxxxxxxx/Documents
. -
Create a new file in .goodsync subfolder in your home:
gedit ~/.goodsync/jobs.tix
-
Enter the following code in the file and save it:
<Job> Name = "OneDrive_Sync" Side1 = <SideOptions> Dir = <Connect> Url = "put_your_syncing_link_here" UserID = "put_your_OneDrive/Office365_Bussiness_email_here" </Connect> </SideOptions> Side2 = <SideOptions> Dir = <Connect> Url = "file:///your_home_folder/one_drive_folder" </Connect> </SideOptions> Direction = 0 ExcludeHidden = No ExcludeSystem = No DetectMovesAndRenames = Yes LinksOption = 1 ExcludeEmptyFolders = No LimitChangesPercent = 100 AutoResolveConflicts = 3 DetectMovesAndRenames = Yes </Job>
-
Start the syncing process:
gsync sync "OneDrive_Sync"
At this step your web Browser will open OneDrive/Office 365 page and ask for your authorization to allow goodsync to access your account. After entering your credentials syncing will start.
Limitations: Microsoft does not allow URL Requests with length of more than 270 character and so GoodSync CAN NOT sync files with long pathnames.
Enjoy!
rclone supports OneDrive for Business. See an article How To Mount OneDrive In Linux Using Rclone (Supports Business And Personal Accounts) - Linux Uprising Blog for usage.
Here is my example to setup a new remote onedrive1
with rclone 1.48.0 (on Fedora 30):
$ rclone config
2019/10/10 06:35:56 NOTICE: Config file ".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> n
name> onedrive1
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
⋮
19 / Microsoft OneDrive
\ "onedrive"
⋮
Storage> 19
** See help for onedrive backend at: https://rclone.org/onedrive/ **
Microsoft App Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>
Microsoft App Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>
Edit advanced config? (y/n)
y) Yes
n) No
y/n> n
Remote config
Use auto config?
* Say Y if not sure
* Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n> y
If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth
Log in and authorize rclone for access
Waiting for code...
Got code
Choose a number from below, or type in an existing value
1 / OneDrive Personal or Business
\ "onedrive"
2 / Root Sharepoint site
\ "sharepoint"
3 / Type in driveID
\ "driveid"
4 / Type in SiteID
\ "siteid"
5 / Search a Sharepoint site
\ "search"
Your choice> 1
Found 2 drives, please select the one you want to use:
0: OneDrive - Example Inc (business) id=b!gFLg-RRe****-T9B****
1: OneDrive - Example Inc (business) id=b!gFLg-RRe****-T-H****
Chose drive to use:> 1
Found drive 'root' of type 'business', URL: https://example-my.sharepoint.com/personal/myname_example_com/Documents
Is that okay?
y) Yes
n) No
y/n> y
Current remotes:
Name Type
==== ====
onedrive1 onedrive
e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q
The drive 0's URL ends with /ElementinnerHTML
and doesn't contain files in my case.
Then mount it on a local directory via command line, rclone-browser or web GUI since v1.49.
While the original and commonly used onedrived
tool by xybu still does not support OneDrive for Business, but only personal OneDrives. however, there is a fork of this project on GitHub by derrix060 that has a somehow working (but still buggy) implementation for the Business client.
Warning: When you use this method, I highly recommend to always verify that the files got synchronized correctly by checking them online at https://www.office.com, and/or to use my wrapper script shown at the end of this page to at least get informed of any errors using desktop notifications!
Sometimes onedrived seems to fail picking up some changes or upload them correctly, leaving your OneDrive in a (partly) unsynchronized state. It can also happen that it generates merge conflicts with itself for some reason and renames your files locally by appending your host name in parentheses and optionally a number. Unfortunately there is no notification about errors, but you can see the entries in your logfile.
If this happens, you can make it try to synchronize the respective files again by e.g. touching them or renaming them or the folder they're in.
Tip: It seems like the onedrived library often has problems especially with files that were saved directly in the OneDrive root. It's probably better to put all files in subdirectories instead of dumping them directly into the OneDrive folder.
Although it sounds stupid, I also noticed that it seems to cause less problems to upload files through the OneDrive Web client and wait until they get synchronized back to your local folder (which can take several minutes though) than to create or copy/move them locally. Whether this is practical or totally voids the purpose of OneDrive is up to your own decision...
See the project's readme file for complete installation instructions, but here's a short summary:
Installation
Make sure you have no other version of
onedrived
(oronedrive-d
) installed.-
Install dependency packages:
sudo apt install build-essential python3-dev libssl-dev inotify-tools python3-dbus libdbus-1-dev libdbus-glib-1-dev
Download the latest
ngrok
client for Linux from the official website at https://ngrok.com/download. Thengrok-client
package from the Ubuntu repositories is too old and doesn't meet the requirements.
Unpack the downloadedngrok-stable-linux-amd64.zip
archive. It contains a singlengrok
binary, which you should put in a location on your$PATH
, e.g. into/usr/local/bin/
.
Signing up to ngrok is probably not necessary.-
Install the
onedrived
Python3 application from GitHub usingpip3
:sudo -H pip3 install git+https://github.com/derrix060/onedriveClient.git
-
Optionally configure a logfile location for
onedrived
, where you can check for problems if anything should not work correctly, e.g.:onedrived-pref config set logfile_path ~/.config/onedrived/onedrived.log
Account setup and drive configuration
After the installation was successful, you have to configure your account and drive(s):
-
Add your OneDrive for Business account using the interactive mode by running:
onedrived-pref account add -b
The interactive wizard will ask you twice to open a link in your browser, where you will have to authorize the application with your Microsoft Business account.
It will ask you to paste the URL you get redirected to after confirming the authorization back into the interactive wizard. Please do as told and follow the instruction the command gives you. -
Verify the account got added successfully by checking the output of the command below. It should look similar and list the account you are logged in with:
$ onedrived-pref account list All OneDrive accounts associated with user "YOUR_UBUNTU_USERNAME": # Account ID Owner Name Email Address Profile Type --- ------------------------- ------------- -------------------- -------------- 0 YOUR_PERSONAL_ACCOUNT_ID YOUR_NAME YOUR_BUSINESS_EMAIL Business
-
Configure your drives in the interactive command mode by running:
onedrived-pref drive set
You will see a list of all your drives and get asked to enter the row number of the drive you want to add to your local configuration.
You then have to specify a local directory that you want to use as root folder for synchronizing with your drive. You can just hit Enter and it will use the default~/OneDrive
. If the path does not exist, it will be created. Same thing for the path to the ignore file you want to use, you can just hit Enter and it will use the default~/.config/onedrived/ignore_v2.txt
and create it, if necessary. -
Check the output of the command below to display the information about all available and configured drives. It should show the drive you just set up with the correct settings under the headline
Drives that have been set up
:onedrived-pref drive list
Launching the daemon
Now that your drive is configured, you need to try and start the onedrived
daemon. I recommend to launch it in debug mode first, in case there are any problems you would otherwise miss. This will start onedrived
in foreground:
onedrived start --debug
If everything is okay and the command does not crash and exit, try putting some files on your local OneDrive folder and see if it synchronizes. You should probably be able to verify that by visiting the OneDrive web application at https://www.office.com and checking if the files you added locally are appearing there.
You can quit the onedrived
process in your terminal again by pressing Ctrl+C.
To launch onedrived
normally, as a background daemon, run it with:
onedrived start
You should probably add this command to your Startup Applications, so that it auto-starts every time you log in. Please refer to How do I start applications automatically on login? for that.
Wrapper for error notifications
If you want to get desktop notifications whenever onedrived
logs an error (e.g. failed file synchronization), here is a wrapper script that parses the log file in real-time and uses notify-send to display them to you.
You can start the wrapper script without arguments (or put it in your auto-start applications) instead of the onedrived start
command.
#!/bin/bash
LOGFILE=~/.config/onedrived/onedrived.log
ICON_START=weather-overcast
ICON_STOP=weather-few-clouds
ICON_ERROR=weather-severe-alert
onexit () {
onedrived stop
notify-send -i "$ICON_STOP" "OneDrive" "Wrapper stopped"
echo "onedrived-wrapper stopped"
}
trap onexit EXIT
onedrived stop
echo "---" >> "$LOGFILE"
onedrived start || {
echo "Failed to start onedrived!"
exit 1
}
notify-send -i "$ICON_START" "OneDrive" "Wrapper started"
echo "Monitoring onedrived.log for error messages..."
tail -n 1 -F --pid="$(pgrep -f "onedrived start")" "$LOGFILE" |
while read LINE ; do
echo "$LINE"
if MESSAGE="$(grep -Pio '(?<=ERROR: ).*' <<< "$LINE")" ; then
notify-send -i "$ICON_ERROR" "OneDrive Error" "$MESSAGE"
fi
done