5.9.5. Archiving Files with star
5.9.5. Archiving Files with star The star utility does not retain extended attributes by default. Since SELinux contexts are stored in extended attributes, contexts can be lost when archiving files. Use the star -xattr -H=exustar command to create archives that retain contexts. The star package is not installed by default. To install star , run the yum install star command as the Linux root user. The following example demonstrates creating a Star archive that retains SELinux contexts: As the Linux root user, run the touch /var/www/html/file{1,2,3} command to create three files ( file1 , file2 , and file3 ). These files inherit the httpd_sys_content_t type from the /var/www/html/ directory: Run the cd /var/www/html/ command to change into the /var/www/html/ directory. Once in this directory, as the Linux root user, run the star -xattr -H=exustar -c -f=test.star file{1,2,3} command to create a Star archive named test.star : As the Linux root user, run the mkdir /test command to create a new directory, and then, run the chmod 777 /test/ command to allow all users full-access to the /test/ directory. Run the cp /var/www/html/test.star /test/ command to copy the test.star file in to the /test/ directory. Run the cd /test/ command to change into the /test/ directory. Once in this directory, run the star -x -f=test.star command to extract the Star archive: Run the ls -lZ /test/ command to view the SELinux contexts. The httpd_sys_content_t type has been retained, rather than being changed to default_t , which would have happened had the -xattr -H=exustar option not been used: If the /test/ directory is no longer required, as the Linux root user, run the rm -ri /test/ command to remove it, as well as all files in it. If star is no longer required, as the Linux root user, run the yum remove star command to remove the package. Refer to the star (1) manual page for further information about star .
~]# touch /var/www/html/file{1,2,3} ~]# ls -Z /var/www/html/ -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file1 -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file2 -rw-r--r-- root root unconfined_u:object_r:httpd_sys_content_t:s0 file3 ~]# star -xattr -H=exustar -c -f=test.star file{1,2,3} star: 1 blocks + 0 bytes (total of 10240 bytes = 10.00k). ~]USD star -x -f=test.star star: 1 blocks + 0 bytes (total of 10240 bytes = 10.00k). ~]USD ls -lZ /test/ -rw-r--r-- user1 group1 unconfined_u:object_r:httpd_sys_content_t:s0 file1 -rw-r--r-- user1 group1 unconfined_u:object_r:httpd_sys_content_t:s0 file2 -rw-r--r-- user1 group1 unconfined_u:object_r:httpd_sys_content_t:s0 file3 -rw-r--r-- user1 group1 unconfined_u:object_r:default_t:s0 test.star