atime, tar and rsync

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Kevin Buettner
Date:  
Subject: atime, tar and rsync
--
--PART-BOUNDARY=.11030912011327.ZM12252.localdomain
Content-Type: text/plain; charset=us-ascii

On Sep 11, 3:08pm, Bill Warner wrote:

> While doing some looking around on some of our production servers I was
> noticing that all files are accessed pretty much every day. I know that
> many of the files are not used by anybody, Does tar or rsync (both used
> in parts of backups) moddify the atime? what else might modify the
> atime on a standard setup. perhaps updatedb? Is there any way to get
> system programs to not change the atime whenever they are just
> catologing or backing up files?


I've had some more thoughts on this matter...

GNU tar has an option called "--atime-preserve" which leaves the
access times alone.

For other programs, it's not difficult to write a script which
determines the atime values for each file in a particular directory
hierarchy, runs an arbitrary command, and then restores the atimes at
the end. I'm attaching a (lightly tested) script which does this
called atime-preserve.

If it could be made to work, I like the mount idea better (see
previous mail) since kernel level support (or some kind of intrusive
locking) is needed to deal with the race conditions that arise from
users accessing files while the no-atime-modification commands are
being run. Fortunately, the consequence of losing (or winning) these
races aren't that severe. The worst that could happen is that an
"old" (i.e, wrong) atime will have been preserved if a user accesses
a file in in between recording the atime values and restoring them.

Kevin

--PART-BOUNDARY=.11030912011327.ZM12252.localdomain
Content-Type: text/plain ; name="atime-preserve" ; charset=us-ascii
Content-Disposition: attachment ; filename="atime-preserve"
X-Zm-Content-Name: atime-preserve

#!/usr/bin/perl -w

use File::Find;

die "usage $0 dir command [args ...]\n" if (@ARGV < 2);

my $dir = shift @ARGV;
my @command = @ARGV;

my @files = ();

find(
    sub {
    my $name = $File::Find::name;
    push @files, ($File::Find::name, (stat)[8]);
    }, $dir );


system @command;

while (@files) {
    my $name = shift @files;
    my $atime = shift @files;
    my $mtime = (stat $name)[9];
    if (utime($atime, $mtime, $name) != 1) {
    warn ("utime for $name failed: $!\n");
    }
}


--PART-BOUNDARY=.11030912011327.ZM12252.localdomain--