diff --git a/mysqlname.c b/mysqlname.c deleted file mode 100644 index ed93196..0000000 --- a/mysqlname.c +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef MYSQL_NAME_C -#define MYSQL_NAME_C - -#include -#include -#include -#include -#include -#include - -typedef unsigned int uint; -uint tablename_to_filename(const char *from, char *to, uint to_length); -extern CHARSET_INFO *system_charset_info; - -int -main(int argc, char* argv[]) { - char out[1024]; - memset(out, '\0', sizeof(out)); - - /* Must be initialized early for comparison of service name */ - system_charset_info= &my_charset_utf8_general_ci; - - if (argc != 2) { - fprintf(stderr, "Please specify a database name\n"); - return 1; - } - - tablename_to_filename(argv[1], out, sizeof(out)); - printf("%s\n", out); - - return 0; -} - -#endif diff --git a/mysqlshow.py b/mysqlshow.py index 25bc972..8959104 100755 --- a/mysqlshow.py +++ b/mysqlshow.py @@ -5,6 +5,7 @@ db = MySQLdb.connect(read_default_file='~/.my.cnf') cursor = db.cursor() -cursor.execute('SHOW DATABASES') -for (database,) in cursor: +cursor.execute('SELECT SCHEMA_NAME, cast(CONVERT(SCHEMA_NAME USING filename) as binary) FROM INFORMATION_SCHEMA.SCHEMATA ORDER BY SCHEMA_NAME ASC') +for (database, filename) in cursor: print(database, end='\0') + print(filename, end='\0') diff --git a/run-afs.sh b/run-afs.sh index a6a5f16..f2a86c8 100755 --- a/run-afs.sh +++ b/run-afs.sh @@ -22,17 +22,16 @@ kstartret=1 while [ $kstartret -ne 0 ]; do ( flock --exclusive 200 - k5start -f /etc/daemon.keytab -u daemon/sql.mit.edu -t -K 15m -l6h -b -p "$kstartpid" || exit 1 + k5start -f /etc/daemon.keytab -u daemon/sql.mit.edu -t -K 15 -l 6h -b -p "$kstartpid" || exit 1 # If we get here, we're under both the lock and the k5start # Get a list of all the mysql databases - mysqlshow.py | while read -d $'\0' db; do + mysqlshow.py | while read -d $'\0' db; read -d $'\0' filename; do # Make sure the database is in the form username+db - echo "$db" | grep -q '+' - [ $? -ne 0 ] && continue + [[ "$db" == *+* ]] || continue # Figure out the size - size=$(du -s ${base}/$(mysqlname "$db") | awk '{print $1}') - [ $size -gt $max_size ] && echo "Skipping $db" && continue + size=$(du -s ${base}/"$filename" | awk '{print $1}') + [ "$size" -gt "$max_size" ] && echo "Skipping $db" && continue user="${db%%+*}" sql-backup.py --local -c sql.mit.edu-afs.json --user="$user" --database="$db" done