Copying files without losing selinux context

Rejy M Cyriac rcyriac at redhat.com
Sat Oct 10 07:01:59 UTC 2015


On 10/08/2015 06:35 PM, Suvayu Ali wrote:
> Hi,
> 
> Yesterday I installed a new SSD in my laptop.  I moved all my files
> (/home, /var, /opt) with rsync and rebooted.  However I see the selinux
> filecontexts are wrong, and many services are failing because of that,
> e.g. the user crontab doesn't load.
> 
>   # ls -Z /var/spool/cron/user
>   unconfined_u:object_r:var_spool_t:s0 /var/spool/cron/user
> 
> I did an autorelabel on boot, I also ran `restorecon -p -r /var',
> neither helped.  To get the crontab working, I had to change the context
> by hand.
> 
>   # chcon --reference=/old/part/spool/cron/user /var/spool/cron/user
>   # ls -Z /var/spool/cron/user 
>   unconfined_u:object_r:user_cron_spool_t:s0 /var/spool/cron/user
> 
> I would like to know how I can fix the rest, and what I should have used
> to do the copy in the first place.  I guess `cp -c' would work, but then
> I wouldn't have the ability to resume the transfer.
> 
> Thanks for any help.
> 
> Cheers,
> 

The following would have retained the SELinux contexts

rsync with the --xattrs option
tar with the --selinux or --xattrs option

rsync supports resume , and remote transfers over ssh

tar supports appending to as well as updating an existing archive, and
remote transfers over ssh

-- 
Regards,

Rejy M Cyriac (rmc)


More information about the users mailing list