How to Log rsync Transfers on Linux

When executing the rsync command, especially with the -v (verbose) option, you’ll see related output in your terminal. But what if you need to save this output, either because you want to refer to it later, or you need to check on unattended rsync transfers? In this guide, we’ll see how to log rsync transfers on Linux.

There are several ways to send rsync’s output to a log file, depending on what exactly you’d like to do. Check out the examples below for various ways to do it.

Log rsync Output

Example 1. The --log-file option is built into rsync and will send detailed transfer information to a log file, while still sending output to your terminal as well.

$ rsync -av --log-file=transfer.log /src /dst

Afterwards, check on your log file to see information about what files were transferred. Itemized output is also shown in the log file, so you can see if a file’s modified time, permissions, etc. were changed.

$ cat transfer.log
 
sending incremental file list
src/test1.txt
src/test2.txt

sent 241 bytes  received 55 bytes  592.00 bytes/sec
total size is 22  speedup is 0.07
2021/05/28 23:19:00 [1655] building file list
2021/05/28 23:19:00 [1655] cd+++++++++ src/
2021/05/28 23:19:00 [1655] >f+++++++++ src/test1.txt
2021/05/28 23:19:00 [1655] >f+++++++++ src/test2.txt
2021/05/28 23:19:00 [1655] sent 244 bytes  received 58 bytes  604.00 bytes/sec
2021/05/28 23:19:00 [1655] total size is 22  speedup is 0.07

Example 2. You don’t have to use rsync’s --log-file parameter if you’d prefer not to. The most basic way to log rsync output is by redirecting standard output with the > operator. Here’s what your command would look like.

$ rsync -av /src /dst > transfer.log

Then, you can check the log file to see details about your rsync transfer.

$ cat transfer.log

sending incremental file list
src/
src/test1.txt
src/test2.txt

sent 241 bytes  received 55 bytes  592.00 bytes/sec
total size is 22  speedup is 0.07

There’s one potential problem here, which is that error messages (stderr) will still show up in terminal, not the log file. The next example overcomes this issue.

Example 3. To redirect rsync output, as well as error messages, to a log file, use the following command syntax.

$ rsync -av /src /dst > transfer.log 2>&1

Example 4. It’s also possible to have output sent to the terminal and the log file simultaneously. To do so, we can use the tee command as shown below.

$ rsync -av /src /dst | tee transfer.log 2>&1

Using this command means that rsync’s standard output (stdout) and standard error (stderr) will be sent to our terminal and the log file at the same time.

2 thoughts on “How to Log rsync Transfers on Linux”

Leave a Comment

Your email address will not be published. Required fields are marked *