Linux Exercise 6 - Compression and Backup
Exercise: Archiving, Compressing, and Backing Up Files in UNIX/Linux
Section titled “Exercise: Archiving, Compressing, and Backing Up Files in UNIX/Linux”Objective
Section titled “Objective”Learn how to:
- Create and extract archives using
tarandcpio. - Apply compression with
compress,gzip, and modern alternatives. - Combine commands for efficient backup workflows.
- Interpret the results and verify integrity.
Task 1: Create a tar Archive
Section titled “Task 1: Create a tar Archive”- Archive the contents of your home directory (including subdirectories) into a single file.
- Expected outcome: A
.tarfile containing all files and directories from your home directory.
Task 2: Compress the tar Archive
Section titled “Task 2: Compress the tar Archive”- Compress the archive you created using gzip.
- Compare the size of the compressed file with the original
.tarfile. - Expected outcome: A
.tar.gzfile that is smaller than the original archive.
Task 3: Create a cpio Archive
Section titled “Task 3: Create a cpio Archive”- Use
findandcpioto create an archive of your home directory. - Compress this archive using compress or gzip.
- Expected outcome: A compressed archive file created with
cpio.
Task 4: Extract and Verify
Section titled “Task 4: Extract and Verify”- Extract both the
tarandcpioarchives into separate directories. - Verify that the extracted files match the original files (check file count and structure).
- Expected outcome: Two restored directories identical to the original.
Task 5: List Archive Contents
Section titled “Task 5: List Archive Contents”- Without extracting, list the contents of your
tararchive. - Expected outcome: A detailed list of files and directories inside the archive.
Task 6: Use Modern Compression
Section titled “Task 6: Use Modern Compression”- Create a
tararchive of/etcand compress it using bzip2 or xz. - Compare the size and compression time with the gzip-compressed archive.
- Expected outcome: A
.tar.bz2or.tar.xzfile, likely smaller than the gzip version.
Task 7: Create a ZIP Archive
Section titled “Task 7: Create a ZIP Archive”- Create a
.ziparchive of your home directory. - Compare its size and compression ratio with the
.tar.gzarchive. - Expected outcome: A
.zipfile and an observation about cross-platform compatibility.
Task 8: Incremental Backup Simulation
Section titled “Task 8: Incremental Backup Simulation”- Use
rsyncto copy your home directory to a backup location. - Modify a few files and run
rsyncagain. - Expected outcome: Only changed files should be updated in the backup.
Task 9: Best Practices Check
Section titled “Task 9: Best Practices Check”- After completing all tasks, reflect on:
- Which compression method gave the best ratio?
- Which tool was fastest?
- Which method is best for large backups?
📑 Protocol (What to Hand In)
Section titled “📑 Protocol (What to Hand In)”Each student must create a protocol (log) containing:
- Command executed
- Output received (full or partial if very long)
- Explanation (1–2 sentences) of what the command did
- Observation/interpretation of what they learned
Example:
Command: file sample.zipOutput: sample.zip: Zip archive data, at least v2.0 to extractExplanation: Identified sample.zip as a compressed archive file.Observation: Shows that zip files are binary and need archive tools to inspect contents.Command: sudo tail -f /var/log/syslogOutput: (live log output appears)Explanation: Monitors new log entries in real-time.Observation: Useful for watching system activity as it happens.