** EDIT ** : that didn’t work. It only synchronizes on first launch, but then no synchro. The reason is that the source directory of lsyncd is a webdav share, and there is no kernel notification mechanisme available for these remote file systems (this includes samba shares, sshfs etc.). Any recommendation welcome.
Dear nc,
I was wondering if there was a nextcloud cli client and got this thread. I wasn’t satisfied with the given answers, so here’s how I ended up doing a realtime synchronization between a nextcloud web folder and a windows shared folder using webdav mount (on linux) and lsyncd for realtime synchronisation :
Ok my solution to this was to mount the nextcloud share via webdav and sync with a windows shared directory via lsyncd. Here’s a short how-to :
On the machine where you want to access the nextcloud share, where <user> and <password> are nextcloud credentials
$ apt-get install davfs2
$ mkdir /mnt/webdav-<user>
added following line to /etc/fstab :
https://mycloud.tld/remote.php/dav/files/<user>/ /mnt/webdav-<user> davfs user,rw 0 0
added following line to /etc/davfs2/secrets
/mnt/webdav-<user> <user> <password>
Test the mount
$ mount /mnt/webdav-<user>
/sbin/mount.davfs: warning: the server does not support locks
$ ls /mnt/webdav-<user>/
total 65M
drwxr-xr-x 3 root root 0 May 23 10:36 '1. INTRODUCTION'
drwxr-xr-x 2 root root 0 May 23 08:16 '2. CERCLES'
-rw-r--r-- 1 root root 154 May 20 15:50 'a lire absolument.txt'
-rw-r--r-- 1 root root 12M May 16 14:54 'essai seulement CHANSON - JOYEUX ANNIVERSAIRE.webm'
drwx------ 2 root root 0 May 23 11:04 lost+found
-rw-r--r-- 1 root root 1.8M May 21 13:44 'Mohamad - مراسلة تجمع جبهة المسقبل بشلغوم العيد--جاهزة.MP3'
-rw-r--r-- 1 root root 1 May 20 15:46 Readme.md
drwxr-xr-x 2 root root 0 May 21 17:27 RNAAMA-Vote2021
-rw-r--r-- 1 root root 4.7M Jul 14 2009 'Sleep Away.mp3'
-rw-r--r-- 1 root root 43M Jan 28 2019 test-chaouche-js-party-32.mp3
-rw-r--r-- 1 root root 13K Mar 4 14:13 'توقعات الأخبار لأيام الجمعة السبت و الأحد الاسبوعية1.docx'
-rw-r--r-- 1 root root 3.6M May 20 14:07 'مراسلة من إذاعة تيارت حول التجمع الشعبي- للأمين العام للتحالف الوطني الجمهوري.mp3'
-rw-r--r-- 1 root root 542K May 20 12:15 'ومضة التشريعيات الطريق الى البرلمان ليلى.mp3'
$
Success. Now I can sync with the windows shared directory like this :
Add following line to /etc/fstab to mount the windows shared directory
//192.168.100.150/ftp-echanges /mnt/ftp-echanges cifs uid=0,credentials=/root/DATA/smb.connect,iocharset=utf8,noperm 0 0
Add the necessary credentials to /root/DATA/smb.connect which supplied in the fstab line, in the fs options field.
Warning : the credential file must not have spaces between fields and values. So instead of
username = <user>
password = <password>
domain = <domain>
You need
username=<user>
password=<password>
domain=<domain>
Mount the shared directory :
$ mount /mnt/ftp-echanges
create /etc/lsyncd.conf and add a sync group :
sync {
default.direct,
source = /var/www/nextcloud/data/<user>/files/,
target = /mnt/ftp-echanges/legislatives2021/
}
edit /etc/init.d/lsyncd to point to the new /etc/lsyncd.conf configuration file
CONFIG=/etc/lsyncd.conf
restart lsyncd
$ service lsyncd restart
Done. Now we have realtime one-way synchronisation between nextcloud webdav share and the windows share (the windows share will at all times reflect what’s in the nextcloud share).