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!