In order to debug my repeatedly crashing Ubuntu 16.04 I want to backup /var/log from my HDD to an external USB medium. I am running an live OS (Ubuntu 16.04) and using the –archive option:
$ sudo rsync --archive /media/ubuntu/2f1ea741-cc93-4b0e-ad74-1e21d56d27a9/var/log/* /media/ubuntu/transcend/DebuggingSystemCrash@box3/var_log_2016-07-04-0939
Expected behavior
Archive mode equals -rlptgoD
, so modification times should be preserved (which I want), since
-t, --times preserve modification times
Observed behavior
The time stamps of the files (atime and mtime) are not being preserved, see screenshot. mtime of folders is preserved.
Since both source and target are mounted this question is probably related to how to tell rsync to preserve time stamp on files when source tree has a mounted point.
I have also read:
- rsync command to backup home tree to another disk
- Preserve date modified on directories / folders with rsync
- How to make rsync preserve timestamps of unchanged files
Am I missing something?
UPDATE
Not running rsync as sudo produces the expected behavior regarding mtime, but will skip some files.
Best Answer
Difference with
sudo
could be due to the extract below from Documentation/filesystems/vfat.txt. (Requires knowledge that your target filesystem is of typevfat
& who owns the directory^Wfilesystem - determined by mount option in the case ofvfat
).I went ahead and posted this anyway because it shows how important the filesystem types are. The general conclusion was that using FAT on Linux is pain (and there has been a special issue with rsync on FAT as well).
I'm certain at least one of the issues listed there has been solved with different defaults (possibly in
udisks
as used by the GUI, as opposed to manualmount
commands). In any case I suggest you'd be wasting your time if what you're trying to do is copy parts of your Linux OS into FAT, and you demand specific results in file metadata (timestamps), or even file names. In that case you should use a native Linux filesystem, ideally the same type as the source.Or, instead of copying individual files, create an archive using a native Linux tool such as
tar
. Think Zip file - but specifically designed for backing upLinux*nix files - their names, and the most common metadata. For example,tar -c -f out.tar input-directory/
(omits compression).Reference doc for setting FAT timestamps on Linux
Community confirmation and other potential issues to avoid
So the blog post I found confirms "only the owner of a FAT32 mount can set file time stamps on it". I'd call this a design bug (root should be able to do it as well), which the reference documentation almost spells out, but I'm too lazy to submit a patch for it.
The blog also provides an explanation for a file/directory difference. Unfortunately it seems to be doubly opposite what you describe. I think the file/directory difference described below should have prevented your normal user from setting timestamps correctly on directories - whereas what you've showed is that if you're root, you can set the correct timestamps on directories but not files.
It sounds to me like the
--modify-window=1
is a workaround for an rsync-specific issue. So usingcp
to copy files instead might give you another data point.