To sync a specific folder from your OneDrive to a folder on your Linux VPS, you can easily do that using the OneDrive CLI tool. Here’s a clear step-by-step guide to help you accomplish that.

Steps to Sync One Specific Folder from OneDrive to a Local Folder on Your Linux VPS


1. Install OneDrive CLI on Your VPS

If you haven’t installed the OneDrive CLI tool yet, follow these instructions to install it.

On Ubuntu/Debian-based systems:

sudo apt update
sudo apt install -y build-essential libcurl4-openssl-dev libsqlite3-dev pkg-config git
sudo apt install -y libssl-dev libfuse-dev

Then, clone the OneDrive repository and build the tool:

cd /opt
sudo git clone https://github.com/abraunegg/onedrive.git
cd onedrive
sudo make
sudo make install

Here, there are chances sudo make and sudo make install may not work for you. If that is the case then follow this:

sudo apt update
sudo apt install -y \
  build-essential \
  curl \
  libcurl4-openssl-dev \
  libsqlite3-dev \
  pkg-config \
  git \
  ldc
 
 

Along with this you can try installing this as well

sudo apt install libdbus-1-dev

2. Authenticate OneDrive CLI with Your OneDrive Account

To authenticate with your OneDrive account, run the following command:

onedrive
  1. The CLI will generate a URL for you to open in a web browser.
  2. Follow the prompts in the browser to authenticate your OneDrive account.
  3. Once authenticated, copy the provided authentication code and paste it into your terminal.
  4. To Allow PublicStorage2, I had to give it ADMIN perms from main OneDrive account

3. Sync a Specific Folder from OneDrive to Your VPS

Now that you have OneDrive CLI installed and authenticated, you can sync a specific folder from OneDrive to a local folder on your Linux VPS.

Syncing a Specific Folder

To sync a specific folder from your OneDrive to a local directory, you will use the --synchronize flag with the --single-directory option.

  1. Create the target folder on your VPS: First, create the local folder where you want to sync your OneDrive folder:
    sudo mkdir -p /path/to/local/folder
    sudo chown -R your-user:your-group /path/to/local/folder

So in theory for me it was

sudo mkdir -p ~/OneDriveAlbums
sudo chown -R ubuntu:ubuntu /music/Albums

Here, my local folder was ~/OneDriveAlbums and Navidrome folder was /music/Albums

  1. Sync the specific OneDrive folder

To sync a specific folder (let’s say the folder is called MyMusic in your OneDrive), use the following command:

One Drive by default starts with “My Files” as root so you can start with your first folder Here, in my case that would be “MAIN”

onedrive --sync --single-directory "MAIN/Public/Music/Albums" --syncdir ~/OneDriveAlbums

If the folder structure was changed, then you can try running with --resync

onedrive --sync --single-directory "My Files/MAIN/Public/Music/Albums" --syncdir /var/lib/navidrome/music --resync

Replace "MyMusic" with the exact path of the folder in OneDrive you want to sync. (For example, Documents/MyMusic or Music/Albums).

Replace /path/to/local/folder with the local directory you created earlier.

This will download only the contents of the MyMusic folder from OneDrive to your VPS.


4. Set Up Automatic Sync (Optional)

To keep the folder synchronized automatically, you have two options: either use systemd or a cron job.

Option 1: Using systemd Service for Continuous Sync

If you want to keep the folder syncing continuously (i.e., every time there is a change), set up a systemd service for the OneDrive CLI tool.

  1. Create a systemd service file for OneDrive:

    sudo nano /etc/systemd/system/onedrive.service
  2. Add the following content to the service file:

    [Unit]
    Description=OneDrive Sync Service
    After=network.target
     
    [Service]
    ExecStart=/usr/local/bin/onedrive --synchronize --monitor --single-directory "MyMusic" --syncdir /path/to/local/folder
    Restart=on-failure
    User=your-user
    Group=your-group
    Environment=DISPLAY=:0
    TimeoutSec=600
     
    [Install]
    WantedBy=default.target

    Replace your-user and your-group with your actual username and group name, and adjust the --single-directory and --syncdir options based on your setup.

  3. Enable and start the service:

    sudo systemctl enable onedrive
    sudo systemctl start onedrive
  4. Check the status of the service:

    sudo systemctl status onedrive

