DEV Community

Cover image for rsync - 10 examples in 11 days (Day 10)
m4r4v
m4r4v

Posted on

rsync - 10 examples in 11 days (Day 10)

Day 10

10 examples in 11 days

Sync --i, --itemize-changes

Now in Day 10 I will talk about a flag that can't be out of this series. I am talking about the -i option.

This option allows us to know what changes were made. This option comes very handy when it used along with the --dry-run flag.

Here is what the man page says about it:

-i,--itemize-changes       output a change-summary for all updates
Enter fullscreen mode Exit fullscreen mode

But how is the output will look like?

Whenever we use the -i we get a string of characters YXcstpoguax (not all of them) on which each one has its own meaning:

source: man rsync

Y and X

Y/X Description
Y Is the type of update
X Is the file-type
Y Description
< a file is being transferred to the remote host (sent)
> a file is being transferred to the local host (received)
c means that a local change/creation is occurring for the item (such as the creation of a directory or the changing of a symlink, etc.).
h the item is a hard link to another item (requires--hard-links.
. the item is not being updated (though it might have attributes that are being modified)
* means that the rest of the itemized-output area contains a message (e.g. "deleting")
X Description
f for a file
d for a directory
L for a symlink
D for a device
S for a special file (e.g. named sockets and fifos).

Attributes cstpoguax

Attributes Description
c Means either that a regular file has a different checksum (requires --checksum) or that a symlink, device, or special file has a changed value. Note that if you are sending files to an rsync prior to 3.0.1, this change flag will be present only for checksum-differing regular files.
s Means the size of a regular file is different and will be updated by the file transfer.
t Means the modification time is different and is being updated to the sender’s value (requires --times). An alternate value of T means that the modification time will be set to the transfer time, which happens when a file/symlink/device is updated without --times and when a symlink is changed and the receiver can’t set its time.
p Means the permissions are different and are being updated to the sender’s value (requires --perms).
o Means the owner is different and is being updated to the sender’s value (requires --owner and super-user privileges).
g Means the group is different and is being updated to the sender’s value (requires --group and the authority to set the group).
u Slot is reserved for future use.
a Means that the ACL information changed.
x Means that the extended attribute information changed.

Let's see an example using a file inside our already known Users and Sync folders:

Note: I will run this with the -n flag which is he short for --dry-run

iamgroot@laptop:~$ rsync -vhrin Users/ Sync
sending incremental file list
>f+++++++++ file1.txt

sent 69 bytes  received 19 bytes  176.00 bytes/sec
total size is 12  speedup is 0.14 (DRY RUN)
Enter fullscreen mode Exit fullscreen mode

As you can see, we get >f+++++++++ file1.txt that means:

  • > : a file is being transferred to the local host (received)
  • f : file not a directory
  • +++++++++ : no other attributes (because we don't have anything in our Sync directory)

If I sync our folders and after doing it, I modify the file and sync it again, I get:

f.sT...... file1.txt.

I got an s meaning that the file size changed and I also got a T instead of the t attribute. The T means that the modification time will be set to the transfer time.

If I change the owner and the group to root, and run my rsync as super-user, I would get:

>f.st.og... file1.txt

Verifying Owner and Group of the file so you can see the reuslt above

iamgroot@laptop:~$ sudo chown root ~/Users/file1.txt && sudo chgrp root ~/Users/file1.txt && sudo rsync -vhaio /home/iamgroot/Users/ /home/iamgroot/Sync
sending incremental file list
.d..t...... ./
>f.st.og... file1.txt

sent 186 bytes  received 38 bytes  448.00 bytes/sec
total size is 58  speedup is 0.26
iamgroot@laptop:~$ ls -la Sync/file1.txt
-rw-rw-r-- 1 root root 58 jul 26 01:20 Sync/file1.txt
Enter fullscreen mode Exit fullscreen mode

I will end up this post, mentioning that is very useful to use the --out-format='arguments' with this, just for reference I will show you an example:

iamgroot@laptop:~$ rsync -vhrin --out-format='%l %n %i' /home/iamgroot/Users/ /home/iamgroot/Sync
sending incremental file list
58 file1.txt >f+++++++++

sent 67 bytes  received 19 bytes  172.00 bytes/sec
total size is 58  speedup is 0.67 (DRY RUN)
Enter fullscreen mode Exit fullscreen mode

The final output is 58 which is the length in bytes and the argument is the %l. We asked for the file name (file1.txt) using the %n argument and the %i to get the changes >f+++++++++

I think you get the idea, if not or if you have any doubt don't hesitate asking me, will be more than happy to help.

Ok, that'll be it for today.


Thanks for reading, keep it safe!!

Follow, ❤️ or 🦄

Top comments (0)