I recently needed to utilize rsync to copy and update the new files that did not already exist at the destination system or directory. Are you also willing to use rsync for only updating and transferring new files? Then follow the rest of the article to learn how to do it.
After the file synchronization through rsync, the process of updating newer files consists of the following steps:
- Ignoring existing files
- The dry run update process
- Update newer files
Now, we will show you two methods following the procedure mentioned above.
Method 1: Updating newer files locally with rsync
For synchronization files from source to the destination directory, check out the below-given command. In our case, “testdir1” is our source and “testdir2” is the destination folder.
The “-u” or the “–update” option forces rsync to skip that files in your destination directory that are still new, and the “-n” or the “–dry run” option is for testing the update process.
Now, remove the “-n” option and quickly update the rsync command execution.
You can see in the retrieved output that only the “testfile” is added to the destination directory this time because it was added to the source file after the file syncing process, which makes it a “new file” for the rsync command.
Method 2: Updating newer files from local to the remote system
–ignore-existing option in rysnc command forces rsync to ignore the files update already existing on the destination. 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.
Let’s suppose you made some file creation changes in your local system after syncing files, and you want only to update the newer files to the destination directory. For this, test a dry update run by utilizing the below-given command:
Now you can move towards the actual update of newer files.
The output declares that “TESFOLDER” is considered a newer file and is updated to the remote system’s directory.
In any system, updating only the newer files removes the data redundancy. rsync command provides this facility in a Linux-based system. This process consists of the following steps: file synchronization, ignoring existing files, test dry run, and, lastly, the actual execution of the update process. We have provided you two methods for updating the newer files in your destination directory in this post.