MongoDB - How to backup and restore a database
This is a quick example to show how to easily backup and restore a MongoDB database from the command line, using the current date as the backup folder name (YYYYMMDD).
Backup MongoDB database using date for the folder name
mongodump command will create a backup / dump of the MongoDB database with the name specified by the
--db [DB NAME] argument.
--out /var/backups/`date +"%Y%m%d" argument specifies the output directory as
/var/backups/[TODAY'S DATE] e.g.
sudo mongodump --db [DB NAME] --out /var/backups/`date +"%Y%m%d"`
Restore MongoDB database from backup
mongorestore command restores a database to the destination
--db [DB NAME] from the specified directory, e.g.
sudo mongorestore --db [DB NAME] /var/backups/[BACKUP FOLDER NAME]
Subscribe or Follow Me For Updates
Subscribe to my YouTube channel or follow me on Twitter, Facebook or GitHub to be notified when I post new content.
- Subscribe on YouTube at https://www.youtube.com/JasonWatmore
- Follow me on Twitter at https://twitter.com/jason_watmore
- Follow me on Facebook at https://www.facebook.com/JasonWatmoreBlog
- Follow me on GitHub at https://github.com/cornflourblue
- Feed formats available: RSS, Atom, JSON
Other than coding...
I'm currently attempting to travel around Australia by motorcycle with my wife Tina on a pair of Royal Enfield Himalayans. You can follow our adventures on YouTube, Instagram and Facebook.
- Subscribe on YouTube at https://www.youtube.com/TinaAndJason
- Follow us on Instagram at https://www.instagram.com/tinaandjason
- Follow us on Facebook at https://www.facebook.com/TinaAndJasonVlog
- Visit our website at https://tinaandjason.com.au
Need Some MongoDB Help?
Search fiverr to find help quickly from experienced MongoDB developers.