When performing large-scale backups using rsync over NFS mounts, you might encounter Error 22 ("Invalid argument") during file operations. This typically manifests when rsync attempts to modify file ownership or permissions on the destination NFS volume.
# Typical error patterns:
rsync: chown "/backup/path/file.ext" failed: Invalid argument (22)
rsync: set times on "/backup/path/directory" failed: Invalid argument (22)
The error stems from NFS protocol limitations and UID/GID mapping issues between systems. When your source and destination systems have different user/group numbering schemes or when NFS exports are configured with restricted permissions, rsync's attempts to preserve ownership (--numeric-ids) or permissions (-p) will fail.
Here are several approaches to resolve this:
Option 1: Modify Your Rsync Command
rsync -av --no-owner --no-group --no-perms \
--exclude-from="/path/to/exclude_file" / /nas1/
Option 2: Adjust NFS Server Configuration
On your NFS server, ensure proper ID mapping:
# /etc/exports example:
/export 192.168.1.0/24(rw,all_squash,anonuid=65534,anongid=65534)
Option 3: Use Intermediate Archive
tar cf - --one-file-system / | (cd /nas1 && tar xpf -)
If you must preserve permissions:
- Ensure identical UID/GID on both systems
- Consider using --super with rsync
- Try NFSv4 which has better ID mapping support
For critical systems where rsync fails:
# Using tar over ssh:
tar -czf - /source | ssh user@backup-server "cat > /backup/archive.tgz"
# Using rdiff-backup:
rdiff-backup --no-hard-links --exclude-globbing-filelist exclude.txt / backup-server::/backup
Remember to test your backup solution thoroughly before relying on it for production systems.
When performing system backups using rsync to an NFS-mounted volume, you might encounter Error 22 with messages like:
rsync: chown "/nas1/home/8003/.local/share/icons/application-x-wine-extension-its.png"
failed: Invalid argument (22)
This typically occurs when rsync attempts to change file ownership on the destination NFS share but encounters permission or filesystem limitations.
The root causes generally fall into these categories:
- NFS server configuration restricting ownership changes
- UID/GID mapping issues between systems
- Special characters in filenames (even with -s flag)
- NFS version compatibility problems
Here are several approaches to resolve this:
# Solution 1: Skip ownership changes
rsync -sav -S --stats -H --numeric-ids --delete -D \
--no-owner --no-group \
--exclude-from="/usr/local/bin/rsync_nas1_exclude" / /nas1/
Or for more granular control:
# Solution 2: Use rsync's chown alternative
rsync -sav -S --stats -H --numeric-ids --delete -D \
--usermap=*:nobody --groupmap=*:nogroup \
--exclude-from="/usr/local/bin/rsync_nas1_exclude" / /nas1/
For persistent NFS issues, consider these server-side adjustments:
# In /etc/exports on the NFS server:
/nas1 *(rw,sync,no_root_squash,no_subtree_check,anonuid=65534,anongid=65534)
Then remount the share:
sudo exportfs -ra
sudo umount /nas1
sudo mount -t nfs nfsserver:/nas1 /nas1
When rsync proves problematic, this method often works:
cd /
tar --numeric-owner --exclude-from=/usr/local/bin/rsync_nas1_exclude \
-cpf - . | (cd /nas1 && tar -xpf -)