This will ensure that OneDrive syncs the MyMusic folder continuously, and any changes made to that folder on OneDrive will be reflected on your VPS in real-time.

5. Ensure Navidrome Accesses the Synced Folder

If you’re using Navidrome to serve your music, just make sure that your Navidrome configuration points to the folder where you’re syncing the music. For example, if you synced to /var/lib/navidrome/music, make sure the Navidrome config file (config.toml or .env) points to that directory:

[music]
music_folder = "/path/to/local/folder"

Then restart Navidrome to load the newly synced content.

sudo systemctl restart navidrome

1. Threads Exceeding CPU Cores Warning

WARNING: Configured 'threads = 8' exceeds available CPU cores (4).
This may lead to reduced performance, CPU contention, and instability. For best results, set 'threads' no higher than the number of physical CPU cores.
  • What’s happening: Your onedrive client is configured to use 8 threads for synchronization, but your system only has 4 CPU cores. This can lead to inefficient use of system resources.

  • Solution: Adjust the threads setting in the onedrive configuration to match your CPU cores. You can go to /opt/onedrive/config and there would a setting which has “Threads” as an option. You can reduce it to 4 in there

2. cURL Version Warning (HTTP/2 Bugs)

WARNING: Your cURL/libcurl version (8.5.0) has known HTTP/2 bugs that impact the use of this client.
Please report this to your distribution, requesting an update to a newer cURL version, or consider upgrading it yourself for optimal stability.
  • What’s happening: Your version of cURL has bugs related to HTTP/2, which could affect the stability of onedrive’s syncing process.

  • Solution: You have a couple of options:

    1. Report it to your distro: Let your distro maintainers know about the issue so they can update cURL.

    2. Upgrade cURL manually: You could manually upgrade cURL to a version that resolves these HTTP/2 issues (or downgrade to an earlier, more stable version).

    3. Ignore it (temporary workaround): If this isn’t causing significant issues, onedrive has automatically downgraded to HTTP/1.1, so you can continue using it without immediate concern.

3. Deprecation Warning: --synchronize

DEPRECIATION WARNING: --synchronize has been deprecated in favour of --sync or -s
DEPRECIATION WARNING: Deprecated commands will be removed in a future release.
  • What’s happening: The --synchronize flag is deprecated, and the new preferred flags are --sync or -s.

  • Solution: Update your command to use the new --sync flag:

    onedrive --sync --single-directory "Albums" --syncdir /var/lib/navidrome/music

4. Application Configuration Change and --resync Warning

An application configuration change has been detected where a --resync is required
  • What’s happening: The configuration of your onedrive client has been updated, and as a result, it needs to perform a full resync of your OneDrive data to ensure that everything is in sync with the new configuration.

  • Solution: Run onedrive --resync to perform a full resync. This will ensure that your local files and the cloud files are synchronized properly with the updated configuration.

    Example:

    onedrive --resync

5. No Backup Config File Warning

WARNING: no backup config file was found, unable to validate if any changes made
  • What’s happening: onedrive is notifying you that it doesn’t have a backup of its configuration file, and as a result, it can’t validate what changes were made.

  • Solution: This is mostly informational. If you’re comfortable with your configuration, you don’t need to worry. However, if you want to keep a backup of your configuration, you can manually back it up:

    cp ~/.config/onedrive/config ~/.config/onedrive/config.backup

Final Command (with fixes):

Taking all of the above into account, here’s how your command might look after applying the changes:

onedrive --sync --single-directory "Albums" --syncdir /var/lib/navidrome/music --resync

Back References: