Time granularity in Robocopy

We came across an issue where Robocopy was thinking that many files on a given server had been modified from the version that was on a different server.
Not a big deal, except "changed files" = "files that need to be copied out", and there were a lot of files that would have been copied over slow links to distant servers.
The wierd thing - some folks were seeing the problem with Robocopy, and some were not.  Finally narrowed it down.. the people who weren't seeing the problem were on an older version of Robocopy (confirmed 9-4-07: v 1.95) and the folks who were were on XP010.  However, that doesn't explain the root cause.
If you looked at the two files in Explorer, the Modified dates were identical.  The files themselves were identical.  However, Robocopy said one was Newer.
Wrote a stupid little app that gave the Modified time down to the millisecond.. still identical.
However, when I got down to the Ticks level (100 nanosecond), the files had different timestamps.. a mirroring utility that was in use on some servers only replicated the time down to the millisecond.  The old Robocopy only looked as far as Milliseconds, where the new one (and our primary directory replication tool) looked all the way at the Ticks level.
The fix?  Wrote another stupid little app that compared two files - if the date, hour, minute, second, and millisecond were the same, but one of them had zeroes in the last four characters of the Ticks value (ticks % 10000), set the time of the zero to be the time of the not-zero.  Beats copying all those files out.
Code?  Here you go:
 
long filetick = File.GetLastWriteTime(file).Ticks;
long badfiletick = File.GetLastWriteTime(badfile).Ticks;
DateTime fileDT = File.GetLastWriteTime(file);
DateTime badDT = File.GetLastWriteTime(badfile);
bool filetrunc = false;
bool badtrunc = false;
filetrunc = IsTruncated(filetick);
badtrunc = IsTruncated(badfiletick);
   if ((fileDT.Date == badDT.Date) && (fileDT.Hour == badDT.Hour) && (fileDT.Minute == badDT.Minute) && (fileDT.Second == badDT.Second) && (fileDT.Millisecond == badDT.Millisecond))

      if (filetrunc || badtrunc)
           if (!(filetrunc && badtrunc))

                {

                      {

                          if (filetrunc)

                              {

                               File.SetLastWriteTime(file, File.GetLastWriteTime(badfile));

                               }

                          else if (badtrunc)

                               {

                               File.SetLastWriteTime(badfile, File.GetLastWriteTime(file));

                               }

                       }

                 }
and



        public bool IsTruncated(long ticks)


        {

            return ((ticks % 10000) == 0);

        }

As always, if there's a better way to do this, please let me know - I'm still a junior coder.
Print | posted on Monday, September 03, 2007 6:40 PM

Feedback

# re: Time granularity in Robocopy

left by HyPet at 7/9/2009 3:48 AM Gravatar
Try to use the /FFT switch instead, it mainly solved the issue for me.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: