7

Is there a way to sync a PC with a nextcloud server, but without the desktop GUI?

Syncing should happen as soon as the PC has booted. Even if the user does not log in yet.

I know the nextcloudcmd. I could run a cron job and call ``nextcloudcmd` every N minutes.

But this is not nice.

I really prefer a solution where the sync happens immediately (for example via inotify).

How could this be done?

I think a shell script wrapping nextcloudcmd is just a work-around.

If nextcloud does not provide this, then I will use seafile which can do this. See: https://manual.seafile.com/deploy/start_seafile_at_system_bootup.html

I personally think this is very strange. The GUI can do this. I just want the same thing, but without a GUI. Yes, I could run the GUI in a "fake" framebuffer X environment ... but no, that's too dirty.

guettli
  • 3,811

3 Answers3

3

This requires basic shell scripting: test for the presence of a lock file, if not present create the lock file, run the update, remove the lock file. This way the nextcloudcmd isn't launched several times.

Untested proof of concept:

#!/bin/sh

LOCKFILE=/var/lock/ncupdate.lock

[ -e $LOCKFILE ] && kill -0 $(cat $LOCKFILE) 2>/dev/null  && exit;


echo $$ > $LOCKFILE
nextcloudcmd
rm $LOCKFILE

Update: it tests for the running process, so if the script get killed it will run anyway and overwrite the PID.

wazoox
  • 7,156
1

You can use inotify-tools to execute nextcloudcmd when files change.

#!/bin/bash

DIR_TO_WATCH="/path/to/dir"

echo "Monitoring changes in $DIR_TO_WATCH..."

inotifywait -m -r --exclude ".sync.*" -e modify,create,delete,move "$DIR_TO_WATCH" | while read path action file; do echo "The file '$file' at '$path' was $action" nextcloudcmd ... done

kramer
  • 11
0
nextcloudcmd /local https://DOMAIN/remote.php/webdav/FOLDER_PATH

example, sync folder /backup and the folder Documents in your Remote Nextcloud

nextcloudcmd /backup /https://nextcloud.mydomain.com/remote.php/webdav/Documents

it will ask for username and password to log in manually. In case you automate via cron job, you can add --user and --password to log in automatically

Note: You need to install nextcloudcmd first , here is how to install nextcloud client in Linux : https://www.addictivetips.com/ubuntu-linux-tips/install-nextcloud-sync-client-on-linux/

More usage can see this link: https://docs.nextcloud.com/desktop/2.6/advancedusage.html

Dylan B
  • 159