How to use rsync dry run?

2

For Linux based system, rsync is a file synchronization tool. This tool is based on the “delta algorithm” that makes the remotes file syncing faster. It deploys this algorithm by transmitting only the differences or modifications in the files across the network. For syncing files, rsync does not require the set of files that exist at one of the link ends. Therefore, it is considered a lightweight program. After the complete transfer of initial files, it only syncs the changed file bits. It also provides support for offsite backups in which it syncs data to a remote system present outside of the firewall. Many Linux users also utilize rsync for mirroring websites.

Rsync features:

  • Internal pipe-lining decreases latency for multiple files.
  • rsync is used to update file systems and directory trees.
  • For data transmission, it uses direct sockets, rsh, or ssh.
  • It also can support the anonymous rsync, which is perfect for mirroring.
  • Its installation on Linux does not require any special privileges.
  • rsync also maintains the file ownership, modification time, devices, hard links, and symbolic links.

What is rsync –dry-run?

–dry-run” option allows the rsync command to run a trial without making any changes—most of the time, this process the same output as the real execution. The rsync command is combined with various options to specify what the rsync command will do before someone can execute it.

However, the “–itemize-changes” should also behave the same as a dry run. There must be a bug if both outputs are not the same.

Since a dry run does not sync the actual data for transferring files, the “–progress” operation has no influence. Thus, the bytes received and sent, matched data, and literal data statistics are minimal. Moreover, the “speedup” value equals an actual run where no file transfers were required.

Using rsync –dry-run:

rsync –dry-run with “–delete” option:

Utilize the rsync –dry-run to delete files while running the trial. Here is the syntax of this form of rsync command:

$ rsync -av –dry-run –delete Source remote_host:Destination.

The below-given command is based on the standard rsync syntax for performing a dry run combined with file deletion.

$ rsync -av –dry-run –delete testdir1 10.0.2.15:/home/testdir2

It was a dry run, but you will get a similar output while doing actual file synchronization. The terminal displayed “DRY RUN” at the bottom of the window to ensure that only the dry run was not the actual one.

rsync –dry-run with “–chown” command:

In the rsync command, you can also set the ownership and group of the destination directories by using the “–chown” option while performing the dry run. Check out the below-given syntax of the rsync command:

$ rsync -avhe ssh –dry-run –chown=USER:GROUP Source user@remote-host:Destination

Specify the “user,” “group,” and the “remote_host,” and start the dry run.

$ rsync -avhe ssh –dry-run –chown=linuxhint:linuxhint ./testdir1 linuxhint@10.0.2.15:/

rsync –dry-run with “head” and “tail” commands:

You can also redirect the output of the rsync –dry-run command to any file by using the “>” operator. Furthermore, utilize the head and tail command to select a specific part of the dry run output to be stored. Have a look at the syntax of this rsync command:

$ rsync –dry-run -avz Source Destination | head –lines=-3 | tail –lines=+3 > Filename

We will execute the below-given command, and all of the filtered dry run output will be stored in the “include.txt” file.

$ rsync –dry-run -avz ./testdir1 ./testdir2 | head –lines=-3 | tail –lines=+3 > include.txt

At the end of this procedure, execute the “cat” command to verify the content of the “include.txt” file.

Conclusion:

In Linux-based systems, rsync exists as a free software utility. We can use it to sync directories and files from remote to the local system, local to a remote system, or at the same system. When you combine the rsync command with the “–dry-run” option, this utility runs a trial without making any changes. In this post, we have seen three different of the rsync –dry-run command execution.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More