$ rsync -avz --delete-after /home/pong/rsyncsource /home/pong/rsyncdest
a : Recursively transfer all files from the directory hone/pong/rsyncsource on the machine foo into the /home/pong/rsyncdest/rsyncsource directory
The files are transferred in “archive” mode, which ensures that symbolic links, devices, attributes, permissions, ownerships etc are preserved in the transfer.
v : verbose
z : compression will be used to reduce the size of data portions of the transfer.
–delete-after : delete the files that got deleted on rsyncsource on rsyncdest after transfer ( ref : http://askubuntu.com/questions/476041/how-do-i-make-rsync-delete-files-that-have-been-deleted-from-the-source-folder )
–rsh=”ssh …” : choose an alternative remote shell program to use for communication between the local and remote copies of rsync. Typically, rsync is configured to use ssh by default. However, if you would like to change an ssh encryption or change port ( ssh -p 2234 ), or change an identity file ( ssh -i /path/to/id_rsa ).
Rsync with last modified date
- Last modified date is one of the factor that rsync use to decide to copy, if we use cp before rsync and we would like to preserve the last modified date, use the –preserve flag.
- However, in my case, while I copied using ant script, I moved the file to the different folder. Although, the preservelastmodified attribute is used, but the last modified date of the folder will be the ant script running date ( ref : http://stackoverflow.com/questions/35583007/ant-script-to-preserve-lastmodified-date-of-the-directory-that-is-defined-in-map ). NOTE : the last modified date also change when the file inside is changed.
Therefore, I use -c ( checksum ) instead.
NOTE : -c ( checksum ) won’t works with -a ( that alias contains -t that is checking last modified date.