rajeshkumar created the topic: Ignore existing files or update only newer files with rsync
Ignore existing files or update only newer files with rsynca
Copying from local to remote
Note that all the examples shown in the post are for copying files from the local computer to a remote server/computer.
Default behavoir
The following command will recursively copy all files from the local filesystem from /var/www to the remote system at 10.1.1.1. Note the following:
Any files that do not exist on the remote system are copied over
Any that have been updated will be copied over, although note that rsync is extremely efficient in that only the changed parts of files are copied and if the file is exactly the same if it is not copied over at all
Any that have been deleted on the local system are deleted on the remote
1 rsync -raz โprogress /var/www 10.1.1.1:/var
Ignore existing files
Use the โignore-existing flag to prevent files from being copied over that already exist on the remote server. By adding this, we eliminate behaviors 2 and 3 in the list above and all that is done is this:
Any files that do not exist on the remote system are copied over
1 rsync โignore-existing -raz โprogress /var/www 10.1.1.1:/var
Update the remote only if a newer version is on the local filesystem
In the case I was talking about, we didnโt want to overwrite any files at the other end. However you may want to copy files over the have been updated more recently on the local filesystem which is done with the โupdate flag. The behavior is now like this:
Any files that do not exist on the remote system are copied over
Any files that exist on both local and remote that have a newer timestamp on the local server are copied over. (Conversely, any files that have an older timestamp are not copied over).
1 rsync โupdate -raz โprogress /var/www 10.1.1.1:/var
Use โdry-run to see what will be copied
It can be a good idea to test what will be transferred before actually doing it to make sure you arenโt going to copy files that you donโt want to. The โdry-run flag helps you do this:
1 rsync โdry-run โupdate -raz โprogress /var/www 10.1.1.1:/var
Combined with the โprogress flag I have included in all the examples, โdry-run will output all the directories it looks at and then all the files that would be copied.
Regards,
Rajesh Kumar
Twitt me @ twitter.com/RajeshKumarIn
Iโm a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND