This is a Bash script which is designed to facilitate the backup and restoration of MySQL databases using mydumper
and myloader
. It provides a user-friendly interface to input database credentials, manage backup directories, and handle errors effectively. The script also incorporates color-coded output for better readability.
MyDumper is a MySQL Logical Backup Tool. It has 2 tools:
mydumper
which is responsible to export a consistent backup of MySQL databasesmyloader
reads the backup from mydumper, connects to the destination database and imports the backup.
Both tools use multithreading capabilities.
MyDumper is Open Source and maintained by the community, it is not a Percona, MariaDB or MySQL product.
- Parallelism (hence, speed) and performance (avoids expensive character set conversion routines, efficient code overall)
- Easier to manage output (separate files for tables, dump metadata, etc, easy to view/parse data)
- Consistency - maintains snapshot across all threads, provides accurate master and slave log positions, etc
- Manageability - supports PCRE for specifying database and tables inclusions and exclusions
- MyDumper Official Documentation
Official Documentation - MyDumper Installation Guide
Official Installation Guide - MyDumper Usage
usage guide to MyDumper
- User Input: Prompts users for source and destination database details with default values.
- Backup Process: Utilizes
mydumper
to create backups of specified databases. - Error Handling: Analyzes
mydumper
errors and provides informative messages. - Permission Management: Adjusts file and directory permissions for security.
- Restore Process: Uses
myloader
to restore backups to a specified database. - Logging: Maintains logs of both backup and restore processes for troubleshooting.
- Color-Coded Output: Enhances user experience with colored messages.
- Bash: Ensure you have a Bash shell available.
- mydumper: Install
mydumper
for backup operations. - myloader: Install
myloader
for restoration operations. - MySQL: Ensure you have MySQL server installed and running.
-
Clone the repository or download the script.
-
Make the script executable:
chmod +x aws_rds_schema_shuttl.sh
-
Run the script
./aws_rds_schema_shuttle.sh
-
Follow the on-screen instructions to input database credentials and manage backups and restores.
- The script will prompt for the following details:
- Source Database Host (default: localhost)
- Source Database User (default: root)
- Source Database Password (default: empty)
- Source Database Name (default: mysql)
- Source Database Port (default: 3306)
- MyLoader User (default: ubuntu)
-
Backup Directory: The script will create a backup directory in the format
YYYY-MM-DD_HH-
in the./Backup/ directory
.- It will also create a log file for the backup process as
./Backup/DumperLogs/logname_YYYY-MM-DD_HH.log
.
- It will also create a log file for the backup process as
-
Restore Process:
- After the backup, you will be prompted to continue with the restore process
- If you choose to proceed, you will need to enter destination database details similar to the source.
-
The script will output the success or failure of the restore process and provide the location of the log file.
The script provides specific error messages based on common issues encountered during backup and restore operations, including:
- Access denied errors
- Connection issues with MySQL server
- Unknown database errors
- Lock acquisition failures
- Thanks to the developers of mydumper and myloader for their excellent tools.
- Special thanks to the open-source community for their contributions.
Notes:
This script is intended for use in a controlled environment and may require adjustments for production use cases.
The `README.md` file is structured to provide clear and concise information about thescript, making it easy for users to understand its purpose and how to use it effectively.
Feel free to modify any sections to better fit your project's specifics or to add additional information as needed.