RHCSA Practical Lab Series β Creating and Compressing Archives
π Lab 12: Archiving and Compressing Files with tar and bzip2
π Objective
In this lab, you will:
β Create a compressed tar archive (/root/system_backup.tar.bz2)
β Archive the entire /etc directory
β Use bzip2 compression to reduce file size
β Verify the archive integrity
π Step 1: Install bzip2 (if not already installed)
πΉ Ensure the bzip2 package is installed:
[root@node1 ~]# yum -y install bzip2
π Explanation:
bzip2is a high-compression tool used to compress tar archives efficiently.- The
-yflag automatically confirms installation.
β Once installed, proceed to Step 2.
π Step 2: Create a Compressed Archive of /etc
πΉ Use tar to archive and compress /etc:
[root@node1 ~]# tar -cvjf /root/system_backup.tar.bz2 /etc
π Explanation:
tarβ The archiving command-cβ Creates a new archive-vβ Displays verbose output (lists files being added)-jβ Uses bzip2 compression-f /root/system_backup.tar.bz2β Specifies the archive filename/etcβ The directory being archived
β
If successful, system_backup.tar.bz2 will be created in /root/.
π Step 3: Verify the Archive Integrity
πΉ Check the file type to confirm it is a compressed tar.bz2 archive:
[root@node1 ~]# file /root/system_backup.tar.bz2
π Expected Output:
/root/system_backup.tar.bz2: bzip2 compressed data, block size = 900k
β If this output appears, the archive is correctly compressed.
πΉ List the contents of the archive without extracting:
[root@node1 ~]# tar -tvjf /root/system_backup.tar.bz2
π This allows you to verify that /etc was properly archived.
π Step 4: Extract and Verify the Backup (Optional)
πΉ Extract the archive to /tmp/test_restore for verification:
[root@node1 ~]# mkdir /tmp/test_restore
[root@node1 ~]# tar -xvjf /root/system_backup.tar.bz2 -C /tmp/test_restore
π Explanation:
-xβ Extracts the archive-C /tmp/test_restoreβ Extracts files into the/tmp/test_restoredirectory
πΉ Verify extracted files:
[root@node1 ~]# ls /tmp/test_restore/etc
β
If the contents match the original /etc, the backup was successful!
β Final Summary
β Installed bzip2 for high-compression archiving
β Created a compressed tar archive (.tar.bz2) of /etc
β Verified the archive integrity and contents
β (Optional) Extracted and confirmed the backup files
π Next Lab: Creating a Custom Container Image
π© Subscribe for more RHCSA exam labs and hands-on tutorials! π