This script will help you to easily back up your MySQL database. It is especially helpful when use with crontab
to automate backup progress. You can define a backup rotation scheme for each database.
Require mysqldump
and jq
.
jq
install instruction can be found here.
For CentOS:
wget -O jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64
chmod +x ./jq
cp jq /usr/bin
Clone the repo:
git clone https://github.com/ownego/database-backup.git
Then start to config:
cd database-backup
bash oe_db.sh -c
This script take 3 options:
-c
to config database connections.
-a
to run backup progress for all databases defined in config file.
-d database_name
to run backup progress for one specific database (must be defined in config).
Each database config entry has 5 properties:
- Database name
- Database username
- Database password
- Database backup cycle (days)
- Database backup directory (where to save backups)
Configuration file is JSON formatted and can be easily manually configured or shared.
Examples:
00 00 * * * bash /path/to/oe_db.sh -a
00 12 * * * bash /path/to/oe_db.sh -d example_database