Krishnakumar
Krishnakumar

Reputation: 73

don't know what to do with file "/root/livedb/filename.metadata.json.gz", skipping

I have taken mongodb dump from atlas mongo db and restore to AWS document DB.

When i am restore to document db getting below error

don't know what to do with file "/root/livedb/filename.metadata.json.gz", skipping...

How can i resolve this issue.

Upvotes: 1

Views: 127

Answers (1)

koksal
koksal

Reputation: 341

I faced a similar issue when trying to restore a MongoDB dump where all files in the dump were compressed with .gz. When I used mongorestore, I encountered the same error. To troubleshoot, I first checked how mongodump generated the dump files. I noticed that the files created for collections (tables) were not compressed.

While I couldn't test this directly on MongoDB Atlas, I read in multiple places that dumps for Atlas might indeed be compressed with .gz during the process.

To resolve this, I wrote a script to extract the .gz files and place the uncompressed files into a separate folder.

import os
import gzip
import shutil

src_dir = "/path/db/dump/db_name"
dest_dir = "/path/db/dump/db_name_extracted"

os.makedirs(dest_dir, exist_ok=True)

for file_name in os.listdir(src_dir):
    if file_name.endswith(".gz"):
        file_path = os.path.join(src_dir, file_name)
        
        # remove .gz extensino
        output_file_path = os.path.join(dest_dir, file_name[:-3])
    
        with gzip.open(file_path, 'rb') as f_in:
            with open(output_file_path, 'wb') as f_out:
                shutil.copyfileobj(f_in, f_out)

        print(f"Extracted: {output_file_path}")

print("All files were extracted and moved to the destination folder.")

After running this script, I was able to successfully restore the dump using the command:

mongorestore db_name_extracted/ -d db_name

This solution worked for me, so I hope it helps others facing the same issue.

Upvotes: 0

Related Questions