| |
| | |

Apple Phoon Forum

 Forgot password?
View: 656|Reply: 2

recovering directory timestamps when extracting tar archives

[Copy link]

Post time: 2014-02-27 21:36:36 |Show all posts
I created a backup using tar, and now I try to extract it, but the problem is that some of the directories do not get the correct timestamps.
As an example, consider the following directory structure:
This can be created (in Terminal) by:
mkdir dir0
cd dir0
touch file1
mkdir dir1
cd dir1
touch file2
mkdir dir2
cd dir2
touch file3
cd ../../..
and then you just navigate to dir0/dir1 in Finder (but not to dir2), which creates the .DS_Store files in both dir0 and dir1. Finally, we delete the .DS_Store in dir0:
rm dir0/.DS_Store
Now i created the archive (on Mountain Lion, bsdtar 2.8.3, but I have the same issue when I try gnutar 1.17):
tar -cvf bkup.tar dir0/
Then I extract the archive in a different location, say:
mkdir different_location
cd different_location
tar -xvf ../bkup.tar
The problem: the (modification) timestamp of dir1 is set to the time I extracted the archive, rather then to the creation time of the original dir1 (but dir0 and dir2 have the correct timestamps of the creation time).
How can I ensure that all extracted directories have the modification timestamps set to the same as the original directories?
The problem seems to be related to the .DS_Store file that is in dir1/ but is not in dir0/ and dir2/. I do want to save the .DS_Store files in my original archive. Perhaps this also has something to do with the fact that .DS_Store files have extended attributes (unlike the other files in these directories);
that is, perhaps tar adds the extended attributes after it sets the timestamps of the extracted files, and that step resets the modification times?
So I tried to disable the extended attributes with:
but that did not work.
any idea how to recover the original timestamps?

Use magic Report

Post time: 2014-02-28 00:24:13 |Show all posts
There's a write-up on tar and how it tries to maintain the directory modification times here.
Do you need to use tar, or could zip and unzip (for instance) be used here? And depending on what you're up to with the backups, using a scratch disk and time machine works, as can using rsync; if it's not working for you here, might there be an alternative to tar?

Use magic Report

Post time: 2014-02-27 23:12:38 |Show all posts
See if the version of GNU tar that you have has the option --delay-directory-restore and if it does try it.
(it's not in the OS X standard tar)
setting that option causes tar to wait until the end of extraction to set the directory times and permissions. It's a long shot but worth a try if you have the option.

Use magic Report

You have to log in before you can reply Login | Register

Archive| Apple Phoon

2021-04-18 07:29 GMT-8 , Processed in 0.070526 sec., 27 queries .

Powered by Discuz! 7.2

Release 20121101, © 2001-2021

To Top