0

Could anyone suggest some good ways of backing up a file from a Windows machine to a Linux platform using a batch file of powershell command?

My goal is to monitor a file for modification using a powershell script on startup, and then to back it up to the linux machine when modified.

Here is the lovely powershell script written by BigTeddy which I am in the proccess of modifying to execute a transfer script on the 'FileChanged' event:

The original can be found here

$folder = 'c:\Documents and Settings\Administrator\My Documents'
$filter = 'myFileToWatch.csv'

$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}

Register-ObjectEvent $fsw Changed -SourceIdentifier FileChanged -Action {
    <...CODE TO TRANSFER FILE...>
}

I have investigated several possibilities:

  • rSync as part of Cygwin
  • cwRsync
  • robocopy

Unfortunatly I have had little success with Cygwin as an apparent bug has prevented the 'postinstall' from completing .. (but thats another story)

I have also run into problems with Windows refusing to recognize the installer for the Windows Server 2003 Resource Kit Tools which contains said Robocopy. It has now decided to play ball.

cwRsync(free) does not support serving files.

I am very new to digging around in the depths of Windows so I imagine there are many possibilities of which I am unaware.

xeuari
  • 68
  • 7
  • 1
    Try `pscp.exe` or WinSCP's .Net assembly. See this question: [How to use PSCP to copy file from Unix machine to Windows machine where target path has spaces?](http://superuser.com/questions/532919/how-to-use-pscp-to-copy-file-from-unix-machine-to-windows-machine-where-target-p) – beatcracker May 14 '16 at 18:08
  • 1
    Alternatively, if the Linux server is running Samba you could use `robocopy` to transfer files to a shared folder. – Ansgar Wiechers May 14 '16 at 21:27
  • +beatcracker +Ansgar Wiechers Thanks for the answers. All good suggestions. I have decided to go with WinSCP's .NET assembly as it is documented in a simple way and will integrate with my script nicely. – xeuari May 18 '16 at 22:02

0 Answers0