I had a task to automate customer files backup from Windows 10 desktop to NextCloud server. The main idea to keep offline backup that will be updated automatically few times a week (not every day). Main requirement for this was to reduce human interaction with the process as much as possible and exclude some files from backup process all together.
Initially I was not concerned about this – after all there is official Nextcloud Windows desktop client along with command line tool, ownCloud desktop client is also compatible and also has command line tool included, so I thought to myself out of these two I should be able to put together some kind of automation.
Well, to my dismay both official clients proved to be completely useless in unattended automation. Whatever webDAV protocol limitation there were, both command line clients had it, for example simple task of synchronizing single directory, say d:\testsync to remote/testsync was impossible because neither client could create 1st level folder on remote server. It could be underlying limitation or bug of Qt implementation of WebDAV protocol, but figuring that out was out of scope of my task.
I needed reliable and compact (this is not the requirement but always welcome, considering that official clients were dragging with them about 100Mb of Qt core libraries and are useless for my purposes) WebDAV client for Windows with automation and I needed it yesterday.
Then, I discovered that WinSCP supports WebDAV and allows scripting advanced enough to help me with my task.
After some testing I cam up with the following system:
- CMD script started by Task Scheduler, executes WiSCP console tool with the script, in the loop until it exits with “success” result
1234567891011121314@echo offremrem winscp starter scriptrem restarting winscp until errorlevel is 0rem:againwinscp.com /ini=nul /script=syncscript.txt /log=syncresult.txtif %ERRORLEVEL% neq 0 goto againecho Successexit /b 0
- WinSCP console util executes script that synchronizes local storage with NextCloud server
12345open https://<username>:<password>@nextcloud.serveraddress.here/remote.php/webdav/synchronize remote -filemask="| *.mdf;*.ldf;*.bak;*.tmp;*RECYCLE.BIN/*; S-1*; ~$*.*; desktop.ini" c:\foldertosync\exit
filemask covers exclusions
This solution synchronizes about 200Gb of data from single Windows every 2-3 days. It’s pretty fast, compact and the best part of it is that it transfers only changed files. Case closed.