0

I use rsync to backup my data from one server to the other. This works great.

rsync -aktvu -e 'ssh -p 22' --modify-window=1 --progress $SOURCE $USER@$SERVER:$DESTINATION

The output display what has been copied over:

building file list ...
11 files to consider
./
server/

server/myfile.txt
        3152 100%    0.00kB/s    0:00:00 (xfer#1, to-check=8/11)
server/test/
server/test/logfile01
        8266 100%    7.88MB/s    0:00:00 (xfer#2, to-check=6/11)
server/test/logfile07
       41004 100%   39.10MB/s    0:00:00 (xfer#3, to-check=5/11)
server/test/logfile08
         318 100%  310.55kB/s    0:00:00 (xfer#4, to-check=4/11)
server/test/logfile09
        8262 100%    7.88MB/s    0:00:00 (xfer#5, to-check=3/11)
server/test/logfile30
       40325 100%   12.82MB/s    0:00:00 (xfer#6, to-check=2/11)
server/test/logfile31
         792 100%  193.36kB/s    0:00:00 (xfer#7, to-check=1/11)
server/test/logfile32
        3152 100%  769.53kB/s    0:00:00 (xfer#8, to-check=0/11)

sent 105902 bytes  received 214 bytes  14148.80 bytes/sec
total size is 105271  speedup is 0.99

I would like to get this output and save it to a file for reference. So I tried this,

test_output=$(rsync -aktvu -e 'ssh -p 22' --modify-window=1 --progress $SOURCE $USER@$SERVER:$DESTINATION)

getscript() {
   pgrep -lf ".[ /]$1( |\$)"
}

getscript "sync.sh" >/dev/null && echo "sync.sh" $test_output >> outputfile.txt;

It works great but the output are all on one line. It's not nicely indented like above. How can I output it so it will be nicely indented?

tks

  • 1
    What's the reason for your getscript function? – Kusalananda Aug 3 '18 at 17:30
2

man rsync will show an option to log output to a logfile:

--log-file=FILE This option causes rsync to log what it is doing to a file. This is similar to the logging that a daemon does, but can be requested for the client side and/or the server side of a non-daemon transfer. If specified as a client option, transfer logging will be enabled with a default format of "%i %n%L". See the --log-file-format option if you wish to override this.

  • Thank you roaima for the response. So my code is rsync -aktvu --log-file=/scripts/web/output/outfile-sync.log -e 'ssh -p 22' --modify-window=1 --progress $SOURCE $USER@$SERVER:$DESTINATION but when I included the --log-file=FILE it gives me an error. rsync: --log-file=/scripts/web/output/outfile-sync.log: unknown option rsync error: syntax or usage error (code 1) at main.c(1243) [client=2.6.8] I checked the man pages but it doesn't include this option, --log-file. I'm using rsync version 3.0.9. I assume my rysnc does not have this option. Is there a workaround?? – Tran Aug 7 '18 at 13:55
  • Hmm. You seem to be using version 2.6.8 of rsync, which is so old all bets are off. It was updated in November 2006 so I'd recommend you get that fixed first. The security issues with a system running code that out of date hardly bear thinking about. Ugh! – roaima Aug 7 '18 at 21:40
  • I've updated my rsync and now I'm able to see the --log-file=FILE in the man page. tks – Tran Aug 9 '18 at 17:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.