From b8a56fc395a50f814f336f3a9156ee05f59cfcb9 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 29 Sep 2020 20:12:48 -0400 Subject: [PATCH 1/4] Switch to using a supported interface for filename conversion --- mysqlname.c | 34 ---------------------------------- mysqlshow.py | 5 +++-- run-afs.sh | 7 +++---- 3 files changed, 6 insertions(+), 40 deletions(-) delete mode 100644 mysqlname.c 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..f13df88 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 AS `Database`, cast(CONVERT(SCHEMA_NAME USING filename) as binary) AS `Filename` FROM INFORMATION_SCHEMA.SCHEMATA') +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..39ced64 100755 --- a/run-afs.sh +++ b/run-afs.sh @@ -26,12 +26,11 @@ while [ $kstartret -ne 0 ]; do # 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=$(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" From 9565df683f45ede6defbaf8994d7dbd58f755dbb Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 29 Sep 2020 20:34:13 -0400 Subject: [PATCH 2/4] Import unknown changes from primary-key --- run-afs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-afs.sh b/run-afs.sh index 39ced64..e9aa967 100755 --- a/run-afs.sh +++ b/run-afs.sh @@ -31,7 +31,7 @@ while [ $kstartret -ne 0 ]; do [[ "$db" == *+* ]] || continue # Figure out the size size=$(du -s ${base}/"$filename" | awk '{print $1}') - [ $size -gt $max_size ] && echo "Skipping $db" && continue + [ "$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 From 9547cb316af62b26fb69145a8a0a9dab7b5eb32c Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Fri, 2 Oct 2020 00:51:43 -0400 Subject: [PATCH 3/4] Modern k5start doesn't take units on -K --- run-afs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-afs.sh b/run-afs.sh index e9aa967..f2a86c8 100755 --- a/run-afs.sh +++ b/run-afs.sh @@ -22,7 +22,7 @@ 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 From 1dba8efc880c85bc6584fc88b64073dbf8e3be73 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Fri, 2 Oct 2020 01:14:56 -0400 Subject: [PATCH 4/4] Backup databases in ascending order --- mysqlshow.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysqlshow.py b/mysqlshow.py index f13df88..8959104 100755 --- a/mysqlshow.py +++ b/mysqlshow.py @@ -5,7 +5,7 @@ db = MySQLdb.connect(read_default_file='~/.my.cnf') cursor = db.cursor() -cursor.execute('SELECT SCHEMA_NAME AS `Database`, cast(CONVERT(SCHEMA_NAME USING filename) as binary) AS `Filename` FROM INFORMATION_SCHEMA.SCHEMATA') +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')