File write times in .NET local drive vs. NAS drive
-
Hi, I'm trying do write a backup program in VB .NET. It needs to avoid backing up files that have already been backed up and so it compares the last write times of the source and backup files. If they are the same, the backup for the file is not performed. If both the source file the backup file are on the local hard drive, the comparisons work correctly. If both the source file the backup file are on a Network Attached Storage drive, the comparisons work correctly. But if the source file is on the local hard drive and the backup file is on the Network Attached Storage drive, the comparison always says the they are different no matter what. Code: (I'm using the CompareTo method.) Dim SourceHasLaterDate As Int16 = SourceWriteTime.CompareTo(BackupWriteTime) Is there any way I can get an accurate result for the third condition? Thanks, Mike PS: I'm modifying the backup program written by Taner Riffit.
-
Hi, I'm trying do write a backup program in VB .NET. It needs to avoid backing up files that have already been backed up and so it compares the last write times of the source and backup files. If they are the same, the backup for the file is not performed. If both the source file the backup file are on the local hard drive, the comparisons work correctly. If both the source file the backup file are on a Network Attached Storage drive, the comparisons work correctly. But if the source file is on the local hard drive and the backup file is on the Network Attached Storage drive, the comparison always says the they are different no matter what. Code: (I'm using the CompareTo method.) Dim SourceHasLaterDate As Int16 = SourceWriteTime.CompareTo(BackupWriteTime) Is there any way I can get an accurate result for the third condition? Thanks, Mike PS: I'm modifying the backup program written by Taner Riffit.
there are a couple of reasons why two DateTimes that should be equal actually can be different, here are the most important ones: - some file systems only have a resolution of 2 seconds (long ago the date was stored in 16-bit, and the time in another 16-bit number (5-bit for the hour, 6-bit for the minutes, and 5 rather than 6 for the seconds). - some file systems have a different way of dealing with daylight savings time (should the correction be applied dynamically, or should the corrected time be stored in the directory information?). When I created my backup/synchronize utility years ago, I ended up comparing DateTimes with a tolerance: any pair of DateTime values that differed by -1, 0 or 1 hour give or take -2 to +2 seconds, I consider identical. And yes, that could lead to false identicals, but since I also compare file size and file name, chances are slim. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
there are a couple of reasons why two DateTimes that should be equal actually can be different, here are the most important ones: - some file systems only have a resolution of 2 seconds (long ago the date was stored in 16-bit, and the time in another 16-bit number (5-bit for the hour, 6-bit for the minutes, and 5 rather than 6 for the seconds). - some file systems have a different way of dealing with daylight savings time (should the correction be applied dynamically, or should the corrected time be stored in the directory information?). When I created my backup/synchronize utility years ago, I ended up comparing DateTimes with a tolerance: any pair of DateTime values that differed by -1, 0 or 1 hour give or take -2 to +2 seconds, I consider identical. And yes, that could lead to false identicals, but since I also compare file size and file name, chances are slim. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
When I compensate for the differences in the storage devices by converting the last write date/time results to concatenated strings containing Year, Month, Day, Hour, and Second, the comparison works properly. With this approach I'm assuming that going to the second is accurate enough. You may want to use the same approach with yours. Thanks for the explanation. Here is my code:
Dim SourceWriteTime As DateTime = CDate(File.GetLastWriteTimeUtc(SourceFileName))
With SourceWriteTime
Test1 = .Year & "/" & .Month & "/" & .Day & "/" & .Hour & "/" & .Minute & "/" & .Second
End WithDim BackupWriteTime As DateTime = CDate(File.GetLastWriteTimeUtc(BackupFileName))
With BackupWriteTime
Test2 = .Year & "/" & .Month & "/" & .Day & "/" & .Hour & "/" & .Minute & "/" & .Second
End With
Dim SourceHasLaterDate As Int16 = Test1.CompareTo(Test2)If the SourceHasLaterDate > zero, I backup the file.