Sample scripts to save files from linux server to nextcloud server

I have been using crontab to set up a mysql file transfer from a remote server to GoogleDrive which runs every hour. I want to change the destination from GoogleDrive to my new Nextcloud server. Can anyone help with a sample script of how this is done please…I have searched through this forum with no luck…
kind regards…

Is the “linux server” in question the same or other then your nextcloud host?


ernolf

Here is described how you can connect with webdav using curl:

https://docs.nextcloud.com/server/latest/user_manual/en/files/access_webdav.html#accessing-files-using-curl

Other posibility is transfering the file(s) in question with ssh or scp and then run

occ files:scan --path=$path_to_file

Much and good luck,
ernolf

1 Like

They are different servers.

After some research i think i could use rclone ??

rclone alone is not enough, since you have to run the occ command to add those files to the filecache table in the database to make them visible.

I would recomend to use curl like I linked you. That is the recommended client for commandline use.


Much and good luck,
ernolf

Hi, can you give an example of the path (path=$path_to_file). Is it something like:
http://mywebsiteaddress:XXXX/nextcloud/foldertosavefileto

Kind regards…

In the manual I linked above it is explained more than clearly, even with examples, so I don’t really know where to start.
Of course, you have to start with it first and build it up step by step on the command line, try it out using the example, and then you will familiarize yourself with it by doing (and making mistakes).
You can then use it to develop your functions that you can integrate into your scripts and include on various places.


Much and good luck,
ernolf

I don’t know if it’s a good idea to store the backup of a database on a Nextcloud. In the past, you would have simply used an FTP or better SFTP account for this. But never mind.

In the documentation:
curl -u user:pass -X MKCOL "https://example.com/nextcloud/remote.php/dav/files/USERNAME/$(date '+%d-%b-%Y')"

the path of the user files is
/path/to/nextcloud/data/USERNAME/files

That is not correct. Is your “nextcloud” a user or a subdirectory? You need something like this:
https://example.com/nextcloud/remote.php/dav/files/USERNAME

You can find your WebDAV url in https://cloud.server.tld/apps/files (web gui files app) and then on the button left Files settingsWebDAV.