Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Ignore existing files or update only newer files with rsync

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

Rajesh Kumar
Follow me
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x