1

Here is my problem. Every night I move data to a remote location, the data retains its modified date correctly, but the folders do not consistently. What I would like to do is to check the folders modified dates and if the local date is older than the remote date, I want to run touch on that folder to make it newer.

My folder structure should look something like this:

/srv/remote
├── dirA
│   ├── dirA1
│       ├── file1
│       └── file2
└── dirB
    └── file1

/srv/local
├── dirA
│   ├── dirA1
│       ├── file1
│       └── file2
│       └── file3
│   ├── dirA2
│       ├── file1
└── dirB
    └── file1

I did find this, touch all folders in a directory , which helps with how to touch each folder, but I can't figure out a find command that will compare the modified time of the mirrored folder (if one exists) to list the folders that need to be touched.

washdoubt
  • 11
  • 2
  • Understand that the modified timestamp for a directory is the last time anything inside the directory changed. Thus, you will have to process all the files in the directory _**before**_ you modify the timestamp of the directory. Otherwise, if you modify the files in the directory after setting the timestamp, the file system will just replace your timestamp with the timestamp when you modified the contents. (In computing terms, you need to do a depth-first traversal of the directory tree.) – C. M. May 12 '21 at 01:21
  • What you might do is reconsider your approach. For example, the `tar` (tape archive) command has options to store/preserve things like user/group, access permissions and timestamps. – C. M. May 12 '21 at 01:28
  • The most important piece of your question is **how** you move the data. Can you share that? The solution might be a single flag away (if your problem can be solved with @C.M.'s comment). – Eduardo Trápani May 12 '21 at 02:05
  • I move the data with rclone, they do not preserver folder modified times well, it is known. I will touch the folder after I finish uploading. I have it all figured out except how to find the list of files that differ in modified time. My last resort is a horrible for loop and compare one folder at a time, but I hope to find a better solution. – washdoubt May 12 '21 at 03:01
  • @washdoubt: This might be easier in Python/Perl/etc, and no promises it is the most efficient way... Make a list file of all the files from the source location ( it is easier to just keep the full path name instead of trying to figure out the common prefix) and the mtime. Do the same for the target location. Then simply compare the lists. If a file appears on the source list, but not the target, it needs to be copied over. If the mtimes differ, you will need to decide which one takes priority. After you sync, you can use the list(s) to `touch` any files that need mtime updates. (depth-first!) – C. M. May 12 '21 at 19:42
  • Now, some notes... You basically want to keep a directory tree synchronized between two locations, correct? Have you searched for a tool that does exactly that and suits your needs? It is such a common task that there are many tools written to do that. Full sync, mirroring, cloning, backup, etc. Even ones to do partial, differential, de-duplicating, "point-in-time", and other methods. – C. M. May 12 '21 at 19:47

0 Answers0