Skip to content

Getting a deleted Minecraft world back off the disk

Published: at 12:00 AM

There is no recycle bin for a folder deleted over SFTP. There is the raw disk, and the game’s own file format.

I deleted a world by accident through a file manager, on a machine I use for game servers. The world was the one I had been playing on, and the folder was gone before I thought about it. The disk does not care that it was an accident.

Undelete on most filesystems is its own research project, so I did not try to recover files. I went after the format instead. A world is a few folders, and each file in them is a container of fixed size sectors with a small header that indexes the chunks inside.

  world/
    region/     blocks, chests, every edit
    entities/   frames, villagers, animals
    poi/        beds and workstations

  one region file:
    [ header, 1024 offsets ]
    [ chunk | chunk | chunk | ... ]

Each chunk is compressed. So if you can find valid headers and decompress what they point at, you can rebuild the world without the filesystem’s help and without knowing the file’s name.

There are three kinds of record and they are not interchangeable. Terrain is blocks, chests, and every edit anyone made. Entities is item frames, armor stands, villagers, animals, minecarts. Points of interest is the link between a villager and its bed or workstation, which is the difference between a village that works and a village where nobody ever sleeps.

  raw disk
     |  scan for record headers
     v
  index of candidates
     |  rebuild and decompress
     v
  chunks, verified two ways:
     region filename + header index

The verification was the interesting part. Comparing recovered chunks against the corrupted originals would let a bug pass by agreeing with itself, so coordinates were checked two ways that do not depend on my own code: against the region file’s own filename, and against the header index. That is how I know 2,398 terrain chunks, 130 entity chunks, and 21 points of interest chunks came back byte identical, instead of assuming they did.

Two things went wrong. The points of interest pass dropped every record and reported success with an empty result, because my classifier looked for a field that the real data does not have, so it fell through silently. Being wrong while returning zero errors is the worst way to be wrong, and it only showed up because the count looked too small to be true. The other is that resuming an interrupted scan saves nothing, because the write position is only flushed to disk every so often, so you restart from a stale offset and quietly rescan the part you already did.

It worked, and the result is smaller than the numbers suggest. Of the base itself, less than a quarter of a chunk’s worth came back. The tower at the end of this post is that fragment, standing on its column.

That is the honest shape of this kind of tool. It recovers whatever is still on the disk, and it cannot tell you how much that is until it has finished. Someone who reads “recovered 2,398 chunks” will assume their build is in there. Mine mostly was not.

What came back is enough to prove the format work was right, and not enough to get the base back. The rest of that evening went into accepting that, and into setting up backups so there is no second evening.

Screenshots

The part of the base that came back.