2

I can use WinSCP GUI just fine to copy a folder from a Linux server locally to a Windows server for backup, using the "updated files/folders only" option (sort of an rsync).

I'd like to use WinSCP's command line utility or something similar that I can schedule through the Windows task scheduler to grab the folder (plus subfolders/files) from the Linux server nightly and store it on the Windows server.

I looked at the WinSCP docs but I'm scared to try any of the commands without really knowing which ones to run, etc. because the last thing I want is to accidentally write the files in the wrong direction.

Anyone able to tell me the WinSCP commands (or a similar utility) that I can schedule to do the following:

Copy folder/subfolder/files (only new or updated) from "/shared/svnrepos" on the linux server to "\WINSERVER\BACKUP"

TheCleaner
  • 32,352
  • 26
  • 126
  • 188
  • If you are scared/worried about something, then why not setup a VM for testing things in? One good way to figure things out is to just try things and see what happens. You won't get that experience, if you don't create an environment where you can test things safely. – Zoredache May 17 '12 at 19:56
  • True. I was probably looking for the easy way out. I'll do some testing on my own and then if necessary update the question or just close it. – TheCleaner May 17 '12 at 20:04
  • Asking the question is fine, someone might know the answer. If you do figure it out, then you can/should post an answer to this so that you can help the next guy. – Zoredache May 17 '12 at 20:09
  • You may want to check out `putty.exe` and its scp equivalent, `pscp.exe` – ivanivan Mar 15 '18 at 16:58

2 Answers2

4

I think the documentation explains it pretty clearly: http://winscp.net/eng/docs/scriptcommand_synchronize

You want to use the synchronize command instead of a get command.

When the first parameter is local, changes from remote directory are applied to local directory. When the first parameter is remote, changes from the local directory are applied to the remote directory.

As you can see there is very little risk of damaging your servers files if you use syncronize local, since it will take the remote directory and apply it to your local directory.

I would create a script file and then add a scheduled task to call WinScp with:

WinScp.exe /script="d:\SvnBackupScript.txt"

Then put something like the following in your script file:

synchronize local d:\svnBackup /shared/svnrepos

Make sure you have your configuration and connection setup per the documentation.

You can always run it in cosole mode and test your commands:

WinScp.exe /console

Then just type the commands you want in your script

Duane
  • 156
  • 1
0

Maybe rclone (https://rclone.org/commands/rclone_sync/) is worth to try. Written in Go, has several binaries (Windows included) and it permits to sync directories from Linux to Windows using several protocols - including SSH.

You have to first configure it (that is define a remote host alias, protocol and credentials) and then you execute from command line:

rclone sync remoteserveralias:/the/dir/path localpath

WARNING: Since sync deletes files in the destination (it tries to have two identical copies - remote vs local), a safer approach is to use the copy command which differentially copies files from source to destination without any deletion.

See https://rclone.org/commands/rclone_copy/

tmanolatos
  • 101
  • 3