Want to back up your Mysql database? This is how it works
Do you use a database? It is of vital importance to create backups on a regular interval. This way, data can be restored in case of an emergency.
But, a backup of just a server is not sufficient. It is better to back up the database as well. To do so, read the steps below.
Mysqldump
Mysqldump is a command-line utility that can be used to create backups of a Mysql database.
Usage: mysqldump [OPTIONS] database [tables]
OR mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help
Schedule regular backups with cron
To create backups on a regular interval, Mysqldump backups can be scheduled using cron.
The following cron example creates a backup every 15 minutes of the 'employees' database, compresses it with gzip and stores it with a date/timestamp.
*/15 * * * * mysqldump -u root -p'password' employees | gzip > /root/db_backup/employees_`date +\%Y\%m\%d_\%H\%M`.sql.gz
Note that this is a very simple example of mysqldump. We recommend exploring the additional options available. A simple search on the internet will return plenty results to work with.
Make sure to test first!
We would recommend you to test restoring the data, so you are certain a succesful restore can be done whenever it is needed.
Comments
Please sign in to leave a comment.