AcademyThe Automator's Grimoire: Scripting WizardryCircle 5: Great Works (Automation)

Practical Automation

Let's put your new skills to the test by writing a script that creates compressed backups of directories.

The tar Command

tar (Tape Archive) is the standard tool for combining files into a single archive, often compressed with gzip.

# Create a gzip compressed archive
tar -czvf backup.tar.gz /path/to/directory

The Goal

Your script should:

  1. Accept a directory path as the first argument ($1).
  2. Check if that directory exists using an if statement.
  3. If it doesn't exist, echo an error and exit 1.
  4. If it does exist, create a tar.gz archive of it in the /tmp directory.
  5. Use $(date +%Y%m%d) to add the current date to the backup filename.

Give it a try!

booting...

Mission Control

Write backup.sh

Expected Command

cat backup.sh

Test the script