18

I am trying to create a log text file after doing an rsync. I've tried using a command line:

rsync -av /source/ /dest/ > log.txt

The text file that was created only shows the file names that are "different" between the source folder & the destination folder, which is close to what I want.

Is there a way for me to create a log file that groups the files that are "different" into files that were modified & created?

2 Answers 2

24

Use the --log-file option. See man rsync for details. Example usage:

rsync -av /source/ /dest/ --log-file=mylog.log

Note that successive runs will append to the log file, rather than overwriting it. Also, rsync logs both stderr and stdout type information to the specified log file.

12

The main idea
For any modern rsync it's possible to use --info instead of -v, e.g:

rsync --info=COPY2,DEL2,NAME2,BACKUP2,REMOVE2,SKIP2 -a source/ dest/ > log.txt
# or eventually with --log-file=mylog.txt

Some additional operations

The resulting output/file will be similar to

file1.zip is uptodate
file2.odt
Dir1/
Dir1/file3.txt

Then you can use grep to filter the results, for example with something like

grep    'is uptodate' mylog.txt | sed 's/is uptodate//g' > Already_Uptodate.txt
grep -v 'is uptodate' mylog.txt                          > Updated_Now.txt

In the first line I deleted the string 'is uptodate' with sed to have a more clean output. This open the problem if you have a file named 'is uptodate' of course :-) It has to be handled in a different way...


Some words more

You can select the info and the info level that you desire for each single option

In a modern rsync, the -v option is equivalent to the setting of groups of --info and --debug options.

You can choose to use these newer options in addition to, or in place of using --verbose, as any fine-grained settings override the implied settings of -v.

Both --info and --debug have a way to ask for help that tells you exactly what flags are set for each increase in verbosity.

The list obtained with rsync --info=help is reported below meanwhile the one from rsync --debug=help is not reported at all:

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

In case on of the rsync (client-server) is not enough modern you have to use more v and more effort. Indeed you can use -vv, -vvv, -vvvv increasing each time in verbosity, but the parsing will be more complex.

More than two -v options should only be used if you are debugging rsync

A really useful lecture might be man rsync in the section where it speaks about the options -v and especially --info=FLAGS.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .