From: Joe Presbrey Date: Thu, 25 Sep 2008 13:57:09 +0000 (+0000) Subject: more old code X-Git-Url: http://andersk.mit.edu/gitweb/sql.git/commitdiff_plain/562fda3a64d1be930e5bed51464ea30c525bc566 more old code git-svn-id: svn://presbrey.mit.edu/sql@164 a142d4bd-2cfb-0310-9673-cb33a7e74f58 --- diff --git a/etc/nagios/nrpe.cfg b/etc/nagios/nrpe.cfg new file mode 100644 index 0000000..1f1d3f4 --- /dev/null +++ b/etc/nagios/nrpe.cfg @@ -0,0 +1,29 @@ +pid_file=/var/run/nrpe.pid +server_port=5666 +#server_address=192.168.1.1 +nrpe_user=nrpe +nrpe_group=nrpe +#allowed_hosts=18.187.1.128,18.181.0.65 +dont_blame_nrpe=1 +debug=0 +command_timeout=60 +connection_timeout=300 +#command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10 +#command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20 +#command[check_disk1]=/usr/lib64/nagios/plugins/check_disk -w 20 -c 10 -p /dev/hda1 +#command[check_disk2]=/usr/lib64/nagios/plugins/check_disk -w 20 -c 10 -p /dev/hdb1 +#command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z +#command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200 +command[check_users]=/usr/lib64/nagios/plugins/check_users -w $ARG1$ -c $ARG2$ +command[check_load]=/usr/lib64/nagios/plugins/check_load -w $ARG1$ -c $ARG2$ +command[check_disk]=/usr/lib64/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -x /usr/vice/cache +command[check_disk_p]=/usr/lib64/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$ +command[check_procs]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ +command[check_procs_C]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -C $ARG3$ +command[check_procs_P]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -P $ARG3$ +command[check_procs_m]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -m $ARG3$ +command[check_procs_s]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$ +command[check_procs_u]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -u $ARG3$ +command[check_procs_z]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -z $ARG3$ +command[check_mysql]=/usr/lib64/nagios/plugins/check_mysql -u $ARG1$ -p $ARG2$ +command[check_mysql_S]=/usr/lib64/nagios/plugins/check_mysql -S -u $ARG1$ -p $ARG2$ diff --git a/etc/rc.local b/etc/rc.local new file mode 100755 index 0000000..dda6cd8 --- /dev/null +++ b/etc/rc.local @@ -0,0 +1,12 @@ +#!/bin/sh +# +# This script will be executed *after* all the other init scripts. +# You can put your own initialization stuff in here if you don't +# want to do the full Sys V style init stuff. + +touch /var/lock/subsys/local + +if [[ -s /srv/mysql/master.info ]]; then + /sbin/ifdown eth0:0 + /sbin/ifdown eth1:0 +fi diff --git a/etc/my.cnf b/etc/sliced-bread/my.cnf similarity index 88% rename from etc/my.cnf rename to etc/sliced-bread/my.cnf index 905549d..692a795 100644 --- a/etc/my.cnf +++ b/etc/sliced-bread/my.cnf @@ -24,8 +24,8 @@ open_files_limit=8192 log-bin=sql-bin log-bin-index=sql-bin.index -relay-log=kitchen-sink-relay-bin -relay-log-index=kitchen-sink-relay-bin.index +relay-log=sliced-bread-relay-bin +relay-log-index=sliced-bread-relay-bin.index query_cache_limit=1M query_cache_size=128M @@ -45,15 +45,14 @@ myisam_sort_buffer_size=64M innodb_buffer_pool_size=512M innodb_additional_mem_pool_size=20M -innodb_log_file_size=256M +innodb_log_file_size=128M innodb_log_buffer_size=8M innodb_lock_wait_timeout=50 innodb_thread_concurrency=4 -innodb_log_group_home_dir=/srv/zebra/ innodb_file_per_table old_passwords=1 -server-id=1 +server-id=2 ssl_ca=/etc/pki/tls/certs/ca.pem ssl_cert=/etc/pki/tls/certs/sql.pem diff --git a/lib/python/sql/__init__.py b/lib/python/sql/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/python/sql/db.py b/lib/python/sql/db.py new file mode 100755 index 0000000..70e1ad4 --- /dev/null +++ b/lib/python/sql/db.py @@ -0,0 +1,11 @@ +from elixir import Entity, Field, String, Integer, DateTime, options, metadata, setup_all, session +from sqlalchemy import create_engine, func +options.options_defaults['shortnames'] = True + +metadata.bind = create_engine('mysql://sql.mit.edu/mitsql?read_default_group=mysql', pool_recycle=True) + +if __name__ == '__main__': + setup_all(True) +else: + setup_all() +session.flush() diff --git a/lib/python/sql/util.py b/lib/python/sql/util.py new file mode 100755 index 0000000..7f05b20 --- /dev/null +++ b/lib/python/sql/util.py @@ -0,0 +1,57 @@ +#!/usr/bin/python + +def get_backup_exceptions(path='/mit/sql/etc/db_no-daily-backup'): + return filter(len, map(str.strip, file(path).read().split('\n'))) + +import MySQLdb, MySQLdb.cursors + +def use_db(cursor, db): + cursor.execute('USE `%s`' % db) + +def get_dbs(cursor): + cursor.execute('SHOW DATABASES') + return [x.values()[0] for x in cursor.fetchall() if x.values()[0] != 'information_schema'] + +def get_db_tables(cursor, db): + cursor.execute('SHOW TABLES FROM `%s`' % db) + return [(db, x.values()[0]) for x in cursor.fetchall()] + +def get_db_tables_ft(cursor, db): + r = [] + for table in get_db_tables(cursor, db): + cursor.execute('SHOW INDEXES FROM `%s`.`%s`' % table) + r.extend(set([(db, x['Table']) for x in cursor.fetchall() if x['Index_type'] == 'FULLTEXT'])) + return r + +def get_db_tables_status(cursor, db): + cursor.execute('SHOW TABLE STATUS FROM `%s`' % db) + return dict([((db, x['Name']), x) for x in cursor.fetchall()]) + +def get_db_tables_engines(cursor, db): + return [(table, status['Engine']) for table, status in get_db_tables_status(cursor, db).items()] + +def repair_table_quick(cursor, table): + # REPAIR TABLE tbl QUICK + # works when changing ft_min_word_len + cursor.execute('REPAIR TABLE `%s`.`%s` QUICK' % table) + +if __name__ == '__main__': + import sys + + cursor = MySQLdb.connect('localhost', read_default_group='client', cursorclass=MySQLdb.cursors.DictCursor).cursor() + #for db in get_dbs(cursor): + # for table in get_db_tables_ft(cursor, db): + # print table + + #db = 'freeculture+youtomb' + #print get_db_tables_status(cursor, db) + #sys.exit(0) + + while True: + data = sys.stdin.readline() + if not data: + break + data = data.strip() + table = eval(data) + print table + repair_table_quick(cursor, table) diff --git a/libexec/afs-run-backup.php b/libexec/afs-run-backup.php index 6c9b75d..64cadd1 100755 --- a/libexec/afs-run-backup.php +++ b/libexec/afs-run-backup.php @@ -65,21 +65,12 @@ foreach($databases as $name=>$info) { `fs sa $dump_path/$owner/ system:sql-backup none`; } $exec = sprintf($dump_exec, $name, $owner.'/'.$name); -/* - if ($owner != 'root' && file_exists("$dump_path/$owner/$name.sql.gz")) { - if (!BACKUP_CRON) - printf("Saving old dump file: %s\n", - "$dump_path/$owner/$name.sql.gz"); - rename("$dump_path/$owner/$name.sql.gz", "$dump_path/OLD/$name.sql.gz"); - } -*/ if (!BACKUP_CRON) printf("Dumping %d of %d / %d%% (%s):\n", $i_database, $stat['nDatabases'], $i_database/$stat['nDatabases']*100, $name); - //printf("Executing $exec\n"); $time[$name][0] = microtime(true); $dump_proc = popen($exec, 'r'); diff --git a/libexec/backup-policy.py b/libexec/backup-policy.py new file mode 100755 index 0000000..94e97c3 --- /dev/null +++ b/libexec/backup-policy.py @@ -0,0 +1,29 @@ +#!/usr/bin/python + +import os, re, sys +from time import strptime +from glob import glob + +PATH = os.path.abspath(sys.argv[1]) +backups = glob('%s/weekly/*.gz' % PATH) +backups.sort() +backups.reverse() +backups = [[x, re.match('.*(\d\d\d\d-\d\d-\d\d).*', x)] for x in backups] +backups = [[x[0], strptime(x[1].groups()[0], '%Y-%m-%d')] for x in backups] + +keep = backups[:4] +backups = backups[4:] +monthlys = {} +for x in backups: + month = (x[1].tm_year, x[1].tm_mon) + if month not in monthlys: + monthlys[month] = x + if len(monthlys) > 5: + break +keep.extend(monthlys.values()) + +for x in backups: + if not x in keep: + print 'rm %s' % x[0] + else: + print '# keeping %s' % x[0] diff --git a/libexec/backup-rename.py b/libexec/backup-rename.py new file mode 100755 index 0000000..8254935 --- /dev/null +++ b/libexec/backup-rename.py @@ -0,0 +1,11 @@ +#!/usr/bin/python + +import os, re, sys +from glob import glob + +PATH = os.path.abspath(sys.argv[1]) +for x in glob('%s/weekly/*.gz' % PATH): + m = re.match('(.+)(\d\d-\d\d)-(\d\d\d\d)(.+)', x) + if m: + g = m.groups() + os.rename(x, '%s%s-%s%s' % (g[0], g[2], g[1], g[3]))