I'm using rsync
to backup local files to a usb disk. That has been working fine for years, but now rsync
is reporting filesystem permission errors, even though run as root on a rw filesystem. This is the command that I run and part of the log outputs:
$ sudo rsync --verbose --archive --delete --partial --inplace /var/ /mnt/backup/var
[...]
log/postgresql/postgresql-12-main.log
log/postgresql/postgresql-12-main.log.1
log/postgresql/postgresql-12-main.log.10.gz
log/postgresql/postgresql-12-main.log.2.gz
log/postgresql/postgresql-12-main.log.3.gz
log/postgresql/postgresql-12-main.log.4.gz
log/postgresql/postgresql-12-main.log.5.gz
log/postgresql/postgresql-12-main.log.6.gz
log/postgresql/postgresql-12-main.log.7.gz
log/postgresql/postgresql-12-main.log.8.gz
log/postgresql/postgresql-12-main.log.9.gz
spool/anacron/cron.daily
tmp/
tmp/systemd-private-3bbae922a969453097f3c87f9cfcc52d-fwupd.service-iiu3gi/
tmp/systemd-private-3bbae922a969453097f3c87f9cfcc52d-fwupd.service-iiu3gi/tmp/
rsync: open "/mnt/backup/var/log/postgresql/postgresql-12-main.log" failed: Permission denied (13)
rsync: open "/mnt/backup/var/log/postgresql/postgresql-12-main.log.1" failed: Permission denied (13)
rsync: open "/mnt/backup/var/log/postgresql/postgresql-12-main.log.10.gz" failed: Permission denied (13)
rsync: open "/mnt/backup/var/log/postgresql/postgresql-12-main.log.2.gz" failed: Permission denied (13)
rsync: open "/mnt/backup/var/log/postgresql/postgresql-12-main.log.3.gz" failed: Permission denied (13)
rsync: open "/mnt/backup/var/log/postgresql/postgresql-12-main.log.4.gz" failed: Permission denied (13)
rsync: open "/mnt/backup/var/log/postgresql/postgresql-12-main.log.5.gz" failed: Permission denied (13)
rsync: open "/mnt/backup/var/log/postgresql/postgresql-12-main.log.6.gz" failed: Permission denied (13)
rsync: open "/mnt/backup/var/log/postgresql/postgresql-12-main.log.7.gz" failed: Permission denied (13)
rsync: open "/mnt/backup/var/log/postgresql/postgresql-12-main.log.8.gz" failed: Permission denied (13)
rsync: open "/mnt/backup/var/log/postgresql/postgresql-12-main.log.9.gz" failed: Permission denied (13)
sent 568,313,680 bytes received 11,776 bytes 32,475,740.34 bytes/sec
total size is 9,562,808,631 speedup is 16.83
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1207) [sender=3.1.3]
As said, I'm running this as root and the destination filesystem is mounted rw. See these mount
outputs:
/dev/mapper/ubuntu--vg-root on / type ext4 (rw,relatime,errors=remount-ro)
/dev/mapper/backup-backup on /mnt/backup type ext4 (rw,nosuid,nodev,noexec,relatime,user)
Notice that rsync
only complains about file permissions in the destination directory. Also, I only observe these errors, if some of the files have been changed in the source directory. If the files are missing in the destination directory, rsync
copies them just fine. If the files have not changed since previous run, rsync
detects that successfully and omits them from copying. It does not emit errors or warnings in either of these situations.
I'm not experiencing much trouble with other files that the above rsync
command processes. Everything looks just fine for these.
One thing that I notice though, is that the parent directory of the failing files has its sticky flag set:
$ sudo ls -la /mnt/backup/var/log/postgresql/
total 48
drwxrwxr-t 2 root postgres 4096 Mar 6 00:00 .
drwxrwxr-x 17 root syslog 4096 Mar 6 00:00 ..
-rw-r----- 1 postgres adm 0 Mar 6 00:00 postgresql-12-main.log
-rw-r----- 1 postgres adm 1873 Mar 6 00:00 postgresql-12-main.log.1
-rw-r----- 1 postgres adm 437 Dec 12 09:37 postgresql-12-main.log.10.gz
-rw-r----- 1 postgres adm 701 Feb 27 00:00 postgresql-12-main.log.2.gz
-rw-r----- 1 postgres adm 436 Feb 20 00:00 postgresql-12-main.log.3.gz
-rw-r----- 1 postgres adm 435 Feb 13 00:00 postgresql-12-main.log.4.gz
-rw-r----- 1 postgres adm 535 Feb 6 00:00 postgresql-12-main.log.5.gz
-rw-r----- 1 postgres adm 720 Jan 30 00:00 postgresql-12-main.log.6.gz
-rw-r----- 1 postgres adm 453 Jan 23 00:00 postgresql-12-main.log.7.gz
-rw-r----- 1 postgres adm 453 Jan 13 10:49 postgresql-12-main.log.8.gz
-rw-r----- 1 postgres adm 441 Jan 5 22:00 postgresql-12-main.log.9.gz
But so do some other directories that I throw at rsync
and those do not cause any errors. Needless to say that I can use other CLI tools to manipulate the above files without any trouble as long as I do it as root.
I get the feeling that I must be missing something really obvious. Can anyone tell me what is going on here? And maybe propose some rsync flags or mount options that could fix this?
Finally, here is some version info:
rsync version 3.1.3 protocol version 31
Ubuntu 20.04.4 LTS
Update:
Outputs of sysctl fs
:
$ sudo sysctl fs | grep fs.protect
fs.protected_fifos = 1
fs.protected_hardlinks = 1
fs.protected_regular = 2
fs.protected_symlinks = 1
rsync
run, or tweak the file privileges. But I'd really like to know what's going on here and learn to avoid similar problems in the future.sudo sysctl fs | grep fs.protect
? What user ID and which groups is your rsync running as? (You said root, your$
shell prompt seems to imply otherwise.)sysctl fs
outputs