Question: I have a new wireless router in my home and have a 3 TB drive hooked up to it. I would like to write a backup script in cygwin which will copy over any changed files to the external HD.

For starters, how do I cd into the hard drive? In windows file explorer I simply type //192.168.1.1 and it takes me to the network drive. However, when I type cd //192.168.1.1 it does not work. So how can I change directory into the HD?

Secondly, does anyone have advice on how to write a good backup script to copy certain directories (recursively) if they have changed?

Answer: You can look at mounted drives in the cygwin UNIX environment’s view of the underlying Windows OS by looking in /cygdrive. ?Do a df at the cygwin shell prompt (usually bash) to see where the drives are mounted. ?Here’s the documentation as to where mounted drives are found. ?For instance, to change to the network drive mounted as Windows f:, you’d cd to /cygdrive/f, as in:

$ cd /cydrive/f

Here’s an example:

  • OS X Mavericks (UNIX) has a 3 TB drive mounted as /Volumes/Time Machine
  • A Virtual Windows XP (VM) is running on OS X, and sees /Volumes/Time Machine as X:
  • Cygwin is running on the XP VM, and sees /Volumes/Time Machine as /cygdrive/x or even x:
  • ?

    $ ls x:

    Here’s a picture:

    enter image description here

    If the external HD isn’t currently mounted on the Windows host and already mapped to a mount point in /cygdrive, then you may need to mount the network share yourself. ?Take a look at cygwin’s implementation of the UNIX mount command.

    Another way to view the network folder is along the lines of the syntax which you used – I have my OS X server exporting my OS X login folder, whmcclos, as an SMB shared folder. ?I can set my current working directory to that shared folder from cygwin, on my Windows XP VM, running under OS X, as follows:

    $ cd //192.168.0.2/whmcclos

    That way, I don’t even need to have the folder mounted as a drive letter to view it from within cygwin.

    For backing up files that have changed, rsync will recursively backup only the files in a directory tree that have changed – it computes a minimal backup set, and only backs up what has changed, and has loads of options, including copying to network drives and being able to be used with encryption via ssh. ?Here’s some hints as to using rsync with cygwin. ?Here is a command to compress and archive (recurse) source on drive mounted as c: ?and put in target on drive mounted as f: on Windows host underlying cygwin.

    $ rsync -avz /cygdrive/c/path/to/source /cygdrive/f/path/to/target

    If you need any further assistance, please do leave a comment.