dfog has asked for the wisdom of the Perl Monks concerning the following question:

I have several servers in a multiple load balancing situations. They are running Windows2000, with IIS as the web server. The contents of one set of servers are constantly changing due to user uploads (these two are always in sync, as copy commands are given as each file is uploaded/deleted). At a later time, these files are then copied over to another set of Load Balanced servers, using File::Copy.
My question is if at a later date, I want to only move over changed files, can I compare them using
if (-M $File1 != -M $File2) { copy ($File1, $File2); }
or is the assumption that the last modified time does not survive the copy. My experience has been that if you copy a file, it maintains its last modified time, but I would like some confirmation that this is true. Any insight into this would be greatly appreciated.

Thanks
Dave

Edit 2001-03-15 by tye, changed title

  • Comment on Preserving "last modified" time stamp when copying files with File::Copy
  • Download Code

Replies are listed 'Best First'.
(tye)Re: Preserving "last modified" time stamp when copying files with File::Copy
by tye (Sage) on Mar 15, 2001 at 21:49 UTC

    "Good" ways of copying files preserve the "last modified" time of both the original file and the copy (well, it'd have to be a particularly bad form of copying to modify the "last modified" time of the original, eh?). I suggest you test File::Copy to verify that it does this in your specific configuration.

    One problem under Windows is that different file systems have different resolutions for their file time stamps (or, that is my guess at the source of the problem). This can mean that the two files end up with slightly different time stamps. I haven't investigated this fully but did put an "off by one (minute)" hack into some code I wrote that compared file modification times in Windows. ):

            - tye (but my friends call me "Tye")
      Thanks. There is no problem with the system, as I haven't quite finished writing it yet. The question is more of a preventive measure. All the systems were configured at the same time, with the same software, and as far as I know, the same hardware. Because of this, the resolution shouldn't be a problem. (Of course, you never know with Windows). This just seems the easiest, least load intensive way to compare the two files, though if anyone has any other ways of checking that are more exact and about the same load, I would love to hear them.
      Dave
Re (tilly) 1: Preserving "last modified" time stamp when copying files with File::Copy
by tilly (Archbishop) on Mar 17, 2001 at 21:00 UTC
    You really want to use rsync for this. Trust me.