In this video, you will learn how to back up, restore and migrate MongoDB databases. Earlier we considered how to install and configure MongoDB on the Ubuntu 20.04 server, and today we will continue this issue and discuss exactly the above aspects in working with MongoDB
Useful links
VPS/VDS - https://www.mivocloud.com/
Commands used
IMPORT DATABASE
wget https://raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/primer-dataset.json
mongoimport --db newdb --collection restaurants --file primer-dataset.json
mongo newdb
db.restaurants.count()
db.restaurants.findOne()
Exit
BACKUP
mkdir /var/backups/mongobackups
mongodump --db newdb --out /var/backups/mongobackups/$(date +'%m-%d-%y')
crontab -e
3 3 * * * mongodump --out /var/backups/mongobackups/$(date +'\%m-\%d-\%y')
find /var/backups/mongobackups/ -mtime +7 -exec rm -rf {} \;
crontab -e
1 3 * * * find /var/backups/mongobackups/ -mtime +7 -exec rm -rf {} \;
RESTORE AND MIGRATE
mongorestore --db newdb --drop /var/backups/mongobackups/10-29-20/newdb/
0 Comments