4

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,113
  • 14
  • 59
  • 110
  • 1
    Running `nextcloudcmd` upon an `inotify` event should be trivial. What have you tried? But: This would be one-way sync only, as you wouldn't learn about remotely changed files ... – Sven Mar 07 '19 at 09:42
  • @Sven if there are several thousand files, then nextcloudcmd takes some seconds. If there a lot of changes in short time, there will be very high load on the machine since nextcloudcmd runs several times parallel. I would like to avoid this. – guettli Mar 07 '19 at 10:01

2 Answers2

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
  • 6,782
  • 4
  • 30
  • 62
  • I don't trust locking like this. If the script gets terminated between creating the lock and deleting the lock, then the lock file will never get deleted and nextcloudcmd will never run again. – guettli Mar 14 '19 at 08:12
  • 2
    @guettli I tried to motivate you on solving the problem yourself :) So I've updated my answer so that it actually check if the script is still running. – wazoox Mar 15 '19 at 15:35
  • I guess your solution works. But if a real solution is not available for nextcloud, then I will use seafile, which can do this. I updated the question. – guettli Mar 15 '19 at 20:26
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
  • 161
  • 1
  • 3