Preserving Context with tar

Daniel J Walsh dwalsh at redhat.com
Thu Oct 20 16:01:30 UTC 2005


Stephen Smalley wrote:
> On Wed, 2005-10-19 at 22:32 -0400, Daniel J Walsh wrote:
>   
>> W. Scott wilburn wrote:
>>     
>>> Sorry to be asking such a simple question. Is it possible to preserve 
>>> file contexts using tar? I would have thought -p would do this, but 
>>> it appears no, atleast on RHEL4 and FC4.
>>>
>>> The reason to do this is a use tar to install modified config files on 
>>> new machines. Having to relabel after doing this is somewhat slow. 
>>> Perhaps there is a better solution?
>>>
>>> Thanks,
>>>   
>>>       
>> Have you looked at star?
>>     
>
> Usage is:
> 	# create an archive including xattrs
> 	star -xattr -H=exustar -c -f foo.tar <list of files to archive>
> 	# extract the archive, preserving any xattrs in it
> 	star -x -f foo.tar
>
> rsync also has support for xattr preservation (-X, --xattrs), at least
> in FC4.
>
> An option for GNU tar might be to selectively apply restorecon to the
> files you are extracting if they are being extracted to the same path on
> the destination machine as on the source machine and both machines have
> the same policy, e.g.:
> 	tar xvf foo.tar | xargs /sbin/restorecon
>
>   
tar xvf foo.tar | /sbin/restorecon -f -

Would probably be better

-- 





More information about the fedora-selinux-list mailing list