Huge problem with a restore of backup

I am in trouble :frowning: an aggregation pipeline I ran corrupted one of my collections. Thought I was lucky since I have a backup of the DB dating only one hour earlier. Currently not able to restore. Here are the details:

The backup is created as follows:

mongodump --uri="mongodb://" --db memaback --archive=/home/bob/mongoback/${timestamp}_memaback.archive.gz --gzip

in a cron shell script that runs daily (and provides a timestamp for the datetime)

Resulting file is:

-rw-r--r-- 1 root root 2.3G May 7 07:05 20230507-070001_memaback.archive.gz

Now as I destroyed only my art collection in the memaback db I tried restoring the above file with the following command:

mongorestore --gzip --host --port 57777 --db memaback --collection art 20230507-070001_memaback.archive.gz

which gives an error:

Failed: error scanning filesystem: file 20230507-070001_memaback.archive.gz does not have .bson or .bson.gz extension

so tried to rename the file to .bson.gz and ran the same command with the new filename but get:

Failed: error restoring from 20230507-070001_memaback.archive.bson.gz: reading bson input: invalid BSONSize: -2120621459 bytes is less than 5 bytes

The file is 2.3GB. The Linux ‘file’ command confirms its a gzipped file.

I also tried gunzipping it and the top of the resulting file seems promising (hopefully) and tried with this other syntax:

mongorestore --port 57777 20230507-070001_memaback.archive.bson
but get the same size error.

mongorestore --version:

mongorestore version: 100.7.0
git version: 17946f45f5fabfcdd99f8960b9109f976d370631
Go version: go1.19.3
   os: linux
   arch: amd64
   compiler: gc
mongos version v4.4.19
Build Info: {
    "version": "4.4.19",
    "gitVersion": "9a996e0ad993148b9650dc402e6d3b1804ad3b8a",
    "openSSLVersion": "OpenSSL 1.0.2g  1 Mar 2016",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu1604",
        "distarch": "x86_64",
        "target_arch": "x86_64"

running on a VPS with Ubuntu 16.04 (yes stuck there unluckily)

Thanks for any help !!!

As the backup is an archive format the mongorestore will also need to use the --archive=filename


Wow ok thanks so there’s hope :slight_smile:

As I’ve started rebuilding that collection via my programs, but it’s a very long process lasting almost a week, how would you advise I proceed to avoid mixing docs from the restore with those from the restore? Maybe using the --collection parameter with a temporary new name?

Thanks a lot.

Well, first renamed the rebuilding collection and then thanks to your correct suggestion restore 150587 documents (over 8GB) in under a minute.

What a relief. Lesson learned.

Thanks a LOT !!!

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.