{"id":2682,"date":"2017-12-09T10:24:59","date_gmt":"2017-12-09T10:24:59","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=2682"},"modified":"2020-01-09T07:20:30","modified_gmt":"2020-01-09T07:20:30","slug":"ignore-existing-files-or-update-only-newer-files-with-rsync","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/ignore-existing-files-or-update-only-newer-files-with-rsync\/","title":{"rendered":"Ignore existing files or update only newer files with rsync"},"content":{"rendered":"<p><strong>rajeshkumar created the topic: Ignore existing files or update only newer files with rsync<\/strong><\/p>\n<p>Ignore existing files or update only newer files with rsynca<\/p>\n<p>Copying from local to remote<\/p>\n<p>Note that all the examples shown in the post are for copying files from the local computer to a remote server\/computer.<\/p>\n<p>Default behavoir<\/p>\n<p>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:<\/p>\n<p>Any files that do not exist on the remote system are copied over<br \/>\nAny 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<br \/>\nAny that have been deleted on the local system are deleted on the remote<br \/>\n1\trsync -raz &#8211;progress \/var\/www 10.1.1.1:\/var<\/p>\n<p>Ignore existing files<\/p>\n<p>Use the &#8211;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:<\/p>\n<p>Any files that do not exist on the remote system are copied over<br \/>\n1\trsync &#8211;ignore-existing -raz &#8211;progress \/var\/www 10.1.1.1:\/var<\/p>\n<p>Update the remote only if a newer version is on the local filesystem<\/p>\n<p>In the case I was talking about, we didn&#8217;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 &#8211;update flag. The behavior is now like this:<\/p>\n<p>Any files that do not exist on the remote system are copied over<br \/>\nAny 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).<br \/>\n1\trsync &#8211;update -raz &#8211;progress \/var\/www 10.1.1.1:\/var<\/p>\n<p>Use &#8211;dry-run to see what will be copied<\/p>\n<p>It can be a good idea to test what will be transferred before actually doing it to make sure you aren&#8217;t going to copy files that you don&#8217;t want to. The &#8211;dry-run flag helps you do this:<br \/>\n1\trsync &#8211;dry-run &#8211;update -raz &#8211;progress \/var\/www 10.1.1.1:\/var<\/p>\n<p>Combined with the &#8211;progress flag I have included in all the examples, &#8211;dry-run will output all the directories it looks at and then all the files that would be copied.<\/p>\n<p>Regards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @ <a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\">twitter.com\/RajeshKumarIn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[4957],"tags":[537],"class_list":["post-2682","post","type-post","status-publish","format-standard","hentry","category-linux","tag-ignore"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2682"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2682\/revisions"}],"predecessor-version":[{"id":2683,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2682\/revisions\/2683"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}