Srini V
Srini V

Reputation: 11355

Why atime is not preserved in tar?

According to the documentation, tar is capable of preserving the access time, but when I tried the same, it failed to do so. Can someone please explain this?

$$$:~/user1/testtar/source> tar --version
tar (GNU tar) 1.15.1

Create two files with older timestamp

$$$:~/user1/testtar/source> touch -t "201501010101" a.txt
$$$:~/user1/testtar/source> touch -t "201501010101" b.txt

$$$:~/user1/testtar/source> ls -ltu
-rw-r--r-- 1 usr usr 0 2015-01-01 01:01 a.txt
-rw-r--r-- 1 usr usr 0 2015-01-01 01:01 b.txt

Move it to another folder

$$$:~/user1/testtar/source> tar --atime-preserve -cvpf archive.tar *
$$$:~/user1/testtar/source> mv archive.tar ../target/
$$$:~/user1/testtar/source> cd ../target/

Extract the tar

$$$:~/user1/testtar/target> tar --atime-preserve -xvpf archive.tar
a.txt
b.txt

$$$:~/user1/testtar/target> ls -lt
total 12
-rw-r--r-- 1 usr usr 10240 2016-07-07 15:55 archive.tar
-rw-r--r-- 1 usr usr     0 2015-01-01 01:01 a.txt
-rw-r--r-- 1 usr usr     0 2015-01-01 01:01 b.txt

Result

$$$:~/user1/testtar/target> ls -ltu
-rw-r--r-- 1 usr usr 10240 2016-07-07 15:56 archive.tar
-rw-r--r-- 1 usr usr     0 2016-07-07 15:56 a.txt
-rw-r--r-- 1 usr usr     0 2016-07-07 15:56 b.txt

Upvotes: 2

Views: 4081

Answers (3)

user2430607
user2430607

Reputation: 35

I think this topic is obsolete, with exactly the same steps, I got the following result.

tar --version
tar (GNU tar) 1.28

mkdir -p source target
touch -t "201501010101" source/a.txt
touch -t "201501010101" source/b.txt
tar -cvpf archive.tar -C source  .
tar -xvpf archive.tar -C target/

ls -l target/
total 16
-rw-rw-r-- 1 usr usr 0 Jan  1  2015 a.txt
-rw-rw-r-- 1 usr usr 0 Jan  1  2015 b.txt

Upvotes: 0

Jean-Baptiste Yunès
Jean-Baptiste Yunès

Reputation: 36391

You can observe in the tar format specification that there is no atime field. This is just to preserve access time of the original file being tar-ed.

Upvotes: 3

John Bollinger
John Bollinger

Reputation: 180038

The referenced man page is confusing. Where it says of --atime-preserve

preserve access times on dumped files [...]

(emphasis added), the current docs say

Preserve the access times of files that are read."

(emphsis added). The word "dumped" refers to putting a file into a tar archive, not to extracting a file to the file system. Thus, the --atime-preserve option is for archiving files without causing the originals' atimes to reflect the access. This is useful in support of making incremental backups (dumps).

Under no circumstances does tar fail to set the atimes of files that it extracts, contrary to your expectation. It certainly cannot give them the same atimes as the originals, for the tar file format does not even record atimes.

Upvotes: 7

Related Questions