I take it that it is a settled fact that NextCloud devs. cannot be persuaded to add a âone-way syncingâ feature to the official NextCloud desktop syncing app (âNextCloud Filesâ), and this thread is not attempting to wake up any sleeping dogs. What can those of us who need this feature use though? Again, what I need is some app that has, by-and-large, the same features as the official NextCloud app PLUS one-way syncing (desktop to NextCloud cloud). As far as I can tell, rclone ainât it. Note that it should preferably be open source, and ideally already packaged as Flatpak, or Docker image or the like.
There is no such thing like âone-way-syncâ⊠depending on the direction what should happen with new/deleted files? If you speak about scheduled snapshots/copies it is possible to do such task using webdav and curl (or GitHub - j4m3z0r/davsync: DavSync: like rsync, for WebDAV)
Thanks, looks nice for P2P, only I already have a personal cloud that I went to great lengths to build. Also, they seem to have deprecated the Docker image, which is a shame. Finally, while I may be able to cram the RPM onto my system (ClearLinux), I am not sure if TrueNAS takes RPMs.
One-way sync scenarioâFolder F of computer A is one-way synced with folder FC of computer C (the âcloudâ):
All changes in folder F are automatically replicated in FC, including deleted files. (Nice-to-have option at this point: delete file from F without deleting from FC. (Deleted F files to be renamed to something else in FC.))
All changes to files in FC that originate from F and have the same names as their F counterparts to be automatically replicated in F.
Any files in FC that do not come from F (or originate from F files but were deleted from Fâsee ânice-to-have optionâ above), to be excluded from syncing.
The crucial requirement is that syncing happens in (almost) real time, hence the âautomatic(ally)â attribute. Can Cron jobs be triggered by changes to the F folder? Any change to the content of F needs to be immediately propagated to FC; periodic backups ainât cuttinâ it, as often as they may be.
Whenever people here ask about one-way sync, I always wonder what their actual use case is, and whether there might be a better way to do what they are trying to achieve, or whether Nextcloud is even the right tool for the job
And no, I donât mean the technical description of the process that you described here, I mean the actual use case. What actual real-world problem are you trying to solve with this rather complex process?
Is it about normal files that you work with day-to-day? is this meant to be some backup concept? is it about a kind of autouload of files that are read by a scanner, camera, auto-generated by some tool�
/read https://help.nextcloud.com/t/one-way-syncing-for-linux/218202/10
Make a suggestion on how best to solve this with a Python script
Based on the discussion in the Nextcloud forum regarding one-way syncing on Linux, a Python script can be created to handle real-time one-way sync from a local folder to Nextcloud, avoiding traditional scheduled sync via cron.
Best Approach: Using Python + Watchdog + WebDAV
Since the user requires real-time sync (not periodic), a solution can be built using:
Watchdog â to detect file changes in the source directory.
WebDAV (Nextcloudâs API) â to upload, update, or delete files on the Nextcloud server.
Python Script Plan
Monitor a local folder (F) for changes â Detect file creations, modifications, and deletions.
Sync changes to Nextcloud (FC) â Using WebDAV:
Upload new files.
Update existing files.
Remove files from Nextcloud when deleted locally.
Ignore files that originated from FC but were modified on the server.
Handle errors and log sync activity.
Implementation: Python Script for One-Way Sync
Hereâs a Python script that continuously syncs a folder to Nextcloud in real-time:
import os
import time
import requests
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
# Nextcloud WebDAV Credentials
NEXTCLOUD_URL = "https://your-nextcloud.com/remote.php/dav/files/your-username/"
USERNAME = "your-username"
PASSWORD = "your-password"
# Local folder to sync
LOCAL_FOLDER = "/path/to/local/folder/"
class SyncHandler(FileSystemEventHandler):
"""Handles file system events and syncs with Nextcloud via WebDAV."""
def __init__(self):
super().__init__()
def upload_file(self, file_path):
"""Uploads or updates a file in Nextcloud."""
relative_path = os.path.relpath(file_path, LOCAL_FOLDER)
nextcloud_path = f"{NEXTCLOUD_URL}{relative_path}"
with open(file_path, "rb") as file:
response = requests.put(nextcloud_path, data=file, auth=(USERNAME, PASSWORD))
if response.status_code in [201, 204]:
print(f"Uploaded: {relative_path}")
else:
print(f"Failed to upload {relative_path}: {response.status_code}")
def delete_file(self, file_path):
"""Deletes a file from Nextcloud."""
relative_path = os.path.relpath(file_path, LOCAL_FOLDER)
nextcloud_path = f"{NEXTCLOUD_URL}{relative_path}"
response = requests.delete(nextcloud_path, auth=(USERNAME, PASSWORD))
if response.status_code == 204:
print(f"Deleted: {relative_path}")
else:
print(f"Failed to delete {relative_path}: {response.status_code}")
def on_created(self, event):
"""Handles file creation."""
if not event.is_directory:
self.upload_file(event.src_path)
def on_modified(self, event):
"""Handles file modification."""
if not event.is_directory:
self.upload_file(event.src_path)
def on_deleted(self, event):
"""Handles file deletion."""
if not event.is_directory:
self.delete_file(event.src_path)
if __name__ == "__main__":
event_handler = SyncHandler()
observer = Observer()
observer.schedule(event_handler, LOCAL_FOLDER, recursive=True)
print(f"Watching {LOCAL_FOLDER} for changes...")
observer.start()
try:
while True:
time.sleep(10)
except KeyboardInterrupt:
observer.stop()
observer.join()
How It Works
Listens for file changes in LOCAL_FOLDER using watchdog.
Uploads new or modified files to Nextcloud via WebDAV.
Deletes files from Nextcloud if they are deleted locally.
The real-world problem is precisely the problem that one tries to solve using two-way sync ⊠except one very important difference: my Nextcloud cloud is 16T, while my local HDD is 512G in size. The Nextcloud box culls files from 4 other LAN boxes.
Unfortunately, if you are on Linux, this is still âexperimentalâ, which means that only the âbarbonesâ variant using placeholder files is implemented. It does work though.
Could there be a solution whereby you set permissions on some local folders such that the sync down to the desktop can only write into certain areas and not others?
Even without virtual files, you can choose which folders youâd like to sync. I use like this a few working folders, where I have files that I currently work on. Other stuff I only sync temporarily: