#!/usr/bin/env php
<?php
-$EXCEPTIONS[] = 'presbrey+aol';
+$EXCEPTIONS = explode("\n",file_get_contents('/mit/sql/etc/db_no-daily-backup'));
+$EXCEPTIONS = array_filter($EXCEPTIONS, 'strlen');
ini_set('memory_limit', '-1');
set_time_limit(0);
define('BACKUP_RUN_STATS', 0);
define('BACKUP_CRON', 1);
-$bin_mysql='mysql -umit-backup';// --defaults-file=/afs/athena.mit.edu/user/p/r/presbrey/web/etc/sql-mit-edu.my.cnf';
-$bin_mysqldump='mysqldump -umit-backup';// --defaults-file=/afs/athena.mit.edu/user/p/r/presbrey/web/etc/sql-mit-edu.my.cnf';
+$bin_mysql='mysql -umit-backup';
+$bin_mysqldump='mysqldump -umit-backup';
$dump_path='/afs/athena.mit.edu/contrib/sql/backup';
-//$dump_exec = "$bin_mysqldump -CefqQK --single-transaction --result-file=$dump_path/%s %s 2>&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';
$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);
}
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,