Non-Root Filesystem Backup with rsync: Preserving File Ownership for Incremental Backups


4 views

When performing system backups with rsync as a non-root user, preserving file ownership becomes problematic because:

  • Standard Unix permissions prevent non-root users from changing file ownership
  • Backup restoration requires maintaining original UID/GID information
  • Traditional rsync approaches (--owner --group) require root privileges

1. FUSE-based Virtual Filesystem Approach

Using FUSE (Filesystem in Userspace) to create a virtual filesystem that stores ownership metadata:


# Install fuse-posixovl
sudo apt-get install fuse-posixovl

# Mount with virtual ownership capabilities
posixovl -o noexec,nosuid ~/backup_mount
rsync -a --numeric-ids /source/ ~/backup_mount/backup/

2. Metadata Sidecar Files

Store ownership information in separate metadata files during backup:


# Backup script example
find /source -printf "%u:%g:%m:%p\\n" > ~/backup_metadata.txt
rsync -a --no-owner --no-group /source/ ~/backup_data/

3. Tar + rsync Hybrid Solution

Combine tar's ownership preservation with rsync's incremental capabilities:


# Initial full backup
tar --numeric-owner -cvzf full_backup.tar.gz /source

# Subsequent incremental backups
rsync -a --link-dest=~/previous_backup /source/ ~/incremental_backup/
tar --numeric-owner -cvzf incremental_$(date +%F).tar.gz ~/incremental_backup
  • Performance impact of each solution (FUSE has ~15% overhead)
  • Restoration complexity (metadata files require custom restore scripts)
  • Space requirements (tar backups consume more space than pure rsync)

#!/bin/bash
# Restore from metadata+rsync backup

BACKUP_DIR=~/backup_data
META_FILE=~/backup_metadata.txt

while IFS=: read -r user group mode path; do
    chown "$user:$group" "$BACKUP_DIR$path"
    chmod "$mode" "$BACKUP_DIR$path"
done < "$META_FILE"

When performing system backups as a non-root user, traditional tools like rsync hit a permissions wall. The standard -a (archive) flag attempts to preserve ownership, but fails without root privileges:

rsync -avz /source/path/ backup-server:/backups/
# rsync: failed to set ownership on "/backups/somefile": Operation not permitted

Here are practical approaches to maintain ownership data without requiring root access:

1. Virtual Ownership Mapping with FUSE

The fuse-map filesystem allows non-root users to store ownership metadata:

# Create ownership mapping database
mkdir ~/backup-metadata
fuse-map -o dbpath=~/backup-metadata/ownership.db /mnt/virtual-backups

# Rsync with metadata capture
rsync -avz --fake-super --files-from=filelist.txt / /mnt/virtual-backups

2. Extended Attribute Storage

Use Linux extended attributes (xattrs) to store ownership info:

# Backup with xattr preservation
rsync -avX --filter=':xattr.user.owner' /source/ /backup/

# Restore ownership from xattrs
getfattr -d -m 'user.owner' --absolute-names /backup/file | \
while read line; do
  [ -z "$line" ] || echo "$line" >> ownership_restore.sh
done

3. Tar + Rsync Hybrid Approach

Combine tar's metadata capabilities with rsync's delta transfers:

# Initial full backup
tar --xattrs --acls --selinux -cvf full_backup.tar /path/to/backup

# Incremental updates
rsync -av --compare-dest=/path/to/full_backup /source/ /incremental/
tar --xattrs --acls --selinux -uvf incremental_$(date +%F).tar /incremental/

Here's a complete backup script using metadata files:

#!/bin/bash
BACKUP_DIR="/mnt/backups"
METADATA_FILE="${BACKUP_DIR}/ownership_metadata.txt"

# Capture ownership data
find /path/to/backup -printf "%u:%g %p\\n" > "${METADATA_FILE}"

# Perform rsync without ownership changes
rsync -rlptDv --delete /path/to/backup/ "${BACKUP_DIR}/data"

# Restoration script generator
echo '#!/bin/bash' > "${BACKUP_DIR}/restore_ownership.sh"
awk '{print "chown", $1, $2}' "${METADATA_FILE}" >> "${BACKUP_DIR}/restore_ownership.sh"
chmod +x "${BACKUP_DIR}/restore_ownership.sh"

When implementing these solutions:

  • Always verify metadata files haven't been tampered with before restoration
  • Consider encrypting ownership metadata files
  • Maintain strict permissions on backup directories
Tool Ownership Preservation Root Required
rsync Partial (with --fake-super) Yes (for direct chown)
tar Full On restore
borg Via metadata files No