Touching dates - please a plugin for this (or help me make a script?)


Recommended Posts

Good health to everybody.

 

I have a weird issue, that I am not sure where this came from.
It relates to files I sync from USB disks to my array and these days also back to the USB disks.

I use DirSyncPro (but not a DirSyncPro issue I think since the files have the issue already).

Seems many files have invalid datestamps (like 1969 or the 22nd century)- and the invalid datestamp propagates differently between the NTFS USB disks and unRAID array.

Can someone make a simple plugin OR help me with a script to check the whole array (or per share - and if possible also on the NTFS disks as they are mounted by Unassigned Devices) for invalid datestamps (or possibly anything before 1996 -?- and after current date/time) and touch the files with current date OR a preset date I define? (this will help identify which files were touched afterwards)

Help please?

 

Link to comment

Never done this but I would use find on the console with the days option. E.g.:

 

find /mnt/user/yourfolder -type f -mtime +300 -print

 

In the above example - Files older than 300 days will be found.

 

To change that modification time to the current one, you can use the exec option, but be really, really carefully about what you do:

 

find /mnt/user/yourfolder -type f -mtime +300 -exec touch {} \;

 

Disclaimer: Use at your own risk.

 

Edited by hawihoney
Link to comment

Here is what I did in the end.

 

First I set the commands to check for invalid dates.

find /mnt/user -type f -mtime 8500 -ls
## Consider before early 1997 that the dates are invalid and usually they are. ##
## Note that Windows and Linux showed some of them DIFFERENTLY ##
## meaning "edge" dates behave differently between the two OS! ##
find /mnt/user -type f -newermt today -ls
## I didn't find parameter "today" mentioned anywhere but suspected it works and from my checks, it does. ##

Interesting trivia with -mtime 8500 (which is January 29 1997 if run today), is that few files (with obviously invalid dates) showed up at January 29, 28 and 27 of 1997, but no file before that date! Any ideas what OS intricacy does that?

When I rerun the tests (after touching), with -mtime 8000 (1.5 years newer datestamp) no files showed up...
Anyway, when the above two checks list at least one file, I run the corresponding commands below:

find /mnt/user -type f -mtime 8500 -ls -exec touch {} -t 2001010123 \;
find /mnt/user -type f -newermt today -ls -exec touch {} -t 2001010123 \;

I then run the "check only" versions again to verify that the files where indeed touched (so, not listed) and it worked. Also checking from my Windows machine indeed touched files showed as modified in the specific date/tame I use as placeholder (easy to find them later as I don't think I indeed modified any files at 01:23 of January 1st 2020).

 

I actually did the above on a per disk basis (so not /mnt/user) but now I trust it enough to use it on the full array (except if I know where the problem lies exactly) and also not run the simple (no touch) version in the future.

 

NOTE that now I am looking into merging the two find (for future and distant past timestamps) into a single one as I believe there are logic operands in find command. Any help appreciated.

 

EDIT: Found error. -mtime 8500 checkes for exactly 8500 days back. I need to put +8500.

 

Edited by NLS
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.