Search code examples
windows-10minecraftwindows-subsystem-for-linuxleveldb

Minecraft Bedrock(WIN10) world corrupted because of missing db/MANIFEST file


I recently ran across a very specific problem that caused my Minecraft Bedrock worlds to be corrupted (whole chunks were literally missing from my worlds). It turns out that the issue was because I was using a backup that was created via 7zip using the command:

7z.exe a -r minecraftWorlds.7z %LOCALAPPDATA%\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang\minecraftWorlds\*.*

…which was not adding files WITHOUT an extension, specifically the MANIFEST files in the {worldID}/db directory.

I had to uninstall Minecraft for Windows 10, which deleted all resource packs and saved worlds, but I thought I was fine because I had a script that was making a daily backup. So I reinstalled Minecraft and restored my backup, then loaded my worlds, and like I said entire chunks were just missing from my worlds.

So I created a new world and compared its save-folder to the folders I restored, and that's when I noticed my worlds were missing the MANIFEST files in the /db subdirectory.

In my investigation, I found a lot of possible fixes for corrupted worlds, but they all had to do with corrupted level.dat files and nothing about missing files in the db directory.

None of the tools like MCCToolchest could even open the world data files, because of these missing MANIFEST files.

So was there anything to be done?


Solution

  • To start with, the correct command to backup your Minecraft Bedrock (Windows 10) worlds using 7-zip is:

    7z.exe a -r minecraftWorlds.7z %LOCALAPPDATA%\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang\minecraftWorlds\*
    

    …no ".*" at the very end. This will create a backup of all files stored in your minecraftWorlds directory.

    The more research I did, it would appear that the Minecraft world data is saved in a database format called leveldb. This is a key/value pairs based database that is loaded into memory and stored in a series of files in the {worldID}/db folder.

    The following was the way that I was able to recovery working MANIFEST files and restore my worlds!

    You'll need a POSIX OS. Since I didn't have one handy, I installed the "Windows-subsystem-for-linux" via the Ubuntu app that can be installed free from the Microsoft Store app.

    Once you've installed, configured, and start this app, you're basically taken to a bash command prompt.

    • First, install the build tools
    sudo apt-get install git cmake g++ libsnappy-dev
    
    sudo su
    git clone --recurse-submodules https://github.com/google/leveldb.git
    cd leveldb && mkdir -p build && cd build
    cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .
    cmake --install
    exit
    cd ~
    

    Once that builds successfully, you'll need to create the following c++ program using your favorite linux editor, saving the file as ldbrpr.cc:

    #include <cstdlib>
    #include <leveldb/db.h>
    
    int main(int argc,char *argv[])
    {
        if(argc==2)
        {
            leveldb::Options o;
            leveldb::Status s=leveldb::RepairDB(argv[1],o);
            return s.ok()?EXIT_SUCCESS:EXIT_FAILURE;
        }
        else return EXIT_FAILURE;
    }
    

    Once you save the file, you'll need to compile it.

    g++ -o ldbrpr ldbrpr.cc -L ~/leveldb/build -I ~/leveldb/include -lleveldb -lsnappy -lpthread
    

    After you execute this command you should find an executable file called: ldbrpr

    ls -las
    

    You now need to execute this program for the world-save folder that you're trying to restore. This is done with the following command:

    (replace {username} with your Windows username), and {worldsavefolder} with the name of world directory name you're trying to restore

    ./ldbrpr /mnt/c/Users/{username}/AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/minecraftWorlds/{worldsavefoldername}/db
    

    Now, this next part is crucial. Minecraft uses a proprietary version of leveldb, so it will appear to only restore one data file, and it will place all of the other data files into a subdirectory called lost.

    cd /mnt/c/Users/{username}/AppData/Local/Packages/Microsoft.MinecraftUWP_8wekyb3d8bbwe/LocalState/games/com.mojang/minecraftWorlds/{worldsavefoldername}/db
    mkdir old
    mv *.ldb old
    mv *.log old
    mv lost/*.ldb .
    mv lost/*.log .
    

    When you start Minecraft, if the world is still not visible then you may also have a corrupt DAT file.

    In Minecraft, create a new world (use all the options you originally used when creating the world you're trying to restore), then close Minecraft.

    Now, in Windows Explorer go to:

    %APPDATALOCAL%\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang\minecraftWorlds\
    

    ...and sort by Date Modified. This should put the folder for the world you just created at the top. Open the folder then select and copy two files:

    level.dat
    level.dat_old
    

    ...copy these files into the folder for the world you're trying to recover, then delete the folder that you copied the files from.

    Restart Minecraft and you should now see the world you're trying to recover.

    I saw someone report that when they opened the world there we chunks missing. That was probably because the original .dat files for the save were corrupt. This restore process won't fix corrupted data files. This process will only correct an issue with a missing or corrupted MANAFEST file.