A server that nobody looks after fails. Back up what matters with tar to a separate disk, schedule the job with cron, watch the disk space, and test the restore: a backup you have never restored is only a hope.
System admin on a Raspberry Pi · Keep it running · about 40 minutes · Open the student lesson
Classroom resources
Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
WorksheetOpen in PrintDownload Print the student copy; the Teacher edition has the answers.
Students will be able to
I can back up a folder with tar and list or restore it.
I can read and write a cron schedule.
I can say why a backup must be on a different disk and be tested.
Timing
Predict and Try 8 min · Worked example 10 min · Vary 10 min · Practise and Make 12 min
Before class
Try the boards yourselves.
The one idea: running a system means planning for failure: a copy on a different disk, a schedule that runs without you, and a restore you have tested. This is the overall picture of securing a system (AC9TDI10K01 node 5): backups, firewall, accounts and updates each cover a different risk.
Simplifications: tar paths are shown as typed; the pretend /media/usb is a USB drive. crontab -e opens an editor on a real Pi (nano); the board refuses it and takes echo "..." | crontab -, which replaces your whole schedule. Disk sizes are made up.
Other options: rsync copies only what changed and suits big folders; rsnapshot and borg keep many versions.
With internet: off-site backups (rclone to cloud storage, or another Pi at home) protect against fire and theft; automatic security updates (unattended-upgrades) keep the Pi patched; monitoring can email you when the disk is nearly full.
Running the lesson
Predict: wrong answers read the fields as 'every 30 minutes'.
Try: ask what would be lost if the card failed now.
Worked example: stop at the untested backup and ask how you would know.
Vary: after the restore, ask how often it should be tested.
Make: ask what the 3-2-1 rule is (three copies, two kinds of media, one off-site).
In class
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
Think, pair, share(start) The computer breaks tonight. What would you wish you had done last week?
What would you lose?
How would you know the copy works?
A copy somewhere else, made automatically, and tested.
Cron cards(predict, 5 min)
Five cards in a row: minute, hour, day, month, weekday. Give a schedule in words and the class builds the line.
Order matters: minute comes first.
Fields(investigate) In 30 2 * * *, what is 30? The minute The first field is the minute.
The hard part (on purpose)
The five cron fields. Write them above the line: minute hour day month weekday.
When students get stuck
What you will see
A question to ask
The fix
A cron line does not run when expected.
Which field is the minute? The hour?
Minute, hour, day, month, weekday, in that order.
tar says it cannot find the folder.
Where are you? Does the path start from there?
cd to the parent, or give the whole path.
Answers to the checks
the schedule: A cron line starts 30 2 * * *. When does it run? At 02:30 every day. The fields are minute, hour, day of month, month, day of week; a star means every.
Try: make a backup: Back up the Documents folder into /media/usb/docs.tar.gz with tar -czf. Check it is there with ls -l /media/usb.
tar -czf /media/usb/docs.tar.gz Documents: c create, z compress, f file name.
Backup, schedule, restore: What does 0 3 * * 0 mean? At 03:00 on Sundays Minute 0, hour 3, any day, any month, weekday 0 (Sunday).
Find the mistake: Sam schedules a backup. Click the line where it first goes wrong. line 2 Line 2: 15 in the minute field means at minute 15 of every hour, once an hour. Every 15 minutes is */15 * * * *.
A backup you never tested: You have made a backup every night for a year, and never opened one. What do you really know? Nothing about whether it restores A backup is only proved by restoring from it. Test it, and keep one copy somewhere else.
Schedule it: Schedule a backup at 02:30 every day. Use echo "30 2 * * * tar -czf /media/usb/docs.tar.gz Documents" | crontab -
echo "30 2 * * * ..." | crontab - loads one line as your schedule. crontab -l shows it.
Restore: Documents/readme.txt was deleted by mistake. Restore it from the backup in /media/usb.
tar -xzf /media/usb/docs.tar.gz, from your home folder: it unpacks Documents again.
Watch the space: Find the free space on the Pi with df -h, then see which folder is biggest with du -h.
df shows each disk's space; du shows what a folder takes.
04:15: Which cron line runs at 04:15 every day? 15 4 * * * Minute first, then hour: 15 4.
Where: Where should the backup of the Pi's files be kept? On a different disk, ideally in another place A copy on the failing disk is not a backup.
Review: firewall: Review: the firewall is on and port 8096 is not allowed. Can a TV reach Jellyfin? No Blocked until allowed.
a nightly backup: Back up Documents to /media/usb/backup.tar.gz and schedule the same backup for 02:30 every night.
Make the archive, then load the cron line that makes it again each night. Then restore from it once, to be sure.
Solutions
One possible solution for each task. Other correct programs are fine.
Vary: change one thing › Schedule it
Open task: any program that does what the step asks.
Vary: change one thing › Restore
Open task: any program that does what the step asks.
Vary: change one thing › Watch the space
Open task: any program that does what the step asks.
a nightly backup
Open task: any program that does what the step asks.
Stretch and support
Stretch: Find out what the 3-2-1 backup rule says.
Support: The five fields written above a cron line.
Exit ticket
What are two reasons a backup might fail you?
It is on the same disk; it has never been tested.
What each step is for
the schedule: Committing to what the five fields mean tests the new move: the order is minute, hour, day, month, weekday.
Try: make a backup: Making an archive settles what a backup is.
Worked example: Backup, schedule, restore: Following the method once, then finding where a plausible account goes wrong, models the new move.
Vary: change one thing: Each task changes one thing: schedule it, restore from it, and find what is using the space.
Practise: Reading schedules and choosing habits without the board is the same move in new forms, plus a review of firewalls.
a nightly backup: Backup, schedule and proof together are the whole move.
Where it leads
Links: Cyber safety and privacy › Threat models; Security and privacy; next: The class server.