'Register Rsync only if you have information
What should I add so that my little script logs the rsync command only if it contains files to copy and is not every 5 minutes logging nothing.
#!/bin/bash
#Synchronize Transfer directories.
ORIGIN=/home/sftp/prueba/Reception/
DESTIN=/mnt/prueba
DATE_Y_Time=`date "+%d-%m-%y_%H-%M-%S"`
ROUTE_LOG="/opt/rundeck/commands/haya/rsync.txt"
echo "[$DATE_Y_Time] Starting Synchronization ..." >> $RUTA_LOG
rsync -vr --times $ORIGIN $DESTINATION >> $RUTA_LOG
This generates the following,
sent 25,430 bytes received 12 bytes 2,993.18 bytes/sec. the total size is 444,102,483 speedup is 17,455.49 [19-03-22_23-36-01] Starting Synchronization ... sending incremental file list
sent 25,430 bytes received 12 bytes 4,625.82 bytes/sec total size is 444,102,483 speedup is 17,455.49 [19-03-22_23-42-01] Starting Synchronization ... sending incremental file list
But of course I would like that it only registers if it has files to copy if there is nothing even if it is executed it is not filling the log of the same thing.
Greetings
Solution 1:[1]
If you use something like:
rsync -vir --times --info=STATS0,FLIST0 $ORIGIN $DESTINATION >> $RUTA_LOG
you will see which files are transfered (any why). If nothing is transfered this will be silent. But you will not get any performance-statistics.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sprobst |
