Scheduling synchronization from Linux to Windows to Owncloud
This is somewhat convoluted, but works, and also offers a backup of sorts as a bonus.
The steps
- Download and install WinSCP on your Windows computer.
- Create a site account to your linux computer in WinSCP. Save the password.
- Login to the linux site.
- Click on the file or folder you want to schedule a transfer for.
- Click menu Files/File names/Generate file URL.
- Check User name, SSH host key and Password.
- Click Close or Copy to clipboard as appropriate.
- I recommend opening a new Notepad++ session and pasting the generated URL there. Save it!
- Click menu Session/Generate session URL/code.
- On the URL tab check User name, SSH host key, Password and Initial directory.
- On the Script tab choose format Command-line.
- Click Copy to clipboard.
- Paste it to the same file opened in 5.2. Save it!
- You should now have two lines in Notepad++.
- Combine them so they look something like the below. You should have one line, possibly word-wrapped.
"C:\Program Files (x86)\WinSCP\winscp.exe" /log="D:\users\Sorin\owncloud\Software.backup\cyndane\WinSCP.log" /ini=nul /command "open sftp://YOURUID:
This email address is being protected from spambots. You need JavaScript enabled to view it. :22/home/sorin/etc.backup/ -hostkey=""ssh-rsa 2048 keykeykeykeykeykeykeykey"" -rawsettings PingType=1 Compression=1 ProxyPort=0" "synchronize local D:\users\Sorin\owncloud\Software.backup\cyndane\etc.backup\ /home/sorin/etc.backup" "exit" - Save the file.
- Add or change the file extension to eg .bat as neccessary.
- Combine them so they look something like the below. You should have one line, possibly word-wrapped.
- Open a Command prompt in Windows.
- Change directory to wherever you saved the file from 7.2.
- Do a test run. If it worked, go to 11. Else review your command and correct as neccessary.
- Create a scheduled task in Windows to run the transfer. See https://winscp.net/eng/docs/guide_schedule for more info.
Summary
I use this script to synchronize any files from various folders on one of my Linux servers. I further make use of my Owncloud linux server and the Owncloud Windows desktop sync client to sync the tars and have them in more than one place, thus effectively having an off-site backup copy.
The command in 7.1 basically means "from the folder /home/sorin/etc.backup synchronize all files to the local folder D:\users\Sorin\owncloud\Software.backup\cyndane\etc.backup".
synchronize local D:\users\Sorin\owncloud\Software.backup\cyndane\etc.backup\ /home/sorin/etc.backup/
The folder D:\users\Sorin\owncloud and its sub-folders is then synced to the Owncloud server using the Owncloud Desktop Sync Client.
Also see the article Scheduling file transfers from linux to Windows.
Sources
https://winscp.net/eng/docs/ui_generateurl
https://winscp.net/eng/docs/guide_schedule
https://winscp.net/eng/docs/scriptcommand_synchronize