NaviteLogger / Shell-Script-for-Automating-MySQL-Database-Duplication

The following script automates the creation of a test database by duplicating an existing database.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shell Script for Automating MySQL Database Duplication

The following script automates the creation of a test database by duplicating an existing database. It exports the schema (and optionally the data), creates a new test database, and imports the schema/data into the test database.

Table of Contents

Prerequisites

  • MySQL Server: One of the scripts is designed for MySQL databases. Ensure you have MySQL server installed and accessible.
  • .env File: Database credentials and other configurations are managed through a .env file in the project directory.

Installation

Clone this repository to your local machine using the following command:

git clone https://github.com/NaviteLogger/Shell-Script-for-Automating-MySQL-Database-Duplication.git
cd Shell-Script-for-Automating-MySQL-Database-Duplication

Ensure the script file (duplicate_db.sh) is executable:

chmod +x duplicate_mysql_db.sh

Configuration

Create a .env file in the root directory of this project with the following content, replacing the placeholders with your actual database credentials and names:

DB_USER=myuser
DB_PASS=mypassword
SOURCE_DB=mydatabase
TEST_DB=mytestdatabase

Usage

To run the script:

./duplicate_mysql_db.sh

The script will prompt you for your MySQL password (if not provided in the .env file), export the specified source database, create (and drop if it already exists) the test database, and then import the data into the test database.

Security

This script prompts for the database password to avoid storing sensitive information in the script or the .env file. Ensure your .env file is not tracked by version control systems (e.g., listed in .gitignore) to keep your credentials secure.

Contributing

Contributions to improve the script or address issues are welcome. Please feel free to submit a pull request or open an issue in the repository.

License

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

About

The following script automates the creation of a test database by duplicating an existing database.

License:Other


Languages

Language:Shell 100.0%