How do I make tar set the correct atime on the extracted version? The option --atime-preserve works just on the original, not on the extracted file.
The extracted files always have current time as atime, which is bad.
use the -p option when you extract it.
That was quick. Thanks!
This does not seem to work though. See below an example where 2 files (with different atimes) are archived and extracted somewhere else. The last line of output shows that the atime was not preserved.
$ ls -lt origin/b*
-rw-r--r-- 1 dsilt2 dsilt2 4 2008-12-15 03:52 origin/bla2
-rw-r--r-- 1 dsilt2 dsilt2 4 2007-07-07 22:22 origin/bla1
$ ls -ltu origin/b*
-rw-r--r-- 1 dsilt2 dsilt2 4 2008-12-15 03:52 origin/bla2
-rw-r--r-- 1 dsilt2 dsilt2 4 2007-07-07 22:22 origin/bla1
$ cd origin/
$ tar --atime-preserve -cvpf archive.tar *
bla1
bla2
$ mv archive.tar ../destination/
$ cd ../destination/
$ tar xvpf archive.tar
bla1
bla2
$ ls -lt b*
-rw-r--r-- 1 dsilt2 dsilt2 4 2008-12-15 03:52 bla2
-rw-r--r-- 1 dsilt2 dsilt2 4 2007-07-07 22:22 bla1
$ ls -ltu b*
-rw-r--r-- 1 dsilt2 dsilt2 4 2008-12-15 04:01 bla1
-rw-r--r-- 1 dsilt2 dsilt2 4 2008-12-15 04:01 bla2
can you add --atime-preserve when you do the extract?
Sure. Same result. Files are as in previous shell log.
$ rm destination/bla*
$ cd destination/
$ tar --atime-preserve -xvpf archive.tar
bla1
bla2
$ ls -lt b*
-rw-r--r-- 1 dsilt2 dsilt2 4 2008-12-15 03:52 bla2
-rw-r--r-- 1 dsilt2 dsilt2 4 2007-07-07 22:22 bla1
$ ls -ltu b*
-rw-r--r-- 1 dsilt2 dsilt2 4 2008-12-15 04:22 bla1
-rw-r--r-- 1 dsilt2 dsilt2 4 2008-12-15 04:22 bla2
I should add that I don't necessarily have to work with tar, *any* tool that can do it is fine by me, say cpio, scp, and so on. It's just that tar, according to its documentation, at least *seems* able to preserve time and atime (and permissions of course). If someone knows of any other tool that can move files between computers and preserves those 3 things, that's fine by me too.
Hi.
My reading of this:
`--atime-preserve'
Tells `tar' to preserve the access time field in a file's inode
when reading it.
-- excerpt from info tar
leads me to believe that this on the source side, not on the target side. In other words, tar obtains the inode times, reads the file into the accumulation of the output file, then resets the inode times to the original.
Some filesystems are set not to even record the access times, since it is often of limited value and causes disk activity.
If my supposition is correct, then one could use touch to reset the access times on the target -- tedious, but doable.
Perhaps someone will stop by with a definitive answer ... cheers, drl
look into 'pax' - 'man pax':
.....................
-p string
Specifies one or more file characteristic options
(privileges). The string option-argument must be a
string specifying file characteristics to be retained
or discarded on extraction. The string consists of the
specification characters a, e, m, o, and p. Multiple
characteristics can be concatenated within the same
string and multiple -p options can be specified. The
meaning of the specification characters are as fol-
lows:
a Does not preserve file access times.
e Preserves the user ID, group ID, file mode bits,
access time, and modification time.
m Does not preserve file modification times.
o Preserves the user ID and group ID.
.....................
Hi.
Indeed, on a brief test of pax, the access time was preserved on the restore ... cheers, drl
Yes drl you are correct. But if an archiving utility like tar includes the ability to carefully restore the original's atime (which requires extra work, i.e. modifying the inode after the file is read), it would be bizarre if the programmers didn't also include the ability to set the extracted copy's atime (which requires absolutely no extra work, because tar always sets the extracted copy's time correctly, and assuming it also sets the atime to something, it is no extra work to set it to the correct value).
Correct. And even if I tar files from such a filesystem (which hence always have an atime long in the past), the atime of the extracted copy is the current time. And also, even if I tar files and *extract* them onto a filesystem that does not record the atime (mount option noatime), the atime is set to the extraction time.
But how? Presumably they are stored in the tar archive, but where? And if I wanted a tool that reads stuff from a tar archive, the tool "tar" would be my choice
We are talking about 10000 to 100000 files here. Possibly there are scripts that store and later reset the atimes, but I don't know of any.
Awesome. I will definitely try pax. Thanks a lot to you and drl!