[ norboten ]
bash · lab bash-02

The Cleanup That Kept the Wrong Releases

· about 35 minutes · runs on ubuntu-26.04-devops · unrated

An unrated lab. It runs on your machine with no account and no network, and everything about it — the faults, the checks, the hints and the reference solution — is in the repository. An attempt on it is recorded on your profile and never moves a rating: only rated labs do. Rated and unrated labs.

The briefing

The application keeps one directory per release in /srv/app/releases/, named after the moment it was built — 20260913-101500, sometimes with a label after a space, such as 20260911-180000 hotfix. current in the same directory is a symlink to the release in use.

prune-releases is supposed to keep the five newest releases and delete the rest, every night. This week it:

  • deleted Tuesday's release and kept one from last month, after someone restored old releases from a backup;
  • left 20260830-090000 rollback behind, and complained about files called rollback that do not exist;
  • and, on a machine where the releases directory had been moved, deleted the contents of the directory it was started from.

It has not run at all since the last reboot.

What is expected, and graded — the grader runs prune-releases itself, against its own directories, through the RELEASES_DIR variable the script already reads:

  1. The five releases with the newest names are kept, whatever their modification times; the others are deleted; current and anything that is not a release directory are left alone.
  2. Release names containing spaces are kept or deleted correctly.
  3. When RELEASES_DIR does not exist, the script exits non-zero and deletes nothing, wherever it was started from.
  4. It runs every night from its systemd timer, and the timer is still there after a reboot.

You have root through sudo.

What is graded

The machine is checked, rebooted, and checked again. A check passes only if it passes both times.

CheckObjective
01_keeps_the_five_newestSelect files by the data in their names, not by incidental metadata
02_names_with_spacesHandle every file name safely, spaces included, and never act in the wrong directory
03_missing_directory_deletes_nothingHandle every file name safely, spaces included, and never act in the wrong directory
04_runs_every_nightSchedule a maintenance script with a systemd timer that survives reboots

Start it

  1. 2Labs
  2. bash-02select this one
  3. udownload it
  4. sstart the machine

Reading

Where the lab's hints send you, level by level, as you ask for them (h, then l opens a journal section in the TUI).

Theory for this lab

4 questions on the same topic, in the lab's Theory tab. They never affect the lab's grade. Three of them, to answer here:

Question 1

What does this print?

cd "$(mktemp -d)"
mkdir "a b" b
echo "a b" | xargs printf '[%s]'; echo
Question 2

What does this print?

cd "$(mktemp -d)"
mkdir 20260102-0900 20260101-0900 "20260103-0900 hotfix"
for d in [0-9]*; do printf '%s|' "$d"; done; echo
Question 3

What does this print?

cd "$(mktemp -d)"
mkdir real && ln -s real link
[ -d link ] && echo dir; [ -L link ] && echo link