Posts Tagged ‘rsync’

Rsync and details on what has changed

January 13th, 2017 No comments


# create a directoy and a couple of files 
mkdir /tmp/mydir1;
mkdir /tmp/mydir1/data;
echo "hello" > /tmp/mydir1/hello.txt;
echo "name is john" > /tmp/mydir1/name.txt;
mkdir -p /tmp/mydir1/dir1/dir2/dir3/dir4/dir5;

# copy the directory with all permissions etc to a new directory 
# -a : copy exactly with owner, group, permissions etc
# -r : recursive
cp -ar /tmp/mydir1 /tmp/mydir2

Some rsync options 

  • –dry-run : only do a simulation – don not perform the actual action
  • -v : verbose
  • -a : archive mode – this is equal to specifying all these options ( -r -l -p -t -g -o – D )
  • -r : recursive
  • -l : copy symlinks as symlinks
  • -p : preserve permissions
  • -t : preserve file timestamps
  • -g: preserve group
  • -o: preserve owner
  • -D: preserve device files and special files
  • -c : compare file checksum instead of timestamp and filesize
  • -i : format the output
  • –delete: delete any files in destination that are not in the source

First try – simple dry run 

# rsync --dry-run -avc --delete /tmp/mydir1/ /tmp/mydir2/
sending incremental file list


Nothing has changed as we have exactly copied the two directories.
Now lets make some changes to mydir2

echo "hello again" >> /tmp/mydir2/hello.txt;
touch /tmp/mydir2/newfile.txt;
chmod o+rwx /tmp/mydir2/dir1;
mkdir /tmp/mydir2/newdir;
chgrp nobody /tmp/mydir2/dir1/dir2;
chown nobody /tmp/mydir2/dir1/dir2/dir3;

Try again 

# rsync --dry-run -avc --delete /tmp/mydir1/ /tmp/mydir2/
sending incremental file list
deleting newdir/
deleting newfile.txt

You will see what changes will be done in this list

To see more details use the  –itemize-changes( -i ) option.
This will tell in detail what attribute has changed

Second try – lets format the output 

# rsync --dry-run -avci --delete /tmp/mydir1/ /tmp/mydir2/
sending incremental file list
.d..t...... ./
*deleting newdir/
*deleting newfile.txt
>fcst...... hello.txt
.d...p..... dir1/
.d.....g... dir1/dir2/
.d....o.... dir1/dir2/dir3/

We can now see that some things have been appended to the list of files – explanation are ( see man rsync for more details on –itemize-changes )

  • (>) means file is being transferred
  • (c) means a change is happening or file is being created
  • (*deleting) means file will be deleted on destination
  • (p) means permission changed
  • (g) means group changed
  • (o) means owner changed




Categories: Linux Tags: