http://www.evbackup.com/support-commonly-used-rsync-arguments/
http://www.evbackup.com/support-commonly-used-rsync-arguments/
https://unix.stackexchange.com/questions/67539/how-to-rsync-only-new-files
https://unix.stackexchange.com/questions/146282/rsync-to-copy-files-which-has-changed
https://stackoverflow.com/questions/13778889/rsync-difference-between-size-only-and-ignore-times
There are several ways rsync compares files -- the authoritative source is the rsync algorithm description: https://www.andrew.cmu.edu/course/15-749/READINGS/required/cas/tridgell96.pdf. The wikipedia article on rsync is also very good.
For local files, rsync compares metadata and if it looks like it doesn't need to copy the file because size and timestamp match between source and destination it doesn't look further. If they don't match, it cp's the file. However, what if the metadata do match but files aren't actually the same? Then rsync probably didn't do what you intended.
Files that are the same size may still have changed. One simple example is a text file where you correct a typo -- like changing "teh" to "the". The file size is the same, but the corrected file will have a newer timestamp. --size-only says "don't look at the time; if size matches assume files match", which would be the wrong choice in this case.
On the other hand, suppose you accidentally did a big "cp -r A B" yesterday, but you forgot to preserve the time stamps, and now you want to do the operation in reverse "rsync B A". All those files you cp'ed have yesterday's time stamp, even though they weren't really modified yesterday, and rsync will by default end up copying all those files, and updating the timestamp to yesterday too. --size-only may be your friend in this case (modulo the example above).
--ignore-times says to compare the files regardless of whether the files have the same modify time. Consider the typo example above, but then not only did you correct the typo but you used "touch" to make the corrected file have the same modify time as the original file -- let's just say you're sneaky that way. Well --ignore-times will do a diff of the files even though the size and time match.
Copy with preserve timestamp
cp -p does the trick. For Linux:
-p same as --preserve=mode,ownership,timestamps
For FreeBSD:
-p Cause cp to preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, ACL, user ID, and group ID, as allowed by permissions.
And for OS X:
-p Cause cp to preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, user ID, and group ID, as allowed by permissions. Access Control Lists (ACLs) and Extended Attributes (EAs), including resource forks, will also be preserved.
http://www.evbackup.com/support-commonly-used-rsync-arguments/
https://unix.stackexchange.com/questions/67539/how-to-rsync-only-new-files
https://unix.stackexchange.com/questions/146282/rsync-to-copy-files-which-has-changed
https://stackoverflow.com/questions/13778889/rsync-difference-between-size-only-and-ignore-times
There are several ways rsync compares files -- the authoritative source is the rsync algorithm description: https://www.andrew.cmu.edu/course/15-749/READINGS/required/cas/tridgell96.pdf. The wikipedia article on rsync is also very good.
For local files, rsync compares metadata and if it looks like it doesn't need to copy the file because size and timestamp match between source and destination it doesn't look further. If they don't match, it cp's the file. However, what if the metadata do match but files aren't actually the same? Then rsync probably didn't do what you intended.
Files that are the same size may still have changed. One simple example is a text file where you correct a typo -- like changing "teh" to "the". The file size is the same, but the corrected file will have a newer timestamp. --size-only says "don't look at the time; if size matches assume files match", which would be the wrong choice in this case.
On the other hand, suppose you accidentally did a big "cp -r A B" yesterday, but you forgot to preserve the time stamps, and now you want to do the operation in reverse "rsync B A". All those files you cp'ed have yesterday's time stamp, even though they weren't really modified yesterday, and rsync will by default end up copying all those files, and updating the timestamp to yesterday too. --size-only may be your friend in this case (modulo the example above).
--ignore-times says to compare the files regardless of whether the files have the same modify time. Consider the typo example above, but then not only did you correct the typo but you used "touch" to make the corrected file have the same modify time as the original file -- let's just say you're sneaky that way. Well --ignore-times will do a diff of the files even though the size and time match.
Copy with preserve timestamp
cp -p does the trick. For Linux:
-p same as --preserve=mode,ownership,timestamps
For FreeBSD:
-p Cause cp to preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, ACL, user ID, and group ID, as allowed by permissions.
And for OS X:
-p Cause cp to preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, user ID, and group ID, as allowed by permissions. Access Control Lists (ACLs) and Extended Attributes (EAs), including resource forks, will also be preserved.
Comments
Post a Comment