Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #include variables from config file
- source /home/porta-one/def_conf.ini
- #check whether the script is run as root/sudo
- is_root ()
- {
- whoami | grep "root" > /dev/null
- if [ $? -eq 1 ]
- then
- echo "You must run script as root";
- exit;
- fi
- }
- parse_options ()
- {
- echo "The following options will be used for replication restoration:
- database replicate from: $master_host
- database replicate to: $slave_host"
- i="0"
- while [ $i -lt 3 ]
- do
- read -p "Do you agree? (Y/N) " confirm
- if printf "%s\n" "$confirm" | grep -Eq "$(locale yesexpr)"
- then
- echo "Confirmed..."
- i=3
- elif printf "%s\n" "$confirm" | grep -Eq "$(locale noexpr)"
- then
- echo "Change def_conf.ini" && exit 1
- i=3
- else
- echo "Press Y or N"
- i=$[$i+1]
- fi
- done
- }
- is_configurator_ssh ()
- {
- conf_ip=`/home/porta-configurator/bin/cfgctl.pl -c get_configurator_addr`
- current_ip=`hostname -I | awk '{print $1}'`
- if [ $conf_ip == $current_ip ]
- then
- ssh_conn=""
- else
- ssh_conn=($rsh_porta $conf_ip)
- fi
- }
- mysql_cmd ()
- {
- slave_ip=`mysql -u root porta-configurator -Nse "select ip from Servers where i_server in (select i_server from Instances where name like \"$slave_host%\" and i_configuration in (select max(i_configuration) from Instances));"`
- master_ip=`mysql -u root porta-configurator -Nse "select ip from Servers where i_server in (select i_server from Instances where name like \"$master_host%\" and i_configuration in (select max(i_configuration) from Instances));"`
- web_ip=(`mysql -u root porta-configurator -Nse "select ip from Servers where i_server in (select i_server from Instances where name like \"$web_host%\" and i_configuration in (select max(i_configuration) from Instances));"`)
- echo "slave: $slave_ip, master: $master_ip, web: $web_ip"
- }
- is_root
- parse_options
- is_configurator_ssh
- $ssh_conn mysql_cmd
- echo "slave: $slave_ip, master: $master_ip, web: $web_ip"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement