0

I'm creating a tarball in a directory which has multiple sub-directories that I need to archive on a monthly basis. The issue is when I go to extract the files/folders for a particular month the top level sub-folders do not retain the modified date.

I am using the following for the tarball

find -type f -newermt 2021-12-01 ! -newermt 2021-12-31 | xargs tar -cvzf 2021-12.tar.gz

It still shows the time of the extract for each folder which I archived instead of when it was modified. Can someone help me out?

I also tried this as recommended on another user post

find -type f -newermt 2021-12-01 ! -newermt 2021-12-31 | xargs tar --atime-preserve -cvzf 2021-12.tar.gz

Thanks

John
  • 35

1 Answers1

1

You didn't archive the actual folders, only the files within. You can see this for yourself by running tar -tvvf 2021-12.tar.gz – it's not that the folder entries are missing their mtimes, it's that there aren't any folder entries at all.

(The folders weren't part of tar's input because find -type f specifically excludes them.)

Your output needs to include all parent directory paths, preferably after the corresponding files (although GNU tar has --delay-directory-restore to deal with misordered entries). Something like this might work:

$ find -name '*.c' |
  perl -ne 'print; print while s!/[^/]+$!\n!g' |
  sort -r |
  uniq |
  xargs -d '\n' tar -cvzf out.tgz --no-recursion

My other suggestion is to use Git, Borg, or Restic for incremental archives.

grawity
  • 501,077