HANDS-ON TASK · 1 OF 1

S3 backup tool

Project: S3 backup tool

You're an SRE at esc bash. A batch job drops files into a directory on each host and someone is supposed to copy them off to object storage every night. Nobody remembers to. Build a small tool that provisions a backup bucket and ships every file in that directory up to S3 in one run, the kind of thing you would wire into a cron job.

Set up the project

Run this first. It seeds the directory of files to back up:

bash
curl -fsSL https://raw.githubusercontent.com/Esc-Bash/project-init-scripts/main/python-for-devops/project-3/init.sh | bash

This creates /root/mission/backup/ with three files in it: config.yaml, notes.txt, and servers.csv.

This environment has no live AWS behind boto3. Just like the boto3 topic, your code runs against moto, a stand in that answers boto3's calls locally. You write ordinary boto3 code and the grader runs it against the mock, so you do not need real credentials and you should not point boto3 at a custom endpoint.

What to build

Write /root/scripts/s3backup.py. When run, it must use boto3 to:

  • Create an S3 client in the us-east-1 region.
  • Create a bucket named esc-bash-backups.
  • Upload every file in /root/mission/backup/ into that bucket, using each file's name as the object key (so config.yaml becomes the key config.yaml, and so on).
  • Write a JSON report to /root/answers/backup-report.json with this exact shape:
{
  "bucket": "esc-bash-backups",
  "uploaded": ["config.yaml", "notes.txt", "servers.csv"],
  "count": 3
}

When you press Submit, the grader runs your script against a mocked AWS and then checks that the bucket, the objects, and the report all came out right.

Press Submit when done.

Start the lab on the right to run checks.

Pass the checks to continue
Spin up a fresh environment and practice live.
python-devops · fresh machine · ready in under a minute