From d978d0051b227f8d612a2567f0f3d3ef601a2220 Mon Sep 17 00:00:00 2001 From: Joe Presbrey Date: Sun, 18 May 2008 21:20:32 +0000 Subject: [PATCH] backups write to partitionable AFS volume structure git-svn-id: svn://presbrey.mit.edu/sql@157 a142d4bd-2cfb-0310-9673-cb33a7e74f58 --- libexec/afs-renew-tickets.sh | 2 +- libexec/afs-run-backup.php | 55 ++++++++++++++++++--------------- libexec/afs-set-permissions.php | 2 +- 3 files changed, 32 insertions(+), 27 deletions(-) diff --git a/libexec/afs-renew-tickets.sh b/libexec/afs-renew-tickets.sh index 076331e..6f3acd6 100755 --- a/libexec/afs-renew-tickets.sh +++ b/libexec/afs-renew-tickets.sh @@ -1,4 +1,4 @@ #!/bin/bash -/usr/kerberos/bin/kinit -k -t /root/keytab-sql.mit.edu daemon/sql.mit.edu +/usr/kerberos/bin/kinit -k -t /root/.keytab-sql.mit.edu daemon/sql.mit.edu /usr/bin/aklog diff --git a/libexec/afs-run-backup.php b/libexec/afs-run-backup.php index 609819a..62572bc 100755 --- a/libexec/afs-run-backup.php +++ b/libexec/afs-run-backup.php @@ -1,7 +1,8 @@ #!/usr/bin/env php &1"; -//$dump_exec = "$bin_mysqldump -CefqQK --result-file=$dump_path/%s %s 2>&1"; -/* great from linerva: -$dump_exec = "$bin_mysqldump -CefqQK %s | gzip > $dump_path/%s.sql.gz "; - */ +$partition_path='/afs/athena.mit.edu/contrib/sql/.backup'; $dump_exec = "$bin_mysqldump -efqQK %s | gzip > $dump_path/%s.sql.gz "; $dump_host=':/srv/mysql/mysql.sock'; $dump_user='mit-backup'; @@ -27,12 +24,12 @@ $sql_resource = mysql_connect($dump_host,$dump_user,$dump_pass); $sql_databases = mysql_list_dbs($sql_resource); $stat['nDatabases'] = mysql_num_rows($sql_databases); -@unlink("$dump_path/.skipped"); +@unlink("$partition_path/skipped"); while($row1 = mysql_fetch_row($sql_databases)) { if ($row1[0] == 'information_schema') continue; if (preg_match('/[^a-z0-9\+_.-]+/i', $row1[0])) { - $f = fopen("$dump_path/.skipped",'w'); + $f = fopen("$partition_path/skipped",'a'); fwrite($f, "{$row1[0]}\n"); fclose($f); } @@ -44,29 +41,37 @@ $time[1][0] = microtime(true); foreach($databases as $name=>$info) { if (in_array($name, $EXCEPTIONS)) { if (!BACKUP_CRON) - printf('Skipping EXCEPTIONed database: %s', $name); + printf("Skipping database: %s\n", $name); continue; + } else { + if (!BACKUP_CRON) + printf("Dumping database: %s\n", $name); } if (stristr($name,'+')) { - $owner = array_shift(explode('+',$name)).'/'; - @mkdir("$dump_path/$owner"); - `fs sa $dump_path/$owner $owner rl 2>/dev/null`; - `fs sa $dump_path/$owner system:authuser none`; + $owner = array_shift(explode('+',$name)); } else { - $owner = 'root/'; - @mkdir("$dump_path/$owner"); - `fs sa $dump_path/$owner system:authuser none`; - `fs sa $dump_path/$owner system:sql-backup none`; + $owner = 'root'; } - $exec = sprintf($dump_exec, $name, $owner.$name); - - if ($owner!='root' && file_exists("$dump_path/$owner$name.sql.gz")) { + if (!is_link($dump_path.'/'.$owner)) { + symlink($partition_path.'/'.substr($owner,0,1).'/'.$owner, $dump_path.'/'.$owner); + } + if (!is_dir(readlink($dump_path.'/'.$owner))) { + mkdir(readlink($dump_path.'/'.$owner)); + } + `fs sa $dump_path/$owner/ system:anyuser none`; + `fs sa $dump_path/$owner/ system:authuser none`; + if ($owner == 'root') { + `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"); + "$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, diff --git a/libexec/afs-set-permissions.php b/libexec/afs-set-permissions.php index af410b9..357dd0f 100755 --- a/libexec/afs-set-permissions.php +++ b/libexec/afs-set-permissions.php @@ -15,7 +15,7 @@ foreach($g as $locker) { $filsys_type = 'unknown'; if (!isset($logs[$filsys_type])) - $logs[$filsys_type] = fopen('.'.$filsys_type, 'w'); + $logs[$filsys_type] = fopen('/mit/sql/.backup/'.$filsys_type, 'w'); fwrite($logs[$filsys_type], "$locker\n"); -- 2.45.1