rsync preserving atime of source

Making rsync leave the source file's atime alone

rsync (see http://rsync.samba.org/) is a sophisticated file tree replication tool with great perfomance. 

Some people want to create exact copies of an existing file system, with all file attributes and timestamps preserved. The baseline rsync distribution replicates modification times, but not access times. There is a patch available with the patch collection distributed with rsync that enriches its functionality adding the -U command line switch to make rsync replicate atimes as well.

Still, the source file's access time is changed when rsync reads the file for replication, when the source file has been changed. This may be considered harmful, as rsync should preserve file properties.

There is a solution: Set the replication file system to read-only mode, or better, use a read-only snapshot.

Example:

There are two machines, "here" and "there", with the directory /rsynctest being replicated from here to there.

-bash-3.00#  ls -lu /rsynctest; ssh there ls -lu /rsynctest

total 36
-rw------T   1 root     root        1024 Dec  5 10:18 file-1
-rw------T   1 root     root        1024 Dec  5 10:18 file-2
-rw------T   1 root     root          12 Dec  5 10:26 file-3
-rw------T   1 root     root          12 Dec  5 10:16 file-4
-rw------T   1 root     root        1024 Dec  5 10:16 file-5
-rw------T   1 root     root        1024 Dec  5 10:16 file-6
-rw------T   1 root     root        1024 Dec  5 10:16 file-7
-rw------T   1 root     root        1024 Dec  5 10:16 file-8
-rw------T   1 root     root        1024 Dec  5 10:16 file-9
total 34
-rw------T   1 root     root        1024 Dec  5 10:16 file-1
-rw------T   1 root     root        1024 Dec  5 10:18 file-2
-rw------T   1 root     root          12 Dec  5 10:26 file-3
-rw------T   1 root     root          12 Dec  5 10:16 file-4
-rw------T   1 root     root        1024 Dec  5 10:16 file-5
-rw------T   1 root     root        1024 Dec  5 10:16 file-6
-rw------T   1 root     root        1024 Dec  5 10:16 file-7

ls -u lists access times instead of modification times.
Both file sets are identical. Now lets change a file:

-bash-3.00# echo "new content" >/rsynctest/file-5
total 36
-rw------T   1 root     root        1024 Dec  5 10:26 file-1
-rw------T   1 root     root        1024 Dec  5 10:26 file-2
-rw------T   1 root     root          12 Dec  5 10:26 file-3
-rw------T   1 root     root          12 Dec  5 10:16 file-4
-rw------T   1 root     root          12 Dec  5 10:16 file-5
-rw------T   1 root     root        1024 Dec  5 10:16 file-6
-rw------T   1 root     root        1024 Dec  5 10:16 file-7
-rw------T   1 root     root        1024 Dec  5 10:16 file-8
-rw------T   1 root     root        1024 Dec  5 10:16 file-9
total 34
-rw------T   1 root     root        1024 Dec  5 10:16 file-1
-rw------T   1 root     root          12 Dec  5 10:18 file-2
-rw------T   1 root     root          12 Dec  5 10:26 file-3
-rw------T   1 root     root        1024 Dec  5 10:16 file-4
-rw------T   1 root     root        1024 Dec  5 10:16 file-5
-rw------T   1 root     root        1024 Dec  5 10:16 file-6
-rw------T   1 root     root        1024 Dec  5 10:16 file-7
-rw------T   1 root     root        1024 Dec  5 10:16 file-8
-rw------T   1 root     root        1024 Dec  5 10:16 file-9

Note the access time did not change when updating the file. To keep rsync from changing atime when reading file-5 to send a copy to "there", lets snapshot the file system.

-bash-3.00# zfs snapshot rsynctest@atimesaver

do sync from "here" to "there":

-bash-3.00#  /usr/local/bin/rsync  -rsync-path /usr/local/bin/rsync --delete \\
--archive -U /rsynctest/.zfs/snapshot/atimesaver/ root@there:/rsynctest/

And voila, atime still intact:

-bash-3.00#  ls -lu /rsynctest; ssh there ls -lu /rsynctest
total 36
-rw------T   1 root     root        1024 Dec  5 10:16 file-1
-rw------T   1 root     root        1024 Dec  5 10:18 file-2
-rw------T   1 root     root          12 Dec  5 10:26 file-3
-rw------T   1 root     root          12 Dec  5 10:16 file-4
-rw------T   1 root     root          12 Dec  5 10:16 file-5
-rw------T   1 root     root        1024 Dec  5 10:16 file-6
-rw------T   1 root     root        1024 Dec  5 10:16 file-7
-rw------T   1 root     root        1024 Dec  5 10:16 file-8
-rw------T   1 root     root        1024 Dec  5 10:16 file-9
total 31
-rw------T   1 root     root        1024 Dec  5 10:16 file-1
-rw------T   1 root     root        1024 Dec  5 10:18 file-2
-rw------T   1 root     root          12 Dec  5 10:26 file-3
-rw------T   1 root     root          12 Dec  5 10:16 file-4
-rw------T   1 root     root          12 Dec  5 10:16 file-5
-rw------T   1 root     root        1024 Dec  5 10:16 file-6
-rw------T   1 root     root        1024 Dec  5 10:16 file-7
-rw------T   1 root     root        1024 Dec  5 10:16 file-8
-rw------T   1 root     root        1024 Dec  5 10:16 file-9

Now we can get rid of that snapshot:

-bash-3.00#  zfs destroy rsynctest@atimesaver

Note: ctime (time of last change to the inode entry) is still not replicated. Does anybody know about a fix? Then again, I can not even think of anybody/any program who needs ctimes...

Comments:

Courier-IMAP uses ctime in IMAP_EMPTYTRASH.

Posted by Tino Reinhardt on December 09, 2008 at 09:11 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Dirk Wriedt

Search

Categories
Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today
Bookmarks
Software for Solaris
Favourite blogs
Dirks Bookmarks

No bookmarks in folder