-
Notifications
You must be signed in to change notification settings - Fork 1
/
mysql_do_db.sh
49 lines (38 loc) · 904 Bytes
/
mysql_do_db.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
# -----------------------------------------------------------------------------
# Name : mysql_do_db.sh
# Description : add a line "binlog-do-db=<database>" after server-id in /etc/my.cnf
# Author : qiaolei
# Date : 2014/10/13
# -----------------------------------------------------------------------------
#!/bin/sh
usage()
{
echo "Usage: $0 <database>"
}
if [ $# -ne 1 ]
then
usage
exit 1
fi
LOG_FILE=/tmp/mysql_scripts.log
if [ ! -f $LOG_FILE ];then
touch $LOG_FILE
fi
TIMESTAMP=`date +%Y%m%d%H%M%S`
echo "@$TIMESTAMP: {$0 $*}" | tee -a $LOG_FILE
DATABASE=$1
TMP_My_CNF=/tmp/my.cnf
sed "/server-id/a\binlog-do-db=$DATABASE" /etc/my.cnf >$TMP_My_CNF
mv -f $TMP_My_CNF /etc/my.cnf
RC=$?
CODE=-1
MSG=""
if [ $RC -eq 0 ];then
CODE=$RC
MSG="OK"
else
CODE=$RC
MSG="KO"
fi
RESULT=`printf "%s%s%s%s%s%s%s" "{" "\"result\":" "\"$CODE\"" "," "\"msg\":" "\"$MSG\"" "}"`
echo $RESULT