Last active
November 9, 2023 08:14
-
-
Save basu021/240694a234d02250c2803ea8f72806fd to your computer and use it in GitHub Desktop.
create database dump from innodb to ndb cluster. Here two files will be generated one is structure and another one contains data. Restore structure first then import data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# MySQL Database Information | |
DB_USER="YOUR_DBA_USER" | |
DB_PASSWORD="DBA_PASSWORD" | |
HOST="HOSTNAME" | |
# Output directory | |
OUTPUT_DIR="/home/rhel/temp" | |
# Prompt for database names or fetch all databases | |
read -p "Enter database names (space-separated) or leave empty to fetch all databases: " DB_NAMES | |
if [ -z "$DB_NAMES" ]; then | |
# Fetch all databases | |
DB_NAMES=$(mysql -u $DB_USER -p$DB_PASSWORD -h $HOST -e "SHOW DATABASES;" | awk '{if(NR>2)print}') | |
fi | |
# Iterate through each database | |
for DB_NAME in $DB_NAMES; do | |
# Backup the database structure only | |
mysqldump -u $DB_USER -p$DB_PASSWORD -h $HOST --no-data $DB_NAME > "$OUTPUT_DIR/$DB_NAME-structureonly.sql" | |
# Backup the database data only | |
mysqldump -u $DB_USER -p$DB_PASSWORD -h $HOST --no-create-info $DB_NAME > "$OUTPUT_DIR/$DB_NAME-dataonly.sql" | |
# Replace InnoDB with NDB in the backup files | |
sed -i 's/ENGINE=InnoDB/ENGINE=NDBCLUSTER/g' "$OUTPUT_DIR/$DB_NAME-structureonly.sql" | |
sed -i 's/ENGINE=InnoDB/ENGINE=NDBCLUSTER/g' "$OUTPUT_DIR/$DB_NAME-dataonly.sql" | |
echo "Database $DB_NAME processed and backup files created." | |
done | |
echo "Migration process completed." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment