Check for Open files during rsync

Kevin Korb kmk at
Thu Jan 19 10:42:26 MST 2012

Hash: SHA1

Rsync can in fact copy open files.  What it can't handle are files
that are actively being written to at the block level at the time that
rsync attempts to read them.  Rsync reads each block of the file as it
was at that particular instant meaning that the copy can end up with
parts of several versions of that file rather than a complete copy
from a particular point in time.  The most common examples of this
problem are with databases and virtual machine images.

This is due to the simple fact that rsync is a file based utility.
Any file based utility would have this problem on this type of file
including the simple cp.  This is why programs that use files of this
type generally include their own mechanisms for backups.  There isn't
really any way that rsync itself can work around this problem other
than possibly detecting that it happened but there are perfectly
acceptable solutions to it.  Here they are in my order of preference:

1. Do something to freeze the files at a particular point in time.
Since you mentioned fuser I will assume you are on Linux.  In Linux
the standard way to freeze the files is with an LVM2 snapshot.  Then
you rsync backup the snapshot instead of the live files.  Here is a
perl script I wrote to do an LVM snapshot on my MySQL server so that
it could be backed up:
Note that pretty much all of the details are hard coded into it.

2. Use the application's included backup functionality.  Depending on
the application this could be some kind of log that is append only
(rsync is fine with files being appended to) that you have to replay
to restore or it could be something that dumps the data out into a
separate file that you could then backup.  If we are going to use
MySQL as an example again this would be mysqldump or mysqlhotcopy.

3.  Force the application to stop writing to files while the backup
runs.  This generally means shutting down a service or a virtual
machine but sometimes they can just be operated in read only mode.  Of
course this is an intrusive option which is why it is the last one.

On 01/19/12 02:08, charith wrote:
> Hi All,
> I saw on previous mail  thread under topic *"exclude open file in
> backup with rsync (2006)"* That Rsync can't handle open files and
> it sends all files without checking whether they are open.I want to
> know whether still Rsync have this problem or if their any solution
> for this. I really need to check open files and I want to sync
> without open files. if their any way do this using --exclude mail
> thread also explain about "*/you could run fuser on all the files
> and translate the results into exclude rules, but files might open
> and close after rsync starts/"* please anyone can explain this to
> me...

- -- 
	Kevin Korb			Phone:    (407) 252-6853
	Systems Administrator		Internet:
	FutureQuest, Inc.		Kevin at  (work)
	Orlando, Florida		kmk at (personal)
	Web page:
	PGP public key available on web site.
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla -


More information about the rsync mailing list