Linux Exercise 6 - Compression and Backup
Exercise: Archiving, Compressing, and Backing Up Files in UNIX/Linux
Objective
Learn how to:
- Create and extract archives using
tar
andcpio
. - Apply compression with
compress
,gzip
, and modern alternatives. - Combine commands for efficient backup workflows.
- Interpret the results and verify integrity.
Tasks
Task 1: Create a tar
Archive
- Archive the contents of your home directory (including subdirectories) into a single file.
- Expected outcome: A
.tar
file containing all files and directories from your home directory.
Task 2: Compress the tar
Archive
- Compress the archive you created using gzip.
- Compare the size of the compressed file with the original
.tar
file. - Expected outcome: A
.tar.gz
file that is smaller than the original archive.
Task 3: Create a cpio
Archive
- Use
find
andcpio
to 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
- Extract both the
tar
andcpio
archives 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
- Without extracting, list the contents of your
tar
archive. - Expected outcome: A detailed list of files and directories inside the archive.
Task 6: Use Modern Compression
- Create a
tar
archive of/etc
and compress it using bzip2 or xz. - Compare the size and compression time with the gzip-compressed archive.
- Expected outcome: A
.tar.bz2
or.tar.xz
file, likely smaller than the gzip version.
Task 7: Create a ZIP Archive
- Create a
.zip
archive of your home directory. - Compare its size and compression ratio with the
.tar.gz
archive. - Expected outcome: A
.zip
file and an observation about cross-platform compatibility.
Task 8: Incremental Backup Simulation
- Use
rsync
to copy your home directory to a backup location. - Modify a few files and run
rsync
again. - Expected outcome: Only changed files should be updated in the backup.
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)
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.