Nightly backups, shipped through a key that can only write
· 4-minute read · Engineering · by Direct Softworks
Our backups had stopped ten weeks before anyone noticed. The replacement ships every night through a key that can only write, and we have restored from it.

In September we found that the backups the hosting control panel was supposed to be taking on our main server had stopped on 15 July. They had not failed with an error. They had simply stopped, and nothing else on the machine dumped the database. For about ten weeks there was no backup at all.
Nobody had looked because there was nothing to look at. A backup that fails loudly gets fixed. A backup that quietly stops producing files looks exactly like a backup that is working, right up to the morning you need one.
The replacement went in on 22 September. This is what it does, and why each part is there.
What a backup has to survive
Three things can take your data, and a copy has to survive all of them to be worth keeping.
The disk dies. The provider loses the machine. Or someone with full access to the server, an attacker or one of us at a bad moment, deletes things. A copy on the same machine survives none of the three. A copy on another machine survives the first two, and a copy that the first machine can delete does not survive the third, because whoever controls the first machine controls it too.
So the requirement is another machine, and a connection to it that can add files and do nothing else.
The nightly job
At half past three every morning, local time, the main server dumps the database and archives the application's data directory. It keeps fourteen days of those locally. Then it sends both to a second server, one we run for a different system. That server does the same in reverse each evening, so each machine is the other's offsite copy.
The job then checks one more thing: that the other server's most recent dump has arrived here within the last 26 hours. A day plus a margin, so a job that runs a little late does not raise an alarm, and a job that has stopped does.
Any failure opens an issue in our repository automatically, using the same mechanism that files production errors. The failure mode we were recovering from was silence, so the replacement is built to be noisy.
The key that can only write
On the receiving side there is a dedicated account. The sending server's SSH key is in that account's authorized keys, with two options in front of it, something like this:
restrict,command="receive-backup web" ssh-ed25519 AAAA... nightly
Both are standard OpenSSH. restrict disables port forwarding, agent forwarding, X11 forwarding and terminal allocation. command= forces a single program to run whenever this key is used, and whatever command the client asked for is ignored; the sshd manual describes both. The only channel left is the session's input, so the backup is piped in and the receiving program writes it.
It writes it under a name it builds itself: which server sent it, whether it is a database dump or a files archive, and a UTC timestamp. It tests the file with gzip before keeping it, and it prunes anything older than thirty days. When we tested the key, listing files, reading one back and opening a port forward were all refused.
A compromised sender can add a bad backup. It cannot read, overwrite or delete a good one. The obvious remaining risk is a sender filling the disk with junk, which is a real limitation and a much smaller problem than losing the history.
The restore drill
A backup is a hypothesis until you have restored it. So on the day it went in, we restored both servers' databases from the copies on the opposite machine, into throwaway containers with no network access, so nothing in them could reach anything.
The main database came back in 24 seconds: 75 tables, and the row counts matched the live database. The other server's restored in 9 seconds with no errors. The restore itself is one line, a decompress piped into the database client, which is what you want from a command that will next be run by somebody who is having a bad day.
Those timings are worth more than they look. Knowing that a restore takes 24 seconds turns "we have backups" into a recovery time you can actually promise someone.
The wider point
The old backups did not break. They stopped, and the difference matters. Breaking produces an error. Stopping produces an absence, and an absence only gets noticed by something that expects a presence. That is why the new job checks that the other side's file arrived, not merely that its own upload succeeded.
It is why a proper handover asks for a tested restore and a named list of scheduled jobs rather than a dump and a promise: the jobs that run at night are the ones most likely to stop without anyone hearing it. If something important is supposed to happen every night, have something else confirm every morning that it did.