1

In order to generate some random files, I have created a script which is as follows:

#!/bin/bash

for dir in `seq 1 10`
do
        mkdir /root/mandar/RsyncSrc/$dir
        cd /root/mandar/RsyncSrc/$dir
        for file in `seq 11 20`
        do
                touch /root/mandar/RsyncSrc/$dir/$file
        done
done

Thus, the contents of /root/mandar/RsyncSrc directory looks like:

1  10  2  3  4  5  6  7  8  9  mkfiles.sh

Case 1 (With cp command):

I execute the following command in order to sync /root/mandar/RsyncSrc with /root/mandar/RsyncDst directory:

cp -R /root/mandar/RsyncSrc/* /root/mandar/RsyncDst/

Contents of /root/mandar/RsyncDst directory:

1  10  2  3  4  5  6  7  8  9  mkfiles.sh

Now, I run the rsync dry-run in order to get list of affected files as follows:

rsync -avzm --stats --safe-links --dry-run --ignore-existing --human-readable /root/mandar/RsyncSrc/*  /root/mandar/RsyncDst/ > test.log

Contents of test.log file:

building file list ... done
1/
10/
2/
3/
4/
5/
6/
7/
8/
9/

Number of files: 112
Number of files transferred: 0
Total file size: 234 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 926
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 963
Total bytes received: 42

sent 963 bytes  received 42 bytes  2.01K bytes/sec
total size is 234  speedup is 0.23 (DRY RUN)

Case 2 (With rsync command):

I deleted everything from /root/mandar/RsyncDst and executed following command to sync the data:

rsync -avzm --stats --safe-links --ignore-existing --human-readable /root/mandar/RsyncSrc/*  /root/mandar/RsyncDst/

And then re-run the dry-run as follows:

rsync -avzm --stats --safe-links --dry-run --ignore-existing --human-readable /root/mandar/RsyncSrc/*  /root/mandar/RsyncDst/ > test.log

This time, contents of test.log are:

building file list ... done

Number of files: 112
Number of files transferred: 0
Total file size: 234 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 926
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 933
Total bytes received: 12

sent 933 bytes  received 12 bytes  1.89K bytes/sec
total size is 234  speedup is 0.25 (DRY RUN)
  1. Why is it not showing any files/directories in the log file, in case of rsync (case 2)?
  2. If I need to show file listing in the log with rsync (case 2), what am I supposed to do?
  • Which version of rsync are you using? I get a different output. – X Tian May 28 '15 at 15:10
  • rsync-3.0.6-9.el6_4.1.x86_64 – Mandar Shinde May 29 '15 at 8:13
1

This is because you are using the -a option when you do the copy with rsync and you do not use the -a option with cp. This results in the timestamps on the cp copied files not being preserved.

PS giving rsync additional -v options results in additional output. Although I am using rsync version 3.1.0 protocol version 31, which has a slightly different output report, it has the same results as yours. When I used -a option on the initial cp copy, rsync outputs the same on my rsyncDstCp and rsyncDstRsync directories.

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.