AWS re/Start Lab · Linux

Working with Files

Create a compressed backup of a folder structure using tar, log the backup with a timestamp, and transfer the backup file to another directory.

Lab Summary

Connected via PuTTY (as described in Lab 225). Created a compressed backup of the CompanyA folder using tar, logged the backup date and file name to a backups.csv file using echo and tee, and transferred the archive to the IA folder.

Backup

Used tar -csvpzf to create a compressed archive of the entire CompanyA folder structure.

Logging

Recorded the backup date, time, and file name in SharedFolders/backups.csv using echo and tee.

Transfer

Moved the backup file to the IA folder with mv, simulating a file transfer to another team.

Step-by-Step Walkthrough

Detailed record of each task performed during the lab.

01

SSH Connection

  • Connected to the EC2 instance via PuTTY following the process described in Lab 225.
02

Create a Backup

  • Verified the current directory with pwd: /home/ec2-user.
  • Confirmed the CompanyA folder structure with ls -R CompanyA, which showed six subdirectories (Employees, Finance, HR, IA, Management, SharedFolders) with their respective files.
  • Created a compressed backup with tar -csvpzf backup.CompanyA.tar.gz CompanyA.
  • Verified the backup was created with ls: backup.CompanyA.tar.gz appeared alongside CompanyA.
The tar flags: -c creates an archive, -s preserves file order, -v shows verbose output, -p preserves permissions, -z compresses with gzip, and -f specifies the output file name.
03

Log the Backup

  • Navigated to CompanyA with cd /home/ec2-user/CompanyA.
  • Created the log file with touch SharedFolders/backups.csv.
  • Wrote the backup record with echo "25 Aug 25 2021, 16:59, backup.CompanyA.tar.gz" | sudo tee SharedFolders/backups.csv.
  • Verified the log content with cat SharedFolders/backups.csv.
The tee command writes output to both the terminal and a file simultaneously. The | (pipe) redirects the output of echo into tee.
04

Move the Backup File

  • Confirmed location with pwd: /home/ec2-user/CompanyA.
  • Moved the backup to the IA folder with mv ../backup.CompanyA.tar.gz IA/.
  • Verified with ls . IA: the backup file was now in the IA directory and no longer in the parent folder.

Command Reference

Commands used in this lab for backups and file operations.

cmd

tar

Creates or extracts compressed archive files.

  • -c : Create a new archive
  • -v : Verbose output (list files being processed)
  • -p : Preserve file permissions
  • -z : Compress with gzip
  • -f : Specify the archive file name
cmd

echo

Prints text to the terminal or writes it to a file when combined with redirection.

cmd

tee

Reads from standard input and writes to both the terminal and a file simultaneously.

cmd

| (pipe)

Redirects the output of one command as the input of another. Example: echo "text" | tee file.csv

Key Learnings

What Was Learned

How to create compressed backups of entire folder structures using tar with gzip compression.
How to log backup operations with timestamps using echo and tee.
How to use the pipe (|) operator to chain commands together.
How to transfer backup files between directories with mv.

Technical Conclusion

This lab demonstrated the backup workflow in Linux: archiving data with tar, documenting the operation in a log file, and transferring the backup to a designated location.

In a production environment, these steps would typically be automated with scripts and scheduled using cron jobs. The logging step is important for tracking when backups were made and avoiding unnecessary duplicates.