user3225309
user3225309

Reputation: 1383

rsync inode difference when nothing is changed

I have created a simple bash script that creates three directories that I rsync and afterwards check destinations inodes.

The script is here:

#!/bin/bash

function dorsync()
{
RSYDIR=$DST/$1
#rm -r $RSYDIR

echo "rsync -azP --delete --delete-excluded --link-dest=$LNKDSTDIR $SRC/ $RSYDIR" >> $LOG
rsync -azP --delete --delete-excluded --link-dest=$LNKDSTDIR $SRC/ $RSYDIR
rm -f ${LNKDSTDIR}
ln -sf ${RSYDIR} ${LNKDSTDIR}
echo "-----" >> $LOG
ls -li $DST/$1 >> $LOG
echo "-----" >> $LOG
cat $DST/$1/a.txt >> $LOG 
cat $DST/$1/b.txt >> $LOG
#du $DST >> $LOG 
echo "===================================================================" >> $LOG
}

SRC=~/tmp/src
DST=~/tmp/dst
LOG=~/tmp/log.txt
LNKDSTDIR=${DST}/Current

echo "SRC=$SRC"
echo "DST=$DST"
echo "LOG=$LOG"
echo "LNKDSTDIR=$LNKDSTDIR"


rm -R "$SRC"
rm -R "$DST"
rm $LOG

mkdir $SRC
mkdir $DST

echo "echo 'A0' > $SRC/a.txt" >> $LOG
echo "A0" > $SRC/a.txt

dorsync d0


echo "***********************************************************" >> $LOG
echo "echo 'A1' > $SRC/a.txt" >> $LOG
echo "A1" >> $SRC/a.txt

dorsync d1


echo "***********************************************************" >> $LOG
echo "echo 'B0' > $SRC/b.txt" >> $LOG
echo "B0" > $SRC/b.txt

dorsync d2



echo "***********************************************************" >> $LOG
echo "echo 'A2' > $SRC/a.txt" >> $LOG
echo "A2" >> $SRC/a.txt

dorsync d0



echo "***********************************************************" >> $LOG
echo "no change" >> $LOG

dorsync d1

echo "***********************************************************" >> $LOG
echo "no change" >> $LOG

dorsync d2

The result of the script looks like the following:

echo 'A0' > /home/pi/tmp/src/a.txt
rsync -azP --delete --delete-excluded --link-dest=/home/pi/tmp/dst/Current /home/pi/tmp/src/ /home/pi/tmp/dst/d0
-----
total 4
399342 -rw-r--r-- 1 pi pi 3 Jan 22 22:15 a.txt
-----
A0
===================================================================
***********************************************************
echo 'A1' > /home/pi/tmp/src/a.txt
rsync -azP --delete --delete-excluded --link-dest=/home/pi/tmp/dst/Current /home/pi/tmp/src/ /home/pi/tmp/dst/d1
-----
total 4
399356 -rw-r--r-- 1 pi pi 6 Jan 22 22:15 a.txt
-----
A0
A1
===================================================================
***********************************************************
echo 'B0' > /home/pi/tmp/src/b.txt
rsync -azP --delete --delete-excluded --link-dest=/home/pi/tmp/dst/Current /home/pi/tmp/src/ /home/pi/tmp/dst/d2
-----
total 8
399356 -rw-r--r-- 2 pi pi 6 Jan 22 22:15 a.txt
399359 -rw-r--r-- 1 pi pi 3 Jan 22 22:15 b.txt
-----
A0
A1
B0
===================================================================
***********************************************************
echo 'A2' > /home/pi/tmp/src/a.txt
rsync -azP --delete --delete-excluded --link-dest=/home/pi/tmp/dst/Current /home/pi/tmp/src/ /home/pi/tmp/dst/d0
-----
total 8
399360 -rw-r--r-- 1 pi pi 9 Jan 22 22:15 a.txt
399359 -rw-r--r-- 2 pi pi 3 Jan 22 22:15 b.txt
-----
A0
A1
A2
B0
===================================================================
***********************************************************
no change
rsync -azP --delete --delete-excluded --link-dest=/home/pi/tmp/dst/Current /home/pi/tmp/src/ /home/pi/tmp/dst/d1
-----
total 8
399347 -rw-r--r-- 1 pi pi 9 Jan 22 22:15 a.txt
399359 -rw-r--r-- 3 pi pi 3 Jan 22 22:15 b.txt
-----
A0
A1
A2
B0
===================================================================
***********************************************************
no change
rsync -azP --delete --delete-excluded --link-dest=/home/pi/tmp/dst/Current /home/pi/tmp/src/ /home/pi/tmp/dst/d2
-----
total 8
399361 -rw-r--r-- 1 pi pi 9 Jan 22 22:15 a.txt
399359 -rw-r--r-- 3 pi pi 3 Jan 22 22:15 b.txt
-----
A0
A1
A2
B0
===================================================================

My question is why in two last runs inode for a.txt isn't 399360 instead 399347 and 399361?

Regards.

Upvotes: 1

Views: 2504

Answers (3)

Armali
Armali

Reputation: 19395

rsync(1) - Linux man page

Options

--link-dest=DIR

...

This option works best when copying into an empty destination hierarchy, as rsync treats existing files as definitive (so it never looks in the link-dest dirs when a destination file already exists)...

In your last two runs, a.txt already existed in the destination directories.

Upvotes: 0

user3225309
user3225309

Reputation: 1383

In my case the file in src directory is the same in let's say d0. If I am rsyncing from src to d1 by using --link-dest d0, I would expect that in d1 I will have the same inode as in d0 because nothing has changed.

If you look at the file b.txt, you will see that when there is no change (3. and 4. iteration), inode 399359 is the same. I just wander why the sambe behaviour is not with the a.txt.

As I understand rsync, if the file from the source dir is the same in the --link-dest dir, just add a hard link in destination directory. If the file is changed, than send delta data and create a new inode.

Regards.

Upvotes: 0

that other guy
that other guy

Reputation: 123630

This is because --link-dest specifies a directory where rsync should look for identical files.

You never write files to it, so it doesn't contain identical files to link against. rsync therefore doesn't link, causing the filenames to have different inodes.

Upvotes: 1

Related Questions