Lion Cipher Lab

Automate encrypted backups with cron and restic

Why it matters

The restic lab gave you encrypted, versioned backups -- but only when you remembered to type the command. That is the quiet failure mode of every hand-run backup: the week you are busiest, or sick, or travelling, is the week you skip it, and that is exactly when a laptop gets stolen or a drive dies. A backup you have to remember is a backup you will eventually forget. Automating it with cron removes the one unreliable part of the system: you. But automation swaps one risk for a sneakier one. When a human ran the backup, a human saw it fail. Hand the job to a scheduler and, unless you build in…

What you'll learn

Steps in this lab

  1. Why automate -- the backup you have to remember is the one you forget
  2. The words you need: cron, crontab, script, exit code, prune
  3. Store the repository password safely -- in a locked file, never in the script
  4. Write the backup script -- backup, then forget --prune
  5. Add logging and a success/failure check
  6. Schedule it with cron
  7. The part that matters most: test your restore and confirm it actually ran
  8. The system that runs itself -- and proves it

Open the full interactive lab →