Rsync and backup and changing timezone

backuprsyncstattimestamps

I back up my pictures from my camera using rsync, using:

 rsync -vzrtl --progress --stats --timeout=0 host destination

Now I was in a different timezone when I did my first backup then I moved to a different timezone and I changed it on my laptop (I use ubuntu 10.04.4). Today I was backing up my pictures and I found that the timestamp were different (I mean the timestamps you can see with 'ls -lt'), so rsync would copy the whole directory (I always run rsync with the option -n first to know the list of files it would transfer). Now this is just stupid, because the files are actually the same. So I changed back to the previous timezone, in fact the file timestamps changed to the same on my camera – this I find weird somehow.

I run rsync again and the files are still different :@
Now, I don't want to copy the files again, this would be stupid, can you suggest a clean solution? How can I prevent this in the future? why the files are still different, if I changed to the previous timezone?


I found that the access and change time are different for the files, using stat.
For example:

on host

   File: `DSC00003.JPG'
   Size: 3068392    Blocks: 6016       IO Block: 32768  regular file
 Device: 821h/2081d Inode: 2109        Links: 1
 Access: (0755/-rwxr-xr-x)  Uid: ( 1000/simona)   Gid: ( 1000/simona)
 Access: 2013-03-26 00:00:00.000000000 +0000 
 Modify: 2007-12-25 22:48:20.000000000 +0000
 Change: 2007-12-25 22:48:20.000000000 +0000

and on the destination

   File: `DSC00003.JPG'
   Size: 3068392    Blocks: 6008       IO Block: 4096   regular file
 Device: 802h/2050d Inode: 245762      Links: 1
 Access: (0755/-rwxr-xr-x)  Uid: ( 1000/simona)   Gid: ( 1000/simona)
 Access: 2013-03-26 10:24:49.000000000 +0000
 Modify: 2007-12-25 22:48:20.000000000 +0000
 Change: 2013-02-09 00:11:09.000000000 +0000

Is there a way to prevent rsync to overwrite pictures that have been modified more recently on the destination?

Best Answer

To answer the question i make an assumption:

You are using rsync locally, transferring from a mounted SD-card to backup space

MMC are formatted with FAT-filesystems, so its always useful to set --modify-window=1 because FAT-filesystems store timestamps in a 2 second resolution.

man rsync gives the option --size-only which ignores the last-modified flag of the files. So only files with modified size, e.g. edited ones will be synced.

Another option would be to set the option --modify-window to the time difference between the two timzeones in seconds. e.g. for 2 hours use modify-window=3660 if there is a 1 hour difference

maybe the is a problem with your UTC setting.

You can check if your hardwareclock is set correct by typing date --utc Xour softwareclock is given by date.

The value should have the same difference as your local timezone to Greenwich Mean Time.

Your hardwareclock should always be set to UTC so all timestamps are set correct even when you change timezones(softwareclock).

If the UTC time is not correct, check if it ist set correct in your BIOS. If not, correct it.

If it is set you can check /etc/default/rcS. The should be the following line (Ubuntu 12.04)

#assume that the BIOS clock is set to UTC time (recommended)
UTC=yes
Related Question