My favorites | Sign in
Project Home Downloads Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /usr/local/bin/php
<?php
//$sortOptions .= "v::";
function shift($options_array)
{
foreach( $options_array as $o => $a ) {
while($k=array_search("-". $o. $a, $GLOBALS['argv'])) {
if($k) {
unset($GLOBALS['argv'][$k]);
}
}
while($k=array_search("-" . $o, $GLOBALS['argv'])) {
if($k) {
unset($GLOBALS['argv'][$k]);
unset($GLOBALS['argv'][$k+1]);
}
}
}
$GLOBALS['argv'] = array_merge($GLOBALS['argv']);
}
$nok = "\033[31;1m[NOK] \033[0m";
$ok = "\033[32m[OK] \033[0m";

$shortopts = "";
$shortopts .= "s:";
$shortopts .= "f:";
$shortopts .= "t:";
$shortopts .= "a:";
$shortopts .= "c:";

try {
$options = getopt($shortopts);

$schema = !array_key_exists('s', $options) ?: $options['s'];
$from = !array_key_exists('f', $options) ?: $options['f'];
$to = !array_key_exists('t', $options) ?: $options['t'];
$action = !array_key_exists('a', $options) ?: $options['a'];

if (array_key_exists('c', $options)) {
$configFile = $options['c'];
} else {
$configFile = dirname(__FILE__) . DIRECTORY_SEPARATOR ."conf.ini";
}
if (!is_file($configFile)) {
throw new Exception("Config file ({$configFile}) not found");
}

$conf = parse_ini_file($configFile, true);

if (array_key_exists($from, $conf)) {
$master = $conf[$from];
} else {
throw new Exception("unknow 'from' database '{$from}' ");
}

include("lib/Pgdbsync/includes.php");
//use \Pgdbsync;

$dbVc = new \Pgdbsync\Db();
$dbVc->setMasrer(new \Pgdbsync\DbConn($master));
if ($to == 'all') {
foreach ($conf as $key => $slave) {
if ($key != $from) {
$dbVc->setSlave(new \Pgdbsync\DbConn($slave));
}
}
} else {
if (array_key_exists($to, $conf)) {
$slave = $conf[$to];
} else {
throw new Exception("unknow 'to' database '{$to}' ");
}
$dbVc->setSlave(new \Pgdbsync\DbConn($slave));
}

switch ($action) {
case 'diff':
echo $dbVc->diff($schema);
break;
case 'summary':
echo $dbVc->summary($schema);
break;
case 'run':
$array = $dbVc->run($schema);
foreach ($array as $host => $errors) {
echo $host . "\n";
foreach ($errors as $error) {
echo $nok . " " . $error[1] . "\n";
echo "----" . "\n";
echo $error[0] . "\n";
}
echo "\n";
}
break;
case 'raw':
$array = $dbVc->raw($schema);
break;
}
echo "\n" . $ok . " end process\n";
} catch (Exception $e) {
echo $nok . " " . $e->getMessage() . "\n";
}

Change log

ad056e8704f0 by gonzalo123 on Dec 12, 2010   Diff
different bugs ans cli renamed to pgdbsync
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 2523 bytes, 102 lines
Powered by Google Project Hosting