Home > Software engineering >  MongoDb 2.6 issue with archiving
MongoDb 2.6 issue with archiving

Time:12-09

good day, i stuck with script which is made to backup a collection of mongodb, 2.6 version doesn't support --gzip suffix, is there a way how to use other way to archive collections and in case of need safely to do mongorestore? Thanks a lot for a reading my post.

#specify collections
collection_list="students loans.lib help.archive"
#if its running on local machine:
host="127.0.0.1"
port="27208"
#where to dump:
out_prefix="/apps/mongodb/uni/backup/mongodump"
for collection in $collection_list; do
        echo $collection
        out_dir="${out_prefix}/${db}_${collection}.$(date  %Y.%m.%d)/"
        mkdir -p ${out_dir}
        /apps/mongodb/server/2.6.2/bin/mongodump -u  -p --host $host --port $port -d $db --collection $collection --out ${out_dir}
done

--gzip is not recognized :( P.S. I'm not able to upgrade our old university mongodb, we dont have a budget for it.

CodePudding user response:

If you need to compress on the fly without the "--gzip" option introduced in mongodb 3.2 , you can do as follow in linux:

 mongodump -d yourDB -c yourCOL -o - | gzip > yourDByourCOLdump.gz

to restore it , you can do:

 gunzip yourDByourCOLdump.gz
 mv yourDByourCOLdump yourDByourCOLdump.bson
 mongorestore -d yourDB -c yourCOL yourDByourCOLdump.bson
  • Related