what should I know About The RHCSA Exam
RHCSA 8 Exam practice question 8
Create a backup file named “/root/backup.tar.bz2”. The backup file should contain the content of “/usr/local” and should be zipped with bzip2 compression format.
Furthermore, ensure SELinux is in enforcing mode. If it is not, change SELinux to enforcing mode.
The question is based On Archiving and Compressing files & Managing SELinux in the learn Linux from scratch series, and the RHCSA 8 course on this website. If you have gone through this course, solving this wouldn’t be a problem.
Learn Linux From Scratch Series
Archiving and Compressing Files In Linux
1. Change directory to “/usr/local” and list the contents in there
[root@DRDEV1 ~]# cd /usr/local/
[root@DRDEV1 local]# ls
bin etc games include lib lib64 libexec sbin share src
NOTE: you can use the manual page of bzip2 or use the command “bzip2 –help” the way it was done in the video below if you need help with bzip2
You can see that the contents in here are directories and not files. Hence, this question can be solved in two methods.
In the course of the study of this chapter “Archiving & compressing files” on this website, it was mentioned that you can either do one of these three things
1. Archive a file
2. Compress a file
3. Archive and compress a file
Method 1: Use the “tar” utility to archive the directory since the “bzip2” utility can’t compress a directory, then use the “bzip2” utility to compress the archived file.
Method 2: Use the tar utility straightaway to compress the directory to bzip2 format.
Method 1
1. use the tar utility to archive the directory
[root@DRDEV1 ~]# tar cfv backup.tar /usr/local
tar: Removing leading `/' from member names
/usr/local/
/usr/local/bin/
/usr/local/etc/
/usr/local/games/
.....................
2. verify the files in the root directory.
[root@DRDEV1 ~]# ls
anaconda-ks.cfg Documents initial-setup-ks.cfg Public Videos
backup.tar Downloads Music Templates
Desktop foo Pictures unzip
3. you can also verify the type of file it is
[root@DRDEV1 ~]# file backup.tar
backup.tar: POSIX tar archive (GNU)
4. use the bzip2 utility to compress the archived file
[root@DRDEV1 ~]# bzip2 backup.tar
[root@DRDEV1 ~]# ls
anaconda-ks.cfg Documents initial-setup-ks.cfg Public Videos
backup.tar.bz2 Downloads Music Templates
Desktop foo Pictures unzip
5. Verify the type of file it is
[root@DRDEV1 ~]# file backup.tar.bz2
backup.tar.bz2: bzip2 compressed data, block size = 900k
Method 2
1. Use the tar utility to archive and compress the file straightaway to bzip2 format
[root@DRDEV1]# tar cjfv backup.tar.bz2 /usr/local/
tar: Removing leading `/' from member names
/usr/local/
/usr/local/bin/
/usr/local/etc/
/usr/local/games/
........................
2. Verify the files in the root directory
[root@DRDEV1 ~]# ls
anaconda-ks.cfg Documents initial-setup-ks.cfg Public Videos
backup.tar.bz2 Downloads Music Templates
Desktop foo Pictures unzip
3. Verify the type of file it is
[root@DRDEV1 ~]# file backup.tar.bz2
backup.tar.bz2: bzip2 compressed data, block size = 900k
The second part of the question says, you should ensure SELinux is in the enforcing mode.
To verify, use the command,
[root@DRDEV1 ~]# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: actual (secure)
Max kernel policy version: 31
OR
[root@DRDEV1 ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
Parting Note: tar is a file archive utility that takes a number of files, directories, and puts them in a single file/location.
tar can also be used to compress and archive a file or directory. Other utilites that can be used to compress a file are zip, gzip, bzip2, xz, etc.
tar cfv backup.tar /usr/local
ls
file backup.tar
bzip2 backup.tar
file backup.tar.bz2
OR
tar cjfv backup.tar.bz2 /usr/local/
ls
file backup.tar.bz2
sestatus
cat /etc/selinux/config
You can also watch the Video on RHCSA 8 Exam Practice Question 8 by clicking the link below.
rhcsa 8 exam practice question 8
Your feedback is welcomed. If you love others, you will share with others
I would recommend changing the following:
The order of -[Options] should be,-cvf or -cjvf (Order matters to tar, for some reason).
You should `cd` into the target dir before performing the operation (tar prefers this).
The Archive should not contain absolute names unless explicitly asked (Extraction, otherwise, becomes
complicated).
Extracted to /usr/local/ from –absolute-names Archive: /usr/local/usr/local/[archive contents]
Extracted to /usr/local/ from relative path Archive: /usr/local[archive contents]
`cd /usr/local; tar -cjvf ./backup.tar.bz2 . ; mv ./backup.tar.bz2 ~; cd ~; ls backup.tar.bz2`