Essential Database Maintenance: Backing Up MariaDB and MongoDB
Protect Your Application’s Most Valuable Asset: Your Data
Running a database is only half the battle; you must also have a strategy for backing it up. The ‘Ubuntu System Administration Guide’ provides the essential commands for creating backups of both MariaDB and MongoDB.
Backing Up MariaDB (SQL)
For MariaDB, the standard tool is `mysqldump`. This command-line utility connects to the database and outputs a `.sql` file containing all the commands needed to recreate the database’s structure and data. A typical command looks like this:
mysqldump -u root -p your_database_name > backup.sql
Backing Up MongoDB (NoSQL)
For MongoDB, the equivalent tool is `mongodump`. This utility connects to the database and creates a `dump/` directory containing the data from your collections in a binary BSON format. A typical command specifies the database to back up:
mongodump --db your_database_name
The book stresses that these commands should be placed in scripts and run regularly via a cron job to ensure you always have recent backups.
This post is based from content of the book Ubuntu System adminstration guide. And the book can be found here https://www.amazon.com/stores/Mattias-Hemmingsson/author/B0FF5CQX13