-
Notifications
You must be signed in to change notification settings - Fork 1
/
replicator.sh
executable file
·58 lines (46 loc) · 1.2 KB
/
replicator.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
. ./replication.properties
#echo "master-username = $musername"
#echo "master-password = $mpassword"
#echo "master-host = $mhost"
#echo "slave-username = $susername"
#echo "slave-password = $spassword"
#echo "slave-host = $shost"
if [ `whoami` != 'root' ]; then
echo "Can be exeucted only with root privileges"
exit 1;
fi
stopMySQL() {
echo -e "\n Stopping MySQL instance"
sleep 2
mysqladmin -uroot -p$spassword shutdown 2> /dev/null
}
stopMySQLNoPassword() {
echo -e "\n Stopping MySQL instance"
sleep 2
mysqladmin -uroot shutdown 2> /dev/null
}
findAndReplace () {
found=""
if [ "`grep "$1" /etc/my.cnf`" == "" ]; then found="true"; fi
if [ -z "$found" ]; then
sed "s/"$1".*=.*/"$1=$2"/g" /tmp/my.cnf > /tmp/my.cnf.bak
else
sed '/\[mysqld\]/a\
'$1=$2'
' /tmp/my.cnf > /tmp/my.cnf.bak
fi
mv /tmp/my.cnf.bak /tmp/my.cnf
}
findAndDisable () {
found=""
if [ "`grep "$1" /etc/my.cnf`" == "" ]; then found="true"; fi
if [ -z "$found" ]; then
sed "s/"$1".*=.*/#"$1"/g" /tmp/my.cnf > /tmp/my.cnf.bak
else
sed '/\[mysqld\]/a\
#'$1'
' /tmp/my.cnf > /tmp/my.cnf.bak
fi
mv /tmp/my.cnf.bak /tmp/my.cnf
}