Using rsync to backup files as a non-root user

I'm using rsync over SSH to do backups between two systems. When you run your backup as non-root user, you cannot save the files owner or group (uid/gid) because only root is allowed to change ownership. You can however tell rsync to store the owner/group in the file's xattrs. This requires that you mount your filesystems with user_xattr:

/dev/sdb1 /backup ext4    defaults,user_xattr        1 2

Then you tell the writing rsync to use --fake-super

rsync -avP --rsync-path='/usr/bin/rsync --fake-super' /src/dir backup-user@domain.com:/dst/dir

This example is a push backup, if it were a pull you'd put --fake-super on the local side. Then to do a restore you'd do the same thing in reverse with the reading side (where the xattrs are stored) getting --fake-user:

rsync -avP --rsync-path='/usr/bin/rsync --fake-super' backup-user@domain.com:/src/dir /dst/dir

You can see the attributes for a given file with getfattr:

getfattr -d *

# file: dovecot.index
user.rsync.%stat="100600 0,0 89:89"

If you don't get any output, there are no xattrs for that file.

Leave A Reply
All content licensed under the Creative Commons License