此内容没有您所选择的语言版本。
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, andfile3). These files inherit thehttpd_sys_content_ttype from the/var/www/html/directory:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 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 thestar -xattr -H=exustar -c -f=test.star file{1,2,3}command to create a Star archive namedtest.star:star -xattr -H=exustar -c -f=test.star file{1,2,3}~]# star -xattr -H=exustar -c -f=test.star file{1,2,3} star: 1 blocks + 0 bytes (total of 10240 bytes = 10.00k).Copy to Clipboard Copied! Toggle word wrap Toggle overflow - As the Linux root user, run the
mkdir /testcommand to create a new directory, and then, run thechmod 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 thetest.starfile in to the/test/directory. - Run the
cd /test/command to change into the/test/directory. Once in this directory, run thestar -x -f=test.starcommand to extract the Star archive:star -x -f=test.star
~]$ star -x -f=test.star star: 1 blocks + 0 bytes (total of 10240 bytes = 10.00k).Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Run the
ls -lZ /test/command to view the SELinux contexts. Thehttpd_sys_content_ttype has been retained, rather than being changed todefault_t, which would have happened had the-xattr -H=exustaroption not been used:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - If the
/test/directory is no longer required, as the Linux root user, run therm -ri /test/command to remove it, as well as all files in it. - If
staris no longer required, as the Linux root user, run theyum remove starcommand to remove the package.
Refer to the star(1) manual page for further information about
star.