Linux Commands

How to use rsync with –ignore-existing?

Rsync or remote synchronization is a Linux and Unix-based utility that syncs files and directories efficiently between two devices or hosts. In this synchronization process, one is the local host or the source from which we will sync the files, and the other is the remote host, where all the synchronization will occur. Rsync can sync or copy data in a couple of different ways:

  • It uses ssh or rsh for syncing files to or from a remote shell.
  • TCP also helps rsync to sync files through the rsync daemon.

Rsync is well-known for its delta algorithm deployment, which allows rsync only to copy the modifications made in the source files on the local host and the current files on the remote host.

Rsync with –ignore-existing:

–ignore-existing option in rysnc command forces rsync to ignore the files update already existing on the destination. This operation does not ignore the existing directories because, in that case, nothing would get done. Since this is a transfer rule rather than exclude, it does not affect the data that goes through the file lists and deletion. This option will only restrict the file transfer requested by the receiver.

When you use the “–link-dest” option combined with the rsync command, it will create a new directory for backing up data. What if suddenly the backup got interrupted, and you want to resume it back? What will you do in such a situation? rsync can effectively use the “–ignore-existing” operation to resolve this issue. Usage of “–ignore-existing” will make sure that the files already been handled do not get change. It means that the “–ignore-existing” will only look at the already existing files present in the destination hierarchy.

Now let’s head towards the practical implementation of this form of rsync command.

Here is the syntax of the rsync command with the “–ignore-existing” option:

$ sudo rsync --ignore-existing -raz --progress Source username@remote_host:Destination

In the below-given example, we are syncing the file to the remote system. Therefore, “–ignore-existing” will restrict rsync to only sync the files from the local system that are not already copied to the destination.

$ sudo rsync --ignore-existing -raz --progress  /var linuxhint@10.0.2.15:/tmp/

Add your user name and host IP in the above command, and check out the output.

The output is also showing the progress while syncing files from the local to a remote system. Remember! This command execution will ignore the existing files present at the receiver end.

Conclusion:

Linux users usually back up their data on remote systems. One of the most incredible benefits that anybody can get from this remote data backup is reliability. In Linux, many command-line tools are used to create backups, and the rsync command is the best one. rsync –ignore-existing command enables a user to resume an interrupted backup and ignore the destination’s existing files.

About the author

Talha Saif Malik

Talha is a contributor at Linux Hint with a vision to bring value and do useful things for the world. He loves to read, write and speak about Linux, Data, Computers and Technology.