]> andersk Git - sql.git/commitdiff
misc /sbin utils
authorJoe Presbrey <presbrey@mit.edu>
Mon, 13 Jul 2009 18:42:31 +0000 (18:42 +0000)
committerJoe Presbrey <presbrey@mit.edu>
Mon, 13 Jul 2009 18:42:31 +0000 (18:42 +0000)
git-svn-id: svn://presbrey.mit.edu/sql@173 a142d4bd-2cfb-0310-9673-cb33a7e74f58

sbin/adjust_repo [new file with mode: 0755]
sbin/autorepair [new file with mode: 0755]
sbin/repair [new file with mode: 0755]
sbin/slave_skip [new file with mode: 0755]
sbin/verify [new file with mode: 0755]

diff --git a/sbin/adjust_repo b/sbin/adjust_repo
new file mode 100755 (executable)
index 0000000..b0d04bf
--- /dev/null
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+for i in `ls *.rpmnew`; do
+       mv -f "$i" "${i::$((${#i}-7))}"
+done
+
+for i in `ls *.repo`; do
+       awk '{ sub(/#baseurl/, "baseurl"); sub(/mirrorlist/, "#mirrorlist"); print }' "$i" > "$i.fix"
+       mv -f "$i.fix" "$i"
+done
diff --git a/sbin/autorepair b/sbin/autorepair
new file mode 100755 (executable)
index 0000000..f3349f4
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+while true; do
+    ./repair
+    sleep 1
+done
diff --git a/sbin/repair b/sbin/repair
new file mode 100755 (executable)
index 0000000..a6416e2
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+E=`mysql -e 'show slave status;' | grep 'Incorrect key file' | head -n1 | cut -f20 | sed -r -e "s/^.*\/(.*)\.MYI.*Default database: '([^']*)'.*$/\2 \1/"`
+DN=`echo $E | cut -d\  -f1`
+TN=`echo $E | cut -d\  -f2`
+
+if [ ! -z "$DN" ]; then
+    if [ ! -z "$TN" ]; then
+        mysql -e "repair table $TN; slave start;" $DN
+    fi
+fi
diff --git a/sbin/slave_skip b/sbin/slave_skip
new file mode 100755 (executable)
index 0000000..1d3dbde
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/python
+
+import time
+import MySQLdb as sql
+con = sql.connect('localhost','root','',unix_socket='/srv/mysql/mysql.sock')
+cur = con.cursor(sql.cursors.DictCursor)
+
+while 1:
+    cur.execute('SHOW SLAVE STATUS')
+    r = cur.fetchone()
+    if r['Slave_IO_Running'] == 'Yes' and r['Seconds_Behind_Master'] is None:
+        print 'Skipping next due to:'
+        print r['Last_Error']
+        cur.execute('SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1')
+        cur.execute('START SLAVE')
+    else:
+        time.sleep(1)
diff --git a/sbin/verify b/sbin/verify
new file mode 100755 (executable)
index 0000000..954a910
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+import time
+import MySQLdb as sql
+import MySQLdb.cursors
+
+srvs = ['kitchen-sink', 'sliced-bread']
+cxns, curs = {}, {}
+for s in srvs:
+    cxns[s] = sql.connect(s, read_default_file='~/.my.cnf', cursorclass=sql.cursors.DictCursor)
+    curs[s] = cxns[s].cursor()
+
+dbs = {}
+for s in srvs:
+    curs[s].execute('SHOW DATABASES')
+    dbs[s] = map(lambda elt: elt.values()[0], curs[s].fetchall())
+    if 'information_schema' in dbs[s]:
+        dbs[s].remove('information_schema')
+
+all = []
+for s in dbs.values():
+    all.extend(s)
+all = list(set(all))
+all.sort()
+
+from pprint import pprint
+
+for db in all:
+    if db < 'geofft':
+        continue
+    stat = {}
+    tables = []
+    keys = []
+    for s in srvs:
+        stat[s] = {}
+        curs[s].execute('SHOW TABLE STATUS FROM `%s`' % db)
+        r = curs[s].fetchall()
+        for x in r:
+            if x['Engine'] != 'MyISAM':
+                continue
+            tables.append(x['Name'])
+            stat[s][x['Name']] = x
+        keys.extend(x.keys())
+    keys = list(set(keys))
+    tables = list(set(tables))
+
+    for t in tables:
+        verified = True
+        for k in keys:
+            if k in ['Check_time', 'Comment', 'Create_time', 'Update_time']:
+                continue
+            vals = {}
+            for s in srvs:
+                if not t in stat[s]:
+                    stat[s][t] = {}
+                vals[s] = stat[s][t].get(k, None)
+            v = list(set(vals.values()))
+            if len(v) > 1:
+                print '%s.%s[%s]: %s' % (db, t, k, str(vals))
+                verified = False
+        print '%s.%s VERIFY' % (db, t), verified
This page took 0.306103 seconds and 5 git commands to generate.