Strategical Shell Scripting For MySql Replication


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strategical Shell Scripting For MySql Replication
# 1  
Old 04-18-2011
Strategical Shell Scripting For MySql Replication

Hi to all guyz ,
As i'm new to Shell scripting i was been working out to write a shell script for mysql Replication for multiple slave master architecture.i have done the process up with a script of 200 lines but still there are some things which can make my script more effective so i want your help to solve this script run like a pro

here is the problem i'm facing now

there is a table in the database by name Ipmonitor and in that i have a master ip and some slave ip's and the slave status will be in "0" and master ip will be as "1".if my master ip gets down it will check for a good slave to make it as new master and it deletes the old master record in the table and assigns new master's status as "1".after that selected ip will be the new master .now the real problem starts is dat i want to write a for loop to checkout the ip's and make the other ip's to route to the new master ip....so how can i write the shell script to check the slaves present apart from the ip which has been changed from slave to master.

Advance thanks to guys who help me out in this problem
# 2  
Old 04-18-2011
Welcome to the forums! Smilie

I dont fully understand the problem. Are you saying the slaves or other hosts should be updated with the information on which master it has to look to. Without going to the details of implementation, it looks like that is not the way right way of doing it. Slave should be agnostic of who the master is. Slave should hit a common interface something like a DNS that should take care of taking the packets or connecting to the 'then' master or 'then' super master and slave should not be knowing that information at all.

I might have misunderstood, sorry.
# 3  
Old 04-18-2011
Hmm actually i'm building up a inteligent monitoring system which checks the architecture every 5secs through cron job......now the script checks up for the slave having up the recent and last log position of the master in to the slave and then we will make that slave as the new master and the other slaves should route up to the new master.the fetching up of the rite slave will be done with the interface of the database.now i want to make other slave ip's to route out to the new master ip.here i want to write a looping statement to check the ip's present in the table and execute some commands on the slave machines
# 4  
Old 04-19-2011
I haven't understood the problem completely.

Quote:
i want to write a looping statement to check the ip's present in the table and execute some commands on the slave machines
So, where is that you are stuck actually?

Code:
while read :
do
<scan_table_or_data_source>
<determine_master_or_slave>
<execute_commands>
sleep +n # if needed
done

# 5  
Old 04-19-2011
Code:
select * from ipmonitor;
+------+-----------+---------+--------+
| id   | ip        | filepos | status |
+------+-----------+---------+--------+
|    1 | 10.0.0.20 |     109 |      1 |
|    2 | 10.0.0.21 |     122 |      0 |
|    3 | 10.0.0.22 |     125 |      0 |
+------+-----------+---------+--------+
3 rows in set (0.00 sec)

the above given was the table having the ip's where the ip having the status 1 will be the new master and the ip's wid '0' will be the slaves and here i should write a for loop to check every ip to execute the commands in making the slaves route to new master ip based on the status value '0' which is assigned for slave ip's!!!!

Last edited by pludi; 04-19-2011 at 08:17 AM..
# 6  
Old 04-20-2011
thank you dude....... your help made me to solve half of the problem in the script.....now my code was done and working like a pro!!!!!!!!
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. UNIX Desktop Questions & Answers

How can I replicate master master and master master MySQL databse replication and HA?

I have an application desigend in PHP and MySQl running on apache web server that I is running on a Amazon EC2 server Centos. I want to implement the master-master and master slave replication and high availability disaster recovery on this application database. For this I have created two... (0 Replies)
Discussion started by: Palak Sharma
0 Replies

2. Linux

Mysql replication

Need to recover a replication broken error on the mysql slave server. I want to force it to resend the binlog file from the begining. What is the correct value for the: MASTER_LOG_POS ? 0, 1 or 107 ? (2 Replies)
Discussion started by: andriesh
2 Replies

3. Shell Programming and Scripting

ERROR in executing mysql querys in shell scripting

Hi All, Please see the below script for mysql 3 commands. Its giving me the right output for all three commands but showing some errors in first two commands , i guess there might be an issue with date. Can anyone help me . #! /bin/bash TABLE_NAME=testingddatabase USER_NAME=root... (3 Replies)
Discussion started by: aish11
3 Replies

4. Web Development

MySQL Replication Issues: Duplicate Key Error

Lately my attention has been focused on distributed MySQL database replication to other web servers. All was going well, but then I noticed the replication would stop and there were there "Duplicate Primary Key" errors in SHOW SLAVE STATUS; I started to trace these down and noticed that this... (2 Replies)
Discussion started by: Neo
2 Replies

5. Shell Programming and Scripting

shell scripting on unix/mysql problems

Hi, I have written a shell script for oracle on unix that does a df for specific files, and then will display the size, Avail, % used and the difference from yesterday to today. I have been asked to place it on some MySql databases that run onn unix and linux also, but when I try to run them I... (2 Replies)
Discussion started by: cat55
2 Replies
Login or Register to Ask a Question