1

I synchronize data with rsync --delete --backup --backup-dir=[some directory] -avz [source] [destination].

  • On the machine where rsync is executed, both [source] and [destination] directories are NFS exports mounted locally (i.e. the machine running rsync is a NFS client).
  • after a succesfull rsync + some checks, the backup is deleted.

Another machine of my LAN is an application server and has this same [destination] NFS export mounted locally. Due to some intricacies on the application side I have NO CONTROL on, it looks like the application refers to files by their inodes rather than using their names. Which brings difficulties when a file was changed from [source] :

  • let's say that on [destination], this file has the inode 123
  • the application "points to" the file having the inode 123
  • rsync detects a difference between the [source] and [destination] versions of this file and has to transfer it
  • before transferring it, it creates a backup by "moving" it : the backup file now has the inode 123
  • the updated version of the file is transferred by rsync, and gets a new inode (456)
  • after a successfull rsync + checks, the backup is deleted : no file has the inode 123 anymore
  • the application, still pointing to inode 123, is broken
  1. Do you confirm I got it clear about how rsync --backup works and inodes ?
  2. How does the --inplace rsync option work with --backup :
  • will rsync create a backup file having its own inode ?
  • will the file keep its current inode ?
0

1 Answer 1

2

It's almost impossible to refer to a file by its inode. To open a file, it is necessary to open a reference to a file name in a directory. Then you have a file handle which is now independent of the file name (which is why a file can be removed from the filesystem but still be open and active). So, let's assume the file is being kept open throughout the life of the application. You now need to replace the content of this file using rsync.

Normally, rsync will create a temporary copy of the target file alongside any existing instance, and then at the last moment it will delete (or backup) the original and switch in the replacement. This behaviour can be modified with the --inplace option, such that instead of creating a new copy rsync will write to the actual target.

Now, you've also specified --backup, so rsync does the right thing and creates a copy for the backup before allowing --inplace to update the original instance. You can see this with a short example:

# Prepare scenario
mkdir /tmp/624404
cd /tmp/624404
date >src
cp -p src dst

# Initial files, with inodes
ls -li src dst
149172 -rw-r--r-- 1 roaima 29 Dec 14 11:49 dst
137559 -rw-r--r-- 1 roaima 29 Dec 14 11:49 src

# Update, copy, and list
date >src
rsync --times --inplace --backup src dst
ls -li
total 12
149172 -rw-r--r-- 1 roaima 29 Dec 14 11:50 dst
149194 -rw-r--r-- 1 roaima 29 Dec 14 11:49 dst~
137559 -rw-r--r-- 1 roaima 29 Dec 14 11:50 src

# Update again, copy, and list
date >src
rsync --times --inplace --backup src dst
ls -li
total 12
149172 -rw-r--r-- 1 roaima 29 Dec 14 11:50 dst
149194 -rw-r--r-- 1 roaima 29 Dec 14 11:50 dst~
137559 -rw-r--r-- 1 roaima 29 Dec 14 11:50 src

You can see that the destination (dst) file still has its original inode but that the backup has been given a new one. The second update shows that inodes are retained thereafter.

In your instance it does sound like --inplace --backup is what you need. However, please note that the man page warns,

WARNING: you should not use this option to update files that are being accessed by others, so be careful when choosing to use this for a copy.

The reason that --inplace is not a default is that an interrupted partial copy could leave the target file in an inconsistent state, and the author(s) decided that it would be better to have an internally consistent out-of-date file than a corrupted out-of-date file. Such behaviour can be modified with flags such as --inplace and --partial (and even --append with rsync versions 3.0.0 onwards).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.