Skip to content

zamibd/db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

🔄 MySQL to MySQL Live Database Transfer Script

A one-click bash script to securely dump, transfer, and import a MySQL/MariaDB database from one live server to another — all in one step.


✨ What You'll Get

✅ Dump a source database
✅ Securely transfer the dump via SSH
✅ Automatically import into a destination MySQL/MariaDB server
✅ Automatically clean up (.sql file deleted from both servers)
✅ Easy-to-configure and reusable


📁 File Structure

db/
├── db.sh         # The main transfer script
└── README.md     # This documentation

⚙️ Requirements

  • Linux/macOS terminal (bash)
  • mysqldump, mysql installed (default in most systems)
  • sshpass for SSH automation (if not using SSH key)

🔧 To install dependencies (Ubuntu/Debian):

sudo apt update
sudo apt install sshpass mysql-client -y

🧠 Configuration

  1. Open the script file:
nano db.sh
  1. Replace the following placeholders with your actual credentials:
# Source DB
SRC_DB="your_database"
SRC_USER="your_database_user"
SRC_PASS="your_source_db_password"

# Destination
DEST_HOST="your_IP"
DEST_DB="your_database"
DEST_USER="your_database_user"
DEST_PASS="your_dest_db_password"
DEST_SSH_USER="root"
DEST_SSH_PASS="your_ssh_password"

🚀 How to Run the Script

  1. Make the script executable:
chmod +x db.sh
  1. Run it:
./db.sh

✅ That’s it — your database will be dumped, transferred, imported, and cleaned up in seconds.


🧹 Auto Cleanup

This script deletes the backup .sql file from both servers after the import is complete.

  • Local .sql file: deleted from the source server
  • Remote .sql file: deleted from the destination server after import

This ensures security and avoids disk clutter.


🔐 Security Notes

  • This script uses plain-text passwords for MySQL and SSH. Only use on trusted environments.
  • For better security, consider:
    • SSH key authentication instead of sshpass
    • Using .my.cnf to store MySQL credentials securely

📦 Example Output

📦 Dumping source database (Database)...
🚚 Transferring backup to destination server (IP)...
📥 Importing into destination database (Database)...
🧹 Deleting local backup file...
✅ Transfer, import & cleanup complete!

🤝 Credits

Author: zamibd
License: MIT — free to use, modify, and distribute.


💬 Need Help?

Feel free to open an issue or pull request on the GitHub repo.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages