= MongoDb / MongoBackup MongoRestore = * Links: [[Linux/Backups]] * Mongo backup {{{ export u="UserMongo" export p="PwdSecret" export d="dbprd" export h="mongodb+srv://$u:$p@prd.mongodb.net/$d?readPreference=secondary" export c="coll_data" echo "#$u , $p , $h , $d , $c" echo " --out /tmp/dump-$dr-$c.bson" time docker run -it -v /tmp:/mnt -e h="$h" -e c=$c -e d=$d mongo mongodump --uri="$h" --collection="$c" --gzip --archive=/mnt/dump-$d-$c.bson }}} * Mongo restore {{{ export u="adminUSR" export p="admPWD" export d="dbprd" export h="mongodb+srv://$u:$p@cluster0.mongodb.net/admin" export c="coll_data" ls -l /tmp/dump-$d-$c.bson time docker run -i -v /tmp:/mnt -e h="$h" -e c=$c -e d=$d mongo \ mongorestore --uri="$h" -v -v --gzip --drop --db=$d --collection="$c" --archive=/mnt/dump-$d-$c.bson }}} * Mongo restore from archive to new db name {{{ mongorestore --host 127.0.0.1:27017 --gzip --archive=latest.dump.gz --nsFrom "olddb.*" --nsTo "newdb.*" --username user --password "abcdefg" --authenticationDatabase newdb }}}