MySQL is one of the worlds most popular opensource databases in use today. Much of MySQL’s success can be attributed to its general ease of installation and usability. A functional MySQL installation is a single package install on most Linux distributions.
It’s so easy to hit the ground running with MySQL that we frequently encounter scenarios where backups haven’t been considered. Backups are just as easy to get going as MySQL itself. We’ll walk you through the process in this article by creating a script that utilizes mysqldump, MySQL’s backup utility.
This script is designed to be generic and run on the database server directly. You can copy and paste it into your environment, set the executable bit, and run it immediately. We deploy this script to /usr/local/bin/mysql_backup.sh.
The script will create an individual file for each database on your server in the /dumps path. If you want to change where the dumps are written to you can change the STORE_PATH variable.
The arguments we use are defined in MYSQL_ARGS and provide the following.
–single-transaction Provides a consistent state of the database for reliable restore.
–routines Includes stored procedures and functions in the database dump.
–events Includes any scheduled events in the database dump.
–databases We specify the databases option to have the CREATE DATABASE statements added to our dump.