Search code examples
backuprsync

rsync fails to copy /home directory


What am I missing?

I have Ubuntu 20.04.3 LTS with an AMD® Ryzen 5 2600 six-core processor × 12 and 15.6 GiB memory

and GNU bash, version 5.0.17(1)-release-(x86_64-pc-linux-gnu)

I am using rsync with parameters in an array as follows:

sudo su
options=( $params$delete$crossfilesystem$excludefile$includefile )
cd /
rsync "${options[@]}" / $target

The various parameters expand correctly to:

rsync -aAXHv --one-file-system --exclude-from=/home/bill/rsync-excludes / /media/bill/spare

The excluded files are empty as expected. However, /home is also empty - not as expected.

I have tried using rsync without using parameters and get the same results whether using a script or not, starting from root or from my home directory, there is nothing in /home. I haven't seen any error messages pop up.

root@wrcraig:/# ls -la /media/bill/spare/home
total 8
drwxr-xr-x  2 root root 4096 Apr 18 08:40 .
drwxr-xr-x 26 root root 4096 Aug 23 17:52 ..

But if I backup just the /home directory, everything works properly using either:

rsync -aAXHv --one-file-system --exclude-from=/home/bill/rsync-excludes /home $target
  or
rsync "${options[@]}" /home $target

This is the exclude file (/home/bill/rsync-excludes)

/dev/*
/home/*/.cache/mozilla/*
/home/*/.cache/thunderbird/*
/home/*/.cache/chromium/*
/home/*/.local/share/Trash/*
/proc/*
/sys/*
/tmp/*
/run/*
/mnt/*
/home/*/.gvfs
/var/lib/dhcpcd/*
swap
/var/cache/zoneminder/events/*
/media/*
lost+found

Solution

  • You see this behaviour because you used --one-file-system but your /home directory is a different filesystem from /.

    -x, --one-file-system
        This tells rsync to avoid crossing a  filesystem  boundary  when
        recursing.   This  does  not limit the user’s ability to specify
        items to copy from multiple filesystems, just rsync’s  recursion
        through the hierarchy of each directory that the user specified,
        and also the analogous recursion on the  receiving  side  during
        deletion.  Also keep in mind that rsync treats a "bind" mount to
        the same device as being on the same filesystem.
    
        If this option is repeated, rsync omits all mount-point directo‐
        ries  from  the copy.  Otherwise, it includes an empty directory
        at each mount-point it encounters (using the attributes  of  the
        mounted  directory  because  those of the underlying mount-point
        directory are inaccessible).