X-Git-Url: http://git.roojs.org/?a=blobdiff_plain;f=Dump.php;h=4102bc16c3c16f0e8ab41a61d09c687177b31cb1;hb=HEAD;hp=18fbe6aa5a13f2ca6e9147467578c445213cf360;hpb=c9f3c56b5e3004ae0ed4f15a8aff2eddc8684f21;p=Pman.Admin diff --git a/Dump.php b/Dump.php index 18fbe6a..4102bc1 100644 --- a/Dump.php +++ b/Dump.php @@ -50,6 +50,9 @@ require_once 'Pman.php'; class Pman_Admin_Dump extends Pman { + static $cli_desc = "Dump database ?/ needs more info..."; + + function getAuth() { @@ -62,13 +65,16 @@ class Pman_Admin_Dump extends Pman { var $deps = array(); // list of dependants var $out = array(); // list of created sql/shell scripts. - function get($path ) + function get($path, $opts = Array() ) { + ini_set('memory_limit', '256M'); // we need alot of memory + set_time_limit(0); + $argv = $_SERVER['argv']; array_shift($argv); array_shift($argv); - $opts = explode(',', 'table==,where==,dump-dir==,dump-dir==,debug='); + $opts = explode(',', 'table==,where==,dump-dir==,debug='); require_once 'Console/Getopt.php'; $go = Console_Getopt::getopt2($argv, '', $opts ); if (is_object($go)) { @@ -121,6 +127,9 @@ class Pman_Admin_Dump extends Pman { if (empty($ar)) { continue; } echo " " .$tbl . ' -> ' . count(array_keys($ar)) . " Records\n"; } + echo "FILES:\n"; + echo " Total : " . $this->filetotal . " files using " . floor($this->filesize/1000000) . "Mb\n"; + echo "GENERATED FILES:\n"; // summary echo " ". implode("\n ", $this->out). "\n"; @@ -137,6 +146,8 @@ class Pman_Admin_Dump extends Pman { var $dscan = array(); // TABLE:COL => [value => TRUE|FALSE] - if its been scanned.. var $childfiles = array(); // array of [ 'sourcedirectory' , 'subdirectory(s) and filename' ] var $childthumbs = array(); // array of [ 'filename', 'filename' ,......] + var $filesize = 0; // size of files to be saved. (not total deletd..) + var $filetotal = 0; // number of distinct files to be saved (not total deleted) /** * scan table for * a) what depends on it (eg. child elements) - which will be deleted. @@ -211,6 +222,7 @@ class Pman_Admin_Dump extends Pman { } } + $x->free(); // flag as checked if we where given an array.. - as some links might have been broken. if (is_array($where)) { foreach($where as $k) { @@ -272,7 +284,7 @@ class Pman_Admin_Dump extends Pman { static $children = array(); if (!isset($children[$table])) { - + $children[$table] = array(); // force load of linsk $do->links(); foreach($_DB_DATAOBJECT['LINKS'][$do->database()] as $tbl => $links) { @@ -299,10 +311,7 @@ class Pman_Admin_Dump extends Pman { } print_R($children); } - if (empty($children[$table])) { - $children[$table] = array(); - - } + $do->selectAdd(); $key = $keys[0]; $do->selectAdd($key); @@ -313,7 +322,7 @@ class Pman_Admin_Dump extends Pman { if (!isset($this->deletes[$table][$do->$key])) { $this->deletes[$table][$do->$key] = 0; } - if (!empty($children[$table])) { + foreach($children[$table] as $kv=>$t) { if (!isset($this->dscan[$kv])) { $this->dscan[$kv] = array(); @@ -323,7 +332,7 @@ class Pman_Admin_Dump extends Pman { } } } - + $do->free(); // now iterate throught dependants. and scan them. @@ -386,6 +395,7 @@ class Pman_Admin_Dump extends Pman { fwrite($fh, "DELETE FROM `$tbl` WHERE `$key` = $id;\n"); // we assume id's and nice column names... } + $do->free(); } fclose($fh); } @@ -406,19 +416,35 @@ class Pman_Admin_Dump extends Pman { $this->out[] = $target; $fh3 = fopen($target, 'w'); - + + $done = array(); + $donedir = array(); foreach($this->childfiles as $v) { - fwrite($fh,"mkdir -p " . escapeshellarg(dirname($args['dump-dir'] .'/'.$v[1])) ."\n" ); - fwrite($fh,"cp " . escapeshellarg($v[0].'/'.$v[1]) . ' ' . escapeshellarg($args['dump-dir'] .'/'.$v[1]) ."\n" ); - fwrite($fh3,"mkdir -p " . escapeshellarg(dirname($v[0].'/'.$v[1])) ."\n" ); - fwrite($fh3,"cp " . escapeshellarg($args['dump-dir'] .'/'.$v[1]) . ' ' . escapeshellarg($v[0].'/'.$v[1]) . "\n" ); + if (isset($done[$v[1]])) { + continue; + } + + $done[$v[1]] = true; + $this->filesize += filesize($v[0].'/'.$v[1]); + $this->filetotal++; + $fdir = dirname($this->args['dump-dir'] .'/'.$v[1]); + if (!isset($donedir[$fdir])) { + fwrite($fh,"mkdir -p " . escapeshellarg(dirname($this->args['dump-dir'] .'/'.$v[1])) ."\n" ); + } + fwrite($fh,"cp " . escapeshellarg($v[0].'/'.$v[1]) . ' ' . escapeshellarg($this->args['dump-dir'] .'/'.$v[1]) ."\n" ); + if (!isset($donedir[$fdir])) { + fwrite($fh3,"mkdir -p " . escapeshellarg(dirname($v[0].'/'.$v[1])) ."\n" ); + } + $donedir[$fdir] = true; + + fwrite($fh3,"cp " . escapeshellarg($this->args['dump-dir'] .'/'.$v[1]) . ' ' . escapeshellarg($v[0].'/'.$v[1]) . "\n" ); fwrite($fh2,"rm " . escapeshellarg($v[0].'/'.$v[1]) ."\n" ); } fclose($fh); fclose($fh3); // restore does not need to bother with thumbnails. - + foreach($this->childthumbs as $v) { @@ -450,7 +476,7 @@ class Pman_Admin_Dump extends Pman { while ($do->fetch()) { fwrite($fh,$this->toInsert($do)); } - + $do->free(); } fclose($fh);