Centos – Diagnosing rsync error output

centosrsyncselinux

I have inherited a Centos 6.5 system which is outputting multiple lines of errors when running an rsync. The rsync is syncing to a locally attached drive mounted as /storage. The command is:

rsync -aAXv /* /storage/backup/ --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/storage/*}

There are three different types of errors noted following # Error concern 1, # Error concern 2, # Error concern 3 in the output below:

rsync -aAXv /* /storage/backup/ --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/storage/*}
sending incremental file list
etc/cron.d/
root/
root/.bash_history
root/.viminfo
selinux/booleans/abrt_anon_write
selinux/booleans/abrt_handle_event
selinux/booleans/allow_console_login

[...]

# Error concern 1: There are probably 80 or more of these mkstemp errors, but I've shortened it:

rsync: mkstemp "/storage/backup/selinux/class/x_pointer/perms/.setfocus.0C5BYW" failed: Permission denied (13)
rsync: mkstemp "/storage/backup/selinux/class/x_pointer/perms/.use.iRMquA" failed: Permission denied (13)
rsync: mkstemp "/storage/backup/selinux/class/x_pointer/perms/.write.rHXg0d" failed: Permission denied (13)
rsync: mkstemp "/storage/backup/selinux/class/x_property/.index.Zwc8vR" failed: Permission denied (13)
rsync: mkstemp "/storage/backup/selinux/class/x_property/perms/.append.tTK01u" failed: Permission denied (13)
rsync: mkstemp "/storage/backup/selinux/class/x_property/perms/.create.KGNUx8" failed: Permission denied (13)
rsync: mkstemp "/storage/backup/selinux/class/x_property/perms/.destroy.IiUP3L" failed: Permission denied (13)

[...]

# Error concern 2:

tmp/
rsync: rsync_xal_clear: lremovexattr("storage","security.selinux") failed: Permission denied (13)
var/cache/man/whatis    

[...]

# Error concern 3:

var/run/utmp
rsync: set_acl: sys_acl_set_file(var/run/cups/certs/0, ACL_TYPE_ACCESS): Operation not supported (95)
var/run/postgresql/.s.PGSQL.5432.lock

[...]

# Finishing output:

sent 4288406721 bytes  received 52199 bytes  86635533.74 bytes/sec
total size is 22337384552  speedup is 5.21
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1039) [sender=3.0.6]

Notes

The rsync seems to run normally until it hits a particular part of /selinux directory with hidden files. When SELinux is set to permissive, setenforce 0, these errors do not occur. Although # Error concern 2 and # Error concern 3 still occur.

The SELinux context of the /selinux directory and /storage directories is as follows:

drwxr-xr-x. root root system_u:object_r:security_t:s0  selinux
drwxr-xr-x. root root system_u:object_r:file_t:s0      storage
# /storage/backup directory
drwxr-xr-x. root root unconfined_u:object_r:public_content_t:s0 backup

So far for # Error concern 2 and # Error concern 3 I have no leads.

Please let me know if I'm missing anything. I am not as well acquainted with CentOS 6.5 as I am with 7 as I'm not aware why there is a /selinux directory off of /. I have a CentOS 7.2 server which is doing the same rsync to an attached storage drive without issues. Any help or suggestions would be greatly appreciated.

Update 1

I changed the SELinux context on /storage/backup to public_content_rw_t via:

semanage fcontext -a -t public_content_rw_t "/storage/backup(/.*)?"
restorecon -Rv /storage/backup

I'll run the rsync again soon and report if this has changed anything.

Update 2

I've ran the rsync again after with the new security context and I'm getting the same error results. I'm wondering if rsyncing the /selinux directory is really worth it since the system should have /etc/selinux backed up anyway which would have all of the contexts if the system needed to relabel itself. Can anyone chime in on this?

Update 3

I'm leaning on not backing up the /selinux directory. The sestatus shows these differences between CentOS 6.5 and CentOS 7.2:

CentOS 6.5
SELinux status:                    enabled
SELinuxfs mount:                   /selinux
Current mode:                      enforcing

CentOS 7.2
SELinux status:                    enabled
SELinuxfs mount:                   /sys/fs/selinux
SELinux root directory:            /etc/selinux
Loaded policy name:                targeted
Current mode:                      enforcing

From what I gather from this the /selinux directory is being used as a mounting point for the SElinux filesystem? I wonder if this is the cause of the errors.

Best Answer

The difference between /selinux and /etc/selinux (in RHEL/CentOS 6) is that the former is a "pseudo flesystem for exporting the security policy API" (remember that Mandatory Access Control is kernel-enforced); whereas the latter "contains configuration files which are local to the machine".

You should not include the /selinux (or any other) pseudo filesystem when syncing.

There's a good Q/A on Unix & Linux about this subject, with very useful linked documentation.