dokku / dokku-mongo

a mongo plugin for dokku
MIT License
177 stars 32 forks source link

dokku-mongo export produces an invalid tar file #105

Closed justintemps closed 6 years ago

justintemps commented 6 years ago

This is essentially the same problem as described in #84 and was supposed to have been resolved in ed7acd3.

However, I continue having the same problem whether I try to do the export remotely or after I've ssh'd into my server.

$ ssh user@example.com
$ dokku mongo:export database > backup.tar
$ tar -xfv backup.tar
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Exiting with failure status due to previous errors

My goal is to export the data from dokku-mongo on my staging server and import it into a local instance of mongo running on localhost (OSX). To do that, I believe I need to be able to export a valid .bson file, which is what I'm guessing the .tar from dokku mongo:export should give me.

This is using DO Dokku One-Click https://www.digitalocean.com/products/one-click-apps/dokku/

josegonzalez commented 6 years ago

I don't think the export is actually a tar. The readme we have is wrong, but if you run dokku mongo:help export, you'll see the correct usage.

jcutrono commented 6 years ago

Here is the restore command I am using currently. Works like a charm: restore.sh

dns=$(aws ec2 describe-instances --filters Name=tag:Name,Values=Test --query 'Reservations[].Instances[].PublicDnsName' --output text)
aws s3 cp s3://{bucket}/{file}.tgz {file}.tgz
tar -xvf {file}.tgz
# i am on a different box so i need to copy to the server
scp -r backup/export ubuntu@$dns:~/

ssh  ubuntu@$dns << EOF
dokku mongo:import {app} < export
EOF

Hope that helps

justintemps commented 6 years ago

@josegonzalez Thanks so much for the fast response! Here's what dokku mongo:help export says:

export a dump of the MongoDB service database

arguments:

service   service to run command against

examples:
by default, datastore output is exported to stdout

dokku mongo:export lolipop

you can redirect this output to a file

dokku mongo:export lolipop > lolipop.dump

export a dump of the MongoDB service database
arguments:

service   service to run command against

examples:
by default, datastore output is exported to stdout

dokku mongo:export lolipop

you can redirect this output to a file

dokku mongo:export lolipop > lolipop.dump

I still can't figure out what kind of file it is or how to import it into another mongo instance via mongorestore.

josegonzalez commented 6 years ago

Looks like its the gzip output of mongodump.

josegonzalez commented 6 years ago

To restore, it should be this command or similar locally.

justintemps commented 6 years ago

Thanks @josegonzalez! Turned out to be pretty simple

mongorestore --gzip --archive=mydatabase.dump