How to sync a folder on a server?

I’m sure this will be easy, but I just can’t see how to do it.

We have a web server that generates files from various data. The files are put into a big directory structure. I would like to sync that directory structure to a directory on a separate Nextcloud server. From there we have users being given access to various directories through shares, and that bit I can understand.

What I am not sure about is how to sync the directory structure on our headless CentOS web server to the remote Nextcloud server. Is there a PHP script I can use to do that? Or would I need to write my own script that pushes files over via webdav? Or is there another API I should use? Or is there a way to do it by installing Nextcloud at both ends and getting them regularly synced to each other?

Ideally I would not have to create my own syncing code - I would just like to point some tool at the local directory and the Nextcloud account and say, “syn 'em up, please”. Running cron to do a sync catch-up once and hour would be sufficient if that was the best approach.

Thanks :slight_smile:

Edit: if I understand correctly, I can put files into the data area for a user then rescan that user for the new files to be recognised. That would work for a local Nextcloud. However, I do want to get the files physically onto the remote server. Maybe cron running rsync to pull the [changed] files over, then a files:rescan to scan for any changes? Or maybe it’s better to drop files into an “external local storage” directory if I’m moving them around from outside the application? So many options! What would be the best approach?

+1 this :slight_smile: Unless you’re explicitly wanting to use WebDav, data transfer to the NC server is really up to you.External storage is the better option if you’re not using WebDav though, as copying directly into /data/ isn’t ideal.

Okay, thanks. Playing with it now, and it seems to work well. I can use ssh/rsync to push the files to the remote storage efficiently and quickly, and don’t have to worry about telling Nestcloud to sync up the new and updated files. By pushing the files in one direction, it also means I can remove them from the old server after a while to save some space.

1 Like