X-Git-Url: http://andersk.mit.edu/gitweb/sql.git/blobdiff_plain/8145dbcc1f707acb781583a288f55923866d6be2..562fda3a64d1be930e5bed51464ea30c525bc566:/libexec/afs-run-backup.php diff --git a/libexec/afs-run-backup.php b/libexec/afs-run-backup.php index eb27cbd..64cadd1 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='localhost'; +$dump_host=':/srv/mysql/mysql.sock'; $dump_user='mit-backup'; $dump_pass=''; $sql_resource = mysql_connect($dump_host,$dump_user,$dump_pass); @@ -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,36 +41,36 @@ $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 (!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"); + $ownerl = strtolower($owner); + if (!is_link($dump_path.'/'.$owner)) { + symlink($partition_path.'/'.substr($ownerl,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 (!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');