10

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?

15

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:

  1. OS X Mavericks (UNIX) has a 3 TB drive mounted as /Volumes/Time Machine
  2. A Virtual Windows XP (VM) is running on OS X, and sees /Volumes/Time Machine as X:\
  3. 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.

3
  • Thanks, I still have a question - when I used -avz, it does not correctly copy permissions. I get rsync: failed to set permissions on "<path>": Permission denied (13). Any idea how to correct this? – drjrm3 Jan 6 '14 at 0:03
  • It sounds like something I saw once with permissions, specifically with ACL permissions. Look at the permissions including the ACL with /bin/ls -le /path/to/source and also /bin/ls -le /path/to/target to check out not only the various folder permissions, but the ACL permissions of and in those folders. See man ls and the -le switches and man chmod and the +a and -a switches. I'm 99% certain that it has something to do with permissions. Start with rsync'ing a subset of the source tree to say, /tmp, where you know you have write permission, and see how that works. – Billy McCloskey Jan 6 '14 at 3:55
  • 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.