I would like to log all the output that is generated by rsync; the output that I see when I run the script myself in terminal. I would prefer this logging to occur from within my script.

Here is my backup script, it works fine. BackupPC.sh:

#!/bin/bash #current date and time to be used as filename CDT=`date +%d-%b-%Y-%H-%M` echo "[START] $(date)" >> /home/pi/logs/${CDT}.txt rsync "-avXP" "bassam@192.168.1.2:/home/bassam/Desktop" "/media/hitachi/backup" echo "[END] $(date)" >> /home/pi/logs/${CDT}.txt 

Here is my crontab entry:

0 2 * * * ~/scripts/BackupPC.sh >/dev/null 2>&1 

1 Answer

Bassam:

The rsync command has the --log-file option. In the manual entry:

$ -> man -P cat rsync | grep 'log-file=FILE' --log-file=FILE log what we're doing to the specified FILE 

Then, if I wanna move the file from source/Example to destination and dump the result in the result file, e,g:

rsync -avz source/Example destination/ --log-file=result 

The result is:

)$ -> cat result 2020/06/11 22:09:04 [13891] building file list 2020/06/11 22:09:04 [13891] >f+++++++++ Example 2020/06/11 22:09:04 [13891] sent 101 bytes received 35 bytes 272.00 bytes/sec 2020/06/11 22:09:04 [13891] total size is 0 speedup is 0.00 

Or you can use "--log-file=filename -q" It has more information:

cat result 2020/06/11 22:20:47 [16240] building file list 2020/06/11 22:20:47 [16240] [sender] make_file(Example,*,0) 2020/06/11 22:20:47 [16240] send_file_list done 2020/06/11 22:20:47 [16240] send_files starting 2020/06/11 22:20:47 [16240] send_files phase=1 2020/06/11 22:20:47 [16240] send_files phase=2 2020/06/11 22:20:47 [16240] send files finished 2020/06/11 22:20:47 [16240] total: matches=0 hash_hits=0 false_alarms=0 data=0 2020/06/11 22:20:47 [16240] sent 61 bytes received 12 bytes 146.00 bytes/sec 2020/06/11 22:20:47 [16240] total size is 0 speedup is 0.00 2020/06/11 22:20:47 [16240] [sender] _exit_cleanup(code=0, file=main.c, line=1196): about to call exit(0) 

Edit:

This could also be helpful: Is it possible to make rsync make a log-file on a remote system?

You have another information that can be helpful in your log file:

$ -> rsync --info=help Use OPT or OPT1 for level 1 output, OPT2 for level 2, etc.; OPT0 silences. BACKUP Mention files backed up COPY Mention files copied locally on the receiving side DEL Mention deletions on the receiving side FLIST Mention file-list receiving/sending (levels 1-2) MISC Mention miscellaneous information (levels 1-2) MOUNT Mention mounts that were found or skipped NAME Mention 1) updated file/dir names, 2) unchanged names PROGRESS Mention 1) per-file progress or 2) total transfer progress REMOVE Mention files removed on the sending side SKIP Mention files that are skipped due to options used STATS Mention statistics at end of run (levels 1-3) SYMSAFE Mention symlinks that are unsafe ALL Set all --info options (e.g. all4) NONE Silence all --info options (same as all0) HELP Output this help message Options added for each increase in verbose level: 1) COPY,DEL,FLIST,MISC,NAME,STATS,SYMSAFE 2) BACKUP,MISC2,MOUNT,NAME2,REMOVE,SKIP 
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy