Making good backups
No defence stops every attack, so resilient organisations plan to recover. A backup is a separate copy of data you can restore from. Our example: a small shop keeps orders.csv on its server, with a network drive (NAS) and an offline vault.
A classic rule from US-CERT, now part of CISA: keep 3 copies of important data (1 primary, 2 backups), on 2 different media types, with 1 copy off-site. Here: the server, the NAS, and a vault drive kept elsewhere.
Lines 2 to 5 define sha(): read a file's bytes and return its SHA-256 digest, a fingerprint that changes if any byte changes. Line 6 saves the fingerprint of orders.csv before the backup: 6d2443d8…
Line 7 makes the vault folder; line 8 copies the file into it. The NAS gets a copy over the network too. Then the vault is unplugged: an offline copy has no connection, so nothing on the network can reach it.
Two targets from NIST SP 800-34. Recovery point objective (RPO): the point in time data must be recovered to. Recovery time objective (RTO): how long recovery may take. Backing up nightly means up to 24 hours of changes can be lost.
Ransomware strikes
Ransomware is malicious software that encrypts files and demands payment to unlock them. At 14:00 it lands on the server, often through a stolen password or an unpatched flaw. orders.csv is now unreadable.
CISA warns that many ransomware variants find and delete or encrypt any backups they can reach. The NAS is always connected, so its copy is locked too. The vault has no cable: there is no path to it.
Recovering
First, contain it. CISA's checklist says to work out which systems are affected and isolate them at once, for example by unplugging them from the network. Then wipe and rebuild the server from clean software before restoring any data.
Line 9 marks the incident. Line 10 copies the clean file from the vault back onto the rebuilt server. CISA advises restoring from offline backups, most critical services first. Orders after 02:00 are lost: the RPO in action.
Line 11 hashes the restored file and compares it with the fingerprint saved at backup time. Equal digests print True: the bytes are exactly what was saved. NIST CSF 2.0 asks for this check (RC.RP-03) before restored data is trusted.
A backup is only proven by a restore. CISA says to test backups regularly, and NIST CSF 2.0 says backups are created, protected, maintained and tested (PR.DS-11). Time each practice restore: 3 hours here, within the 8-hour RTO.
What happens
;; step 1/11 · resilience
resilience keep working, and recover when
something gets through
backup a separate copy you can restore from
server orders.csv (the primary copy)
NAS network drive, always connected
vault a drive kept offline and off-site
The times are one worked example, not a standard: a nightly backup at 02:00, an attack at 14:00, an RTO of 8 hours and a 3-hour drill. Real targets come from how much loss and downtime each business process can bear. The program runs as is with Python 3 next to a file called orders.csv. Real backup tools add schedules, many versions, encryption and logs; the idea is the same.