lihaibh / ditto

NPM library that helps managing MongoDB snapshots easily and efficiently
https://www.npmjs.com/package/mongodb-snapshot
MIT License
48 stars 6 forks source link

backup.tar file invalid #18

Open prabesh887 opened 3 years ago

prabesh887 commented 3 years ago

I have successfully generated the backup file, but when I try to open that file, the file doesn't open. It throws an error as Invalid archive header found.

lihaibh commented 3 years ago

how did you create this tar?

prabesh887 commented 3 years ago

I simply run this code below, it generated the tar file, and when I tried to open that file on my PC its shows an error.

import { MongoTransferer, MongoDBDuplexConnector, LocalFileSystemDuplexConnector } from 'mongodb-snapshot';

async function dumpMongo2Localfile() { const mongo_connector = new MongoDBDuplexConnector({ connection: { uri: mongodb://<username>:<password>@<hostname>:<port>, dbname: <database-name>, }, });

const localfile_connector = new LocalFileSystemDuplexConnector({
    connection: {
        path: './backup.tar',
    },
});

const transferer = new MongoTransferer({
    source: mongo_connector,
    targets: [localfile_connector],
});

for await (const { total, write } of transferer) {
    console.log(`remaining bytes to write: ${total - write}`);
}

}

lihaibh commented 3 years ago

@prabesh887 with what program are you trying to open this tar? you need rar, the native zip in windows wont work. or if you have unix shell, you can run tar -xvf backup.tar

prabesh887 commented 3 years ago

@lihaibh I have tried it with the WinZip application, that didn't work. I ran tar -xvf backup.tar via window's terminal, it generated JSON and BSON file types but those files are empty. Do I need to use any other kind of terminal?

lihaibh commented 3 years ago

@prabesh887 you need winrar to extract the file

prabesh887 commented 3 years ago

@lihaibh Thanks. WinRAR worked, it open the files but inside all JSON file there is only {"options":{},"indexes":[{"v":2,"key":{"_id":1},"name":"_id_"}],"uuid":""} . Have I missed anything?

lihaibh commented 3 years ago

the json files are metadata about the collection, it contains the index details of the collection, you should have also bson files which are the actual encoded monodb data.

lihaibh commented 1 year ago

@prabesh887 the issue resolved for you?