I am using rsync-3.2.3 on Fedora 33 (GNOME).
But how can I keep the access time (atime
) for my files and folders?
I can only keep the modified time (mtime
) with this command:
rsync -t
I am using rsync-3.2.3 on Fedora 33 (GNOME).
But how can I keep the access time (atime
) for my files and folders?
I can only keep the modified time (mtime
) with this command:
rsync -t
You can ask to preserve atime
(access time) on the source with the --noatime
flag, but on filesystems mounted with relatime
(the modern default) or noatime
this already isn't strictly necessary
rsync -av --noatime src/ dstHost:dst/
I know of no option to preserve atime
on the destination as a copy of the source natively within rsync
. If you have access to the target system you might be able to iterate across the copied tree. Something like this could work on a GNU/Linux type system
( cd src/ && find -type f -print0 ) |
ssh dstHost 'cd dst && while IFS= read -r -d "" f; do touch -a -d "@$(stat -c %Y "$f")" "$f"; done'
Or if you are processing a copy between two local filesystems
( cd src/ && find -type f -print0 ) |
( cd dst && while IFS= read -r -d "" f; do touch -a -d "@$(stat -c %Y "$f")" "$f"; done )
Basically these two snippets do the same thing: for each file in the source, find the corresponding file in the destination and update its atime
to match its mtime
.
ctime
you'll update mtime
. And when you change mtime
you reset ctime
. You cannot control both. I've updated my answer to show a possible method for updating atime
from mtime
. On some versions of stat
you might be able to use this for managing btime
too
– Chris Davies
Jan 21 '21 at 20:47
stat
command, it doesn't show anything at change time, just an empty character (-
).
– Laradu9sna7al
Jan 22 '21 at 01:29
Since rsync version 3.2.0, there are two flags that affect atimes:
--atimes, -U
preserve access (use) times--open-noatime
avoid changing the atime on opened filesThe full description of these is:
--atimes, -U
This tells rsync to set the access (use) times of the destina‐
tion files to the same value as the source files.
If repeated, it also sets the --open-noatime option, which can
help you to make the sending and receiving systems have the same
access times on the transferred files without needing to run
rsync an extra time after a file is transferred.
Note that some older rsync versions (prior to 3.2.0) may have
been built with a pre-release --atimes patch that does not imply
--open-noatime when this option is repeated.
--open-noatime
This tells rsync to open files with the O_NOATIME flag (on sys‐
tems that support it) to avoid changing the access time of the
files that are being transferred. If your OS does not support
the O_NOATIME flag then rsync will silently ignore this option.
Note also that some filesystems are mounted to avoid updating
the atime on read access even without the O_NOATIME flag being
set.
So my reading of these (which testing has borne out) is that the following will both keep rsync from updating the atime on src
, and will copy the atime of src
to dest
:
rsync -UU <src> <dest>