1

Similar questions have been asked and I think I've read most of them, basically, rsync -a --stats src/ dest/ shows a neat summary, but if I also use --log-file= I get a (huge) list of files and folders, I'm trying to get ONLY the summary in to a file so I can email it, regardless of the how, maybe --log-file= is not the right way, so my question again:

Running from a script, is there a way to get only the summary in a file?

Thanks.

Scar_UY
  • 11

2 Answers2

0

Yes, you can get only the summary of an rsync operation in a log file by redirecting the output of rsync and then filtering it to include only the summary. One way to achieve this is by using grep or awk to extract the summary part after the rsync operation is complete.

I've reused this lots of times:

#!/bin/bash

Define source and destination directories

SRC="src/" DEST="dest/"

Define temporary and final log files

TEMP_LOG="/tmp/rsync_temp.log" FINAL_LOG="/path/to/rsync_summary.log"

Run rsync and save the entire output to the temporary log file

rsync -a --stats "$SRC" "$DEST" &> "$TEMP_LOG"

Extract the summary and save it to the final log file

awk '/^Number of files:/,/^$/ {print}' "$TEMP_LOG" > "$FINAL_LOG"

Optionally, remove the temporary log file

rm "$TEMP_LOG"

Explanation:

rsync -a --stats "$SRC" "$DEST" &> "$TEMP_LOG": Runs rsync with archive mode (-a) and statistics (--stats) and redirects both stdout and stderr to the temporary log file.

awk '/^Number of files:/,/^$/ {print}' "$TEMP_LOG" > "$FINAL_LOG": Uses awk to extract the lines from the temporary log file starting with "Number of files:" to the first empty line (which is where the summary section ends) and saves this to the final log file.

rm "$TEMP_LOG": Optionally removes the temporary log file to clean up.

Good luck!

Max Haase
  • 1,123
0

Max Haase response worked great, but now I came upon something strange while trying to send that by email, if you're curious : here“s the post

Scar_UY
  • 11