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.
The Pi's SD card dies on a Friday. What did you lose?
What you should already know:
Public and private keys· To send a secret to someone you've never met, you can't share a key first: anyone could copy it on the way.
Keeping a system running is half the job. Three habits cover most of it: a backup on a different disk, a schedule so it happens without you, and a test that you can get the files back. Each one protects against a different failure, and none replaces the others.
How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
Predict: Read the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
Try: Try it on the board and compare the result with your prediction.
Investigate: Work out why it happens, one step at a time.
Modify: Change the problem on purpose and see what happens.
Practise: A few on your own, to check you have it.
Make: Make your own problem using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
The schedule
TryTry it on the board and compare the result with your prediction.
Try: make a backup
Was your prediction right?
Try it yourselfYour edits are saved in this browser.
Back up the Documents folder into /media/usb/docs.tar.gz with tar -czf. Check it is there with ls -l /media/usb.
Use the board. This ticks when you get there.
InvestigateWork out why it happens, one step at a time.
Worked example: Backup, schedule, restore
Worked exampleBefore each step, say what you think comes next.
tar -czf /media/usb/docs.tar.gz Documentsmake a compressed copy of a folder.
echo "30 2 * * * tar -czf ..." | crontab -run it at 02:30 every day.
tar -tzf docs.tar.gzlist what is inside, without changing anything.
tar -xzf docs.tar.gzrestore: unpack it into the current folder.
Now try it yourself.
Sam schedules a backup. Click the line where it first goes wrong.
ModifyChange the problem on purpose and see what happens.
Vary: change one thing
Try it yourselfYour edits are saved in this browser.
Schedule a backup at 02:30 every day. Use echo "30 2 * * * tar -czf /media/usb/docs.tar.gz Documents" | crontab -
Use the board. This ticks when you get there.
Documents/readme.txt was deleted by mistake. Restore it from the backup in /media/usb.
Use the board. This ticks when you get there.
Find the free space on the Pi with df -h, then see which folder is biggest with du -h.
Use the board. This ticks when you get there.
PractiseA few on your own, to check you have it.
Practise
MakeMake your own problem using what you have learned. Expect a few tries; that is normal.
A nightly backup
Then: on a real Pi, look at /var/log/syslog and try df -h on the real disk.
Try it yourselfYour edits are saved in this browser.
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. About 40 minutes.
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.
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).
The hard part (on purpose)
The five cron fields. Write them above the line: minute hour day month weekday.
When students get stuck
A cron line does not run when expected. Ask: Which field is the minute? The hour? Fix: Minute, hour, day, month, weekday, in that order.
tar says it cannot find the folder. Ask: Where are you? Does the path start from there? Fix: cd to the parent, or give the whole path.
Stretch and support
Stretch: Find out what the 3-2-1 backup rule says.
Support: The five fields written above a cron line.
Where it leads
Links: Cyber safety and privacy › Threat models; Security and privacy; next: The class server.
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.