This is a simple backup script for MySQL servers, designed to help you easily back up your databases and manage your backup files. You can specify your database connection details and customize the backup settings using environment variables. This tool also provides the option to clean up old backups to save space.
Before you can use this tool, make sure you have the following prerequisites installed on your system:
- MySQL Client: Ensure that you have the MySQL client installed to interact with your MySQL databases.
-
Clone this repository to your local machine or server.
git clone https://github.com/obrunsmann/mysql-server-backup.git cd mysql-server-backup
-
Create a
.env
file based on the.env.example
template provided. This file will hold your database connection details and backup configuration.cp .env.example .env
-
Open the
.env
file in a text editor and provide the required information:db_host
: The hostname or IP address of your MySQL server.db_user
: The MySQL user with backup privileges.db_pass
: The password for the MySQL user.max_parallel
: The maximum number of parallel database backups.max_backups
: The maximum number of backup sets to retain.
-
Make sure the script file is executable.
chmod +x backup.sh
To create database backups using this tool, simply run the backup.sh
script:
./backup.sh
The script will perform the following actions:
-
Load Environment Variables: It reads the configuration from the
.env
file. -
Create Backup Directory: It creates a directory in the
backup/
folder with a timestamp to store the backups. -
Backup Databases in Parallel: It retrieves a list of databases from the MySQL server (excluding system databases) and backs them up in parallel based on the
max_parallel
setting. -
Cleanup Old Backups: It checks the number of backup sets and removes old backups if the number exceeds the
max_backups
setting.
Here's an example of how to run the backup script:
./backup.sh
This backup tool is released under the MIT License. See the LICENSE file for more details.
- Oliver Brunsmann: @obrunsmann
That's it! You now have a simple backup tool to help you manage your MySQL database backups. If you encounter any issues or have suggestions for improvements, feel free to open an issue on GitHub or contribute to the project.