Depending upon the env, you may need to use one of the ssh, docker exec, docker compose exec or kubectl exec to get into the mongo server.
mongodump --db=<db_name> --gzip --archive=/tmp/db_name_dump.gz
Depending upon the env, you may need to use one of the scp, docker cp, docker compose cp or kubectl cp commands to
copy /tmp/*_dump.gz files from source server to the target.
ssh |
docker exec |
docker compose exec |
kubectl exec |
mongorestore --gzip --archive=/tmp/db_name_dump.gz --dryRun --verbose
Observe the screen output. Proceed only if you are confident that you are not overwriting any wrong db or collection
By default, mongorestore uses the original database name. If there is any need to change the database name during restore, this command may be used.
mongorestore --gzip --archive=/tmp/db_name_dump.gz --nsFrom="<old_db_name>.*" --nsTo="<new_db_name>.*" --dryRun --verbose
Make sure the command is structured correctly by doing a dry run first. Once you are confident, omit the --dryRun option from the command and viola!
mongorestore --gzip --archive=/tmp/db_name_dump.gz