RHCSA Practical Lab Series – Creating and Compressing Archives

Expertise in Cloud, Networking & DevOps
Photo by Blake Wisz / Unsplash

πŸ” 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:

  • bzip2 is a high-compression tool used to compress tar archives efficiently.
  • The -y flag 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_restore directory

πŸ”Ή 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! πŸš€


Read more