Skip to content

MongoDB Restore Backedup DBs

This document highlights the steps needed to restore backedup DBs in MongoDB.

📖 Table of Contents

Initial Access

SSH into bastion server and then into master1 node:

user@local:~$ ssh ansible@185.129.118.27 -p 23389 -t sudo -i
root@bastion:~# ssh bticir-xaas-prd-k8s-master1 -t sudo -i

Download Backup Files

Get your backup files inside the master1 node. You can use wget or scp for this. For example if your backups are available as a zip file(e.g dump.zip) somewhere:

root@bticir-xaas-prd-k8s-master1:~# wget 192.168.3.12:8000/dump.zip
root@bticir-xaas-prd-k8s-master1:~# unzip ./dump.zip
root@bticir-xaas-prd-k8s-master1:~# ls

dump

Now move the dump dir into a pod:

kubectl -n backend-mongodb-prd  cp ./dump mongodb-prd-0:/tmp/dump

Run The Restore Command

All you need to do now, is to put the restore command for MongoDB in front of this command as an argument:

kubectl -n backend-mongodb-prd exec -it mongodb-prd-0 -- mongorestore <options> <connection-string> <directory or file to restore>

And as for our example the command would be like this:

kubectl -n backend-mongodb-prd exec -it mongodb-prd-0 -- mongorestore mongodb://admin:password@localhost:27017/?replicaSet=rs0 /tmp/dump