I’m creating a shell script to automatically dump the database. I have the current code below.
#!/bin/sh FILENAME=backup_`date +%m%d%y%H`.zip DEST=/backup/$FILENAME SERVER=127.0.0.1:27017 mongodump -h $SERVER -d "database-cms" --archive=$DEST --gzip
The problem is when I’m opening the zip file it shows a single binary file. Usually, when I dump manually it consists of bson and json files. I don’t know what I’m doing wrong I’m expecting a zip file with bson and json file.
UPDATE Turns out that –archive returns binary file. I updated the codes to:
#!/bin/sh FILENAME=configurator_`date +%m%d%y%H`.tar.gz DEST=/home/glenn/projects/database_dump/backup SERVER=127.0.0.1:27017 mongodump -h $SERVER -d siaphaji-cms --out $DEST; tar -zcvf $FILENAME siaphaji-cms
The problem is how can I specifically tar the siaphaji-cms folder. The way it runs now is when its compressing it compress all inside backup folder.
Advertisement
Answer
That’s actually works as designed when you use --archive
.
The alternative is to provide a path
to --out
, which will then give you individual BSON & JSON files … you’d have to manually GZIP those (or tar the resulting subdirectory/ies.