Bug 1455 - Make -x skip a "bind" mount point to the same filesystem
Summary: Make -x skip a "bind" mount point to the same filesystem
Alias: None
Product: rsync
Classification: Unclassified
Component: core (show other bugs)
Version: 2.6.3
Hardware: x86 Linux
: P5 enhancement (vote)
Target Milestone: ---
Assignee: Wayne Davison
QA Contact: Rsync QA Contact
Depends on:
Reported: 2004-06-10 13:27 UTC by mario
Modified: 2005-04-01 11:21 UTC (History)
0 users

See Also:

Improved mntexcl perl script (407 bytes, text/plain)
2004-06-10 15:35 UTC, Wayne Davison
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description mario 2004-06-10 13:27:14 UTC
I used the command "/usr/bin/rsync -avx --delete --numeric-ids /www/
/backup/daily.0/www/" and got the following output:

building file list ... done

Due to the -x option, rsync shouldn't touch my lib subdirectory.

Here is the output of "mount":

/dev/hda3 on / type reiserfs (rw,noatime)
none on /dev type devfs (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
none on /dev/shm type tmpfs (rw)
/bin on /www/bla/bin type none (ro,bind)
/etc on /www/bla/etc type none (ro,bind)
/dev on /www/bla/dev type none (ro,bind)
/lib on /www/bla/lib type none (ro,bind)
/usr on /www/bla/usr type none (ro,bind)

I use Gentoo Linux with rsync-2.6.2-r3 .
Comment 1 Wayne Davison 2004-06-10 15:10:31 UTC
Since the bla/lib dir is on the same partition as bla, there is no way for the
current rsync algorithm to notice any difference (the stat() call shows no
change because the files dirs are actually on the same filesystem).  It might be
possible to do something like transform a mount list into an exclude list, but
only if it could be done portably (e.g. by using getfsent(), getmntent(), or
whatever is available).

In the meantime I've changed this bug to an enhancement request.

Your best bet for a quick fix is to use some explicit excludes.  One way is to
use a perl script to automatically create an exclude list from the /proc/mounts
file, like this one (name this "mntexcl"):

#!/usr/bin/perl -w
use strict;
my $start_dir = shift;
$start_dir =~ s#^([^/])#$ENV{'PWD'}/$1#;
my($prefix, $suffix) = $start_dir =~ m#^(.*/)([^/]*)$#;
open(IN, '/proc/mounts') or die $!;
while (<IN>) {
    $_ = (split)[1];
    next unless s#^\Q$prefix\E##o && $_ ne '';
    next if $suffix ne '' && !m#^\Q$suffix\E/#o;
    print "/$_\n";
close IN;

You could feed this into rsync like this (specifying the starting directory to
mntexcl so that it can properly trim the excludes):

mntexcl /www/ | rsync --exclude-from=- ... /www/ /backup/daily.0/www/
Comment 2 Wayne Davison 2004-06-10 15:35:40 UTC
Created attachment 542 [details]
Improved mntexcl perl script

A few minor improvements to the in-line script mentioned in comment #1.  This
script expects /proc/mounts to exist, but could be easily adapted to read
/etc/mtab or similar.
Comment 3 Wayne Davison 2005-02-13 22:25:27 UTC
I don't see this being done automatically in rsync.

There is now a script named mnt-excl in the support dir that is an updated
version of the script that is attached to this bug report.