1 |
37799
|
eri.katsar
|
<?php
|
2 |
|
|
require_once('./js/log4php/Logger.php');
|
3 |
|
|
require_once('./paths.php');
|
4 |
|
|
require_once('./controller.php');
|
5 |
|
|
|
6 |
|
|
class BackupCache {
|
7 |
|
|
private $log;
|
8 |
|
|
private $cache = null;
|
9 |
|
|
|
10 |
|
|
public function __construct(){
|
11 |
|
|
|
12 |
|
|
global $redis_host;
|
13 |
|
|
global $redis_port;
|
14 |
|
|
global $redis_scheme;
|
15 |
|
|
|
16 |
|
|
global $host;
|
17 |
|
|
|
18 |
|
|
$this->log = Logger::getLogger(__CLASS__);
|
19 |
|
|
Logger::configure('./js/log4php/log4php.xml');
|
20 |
|
|
if(class_exists("Predis\Client")){
|
21 |
|
|
|
22 |
|
|
try {
|
23 |
|
|
//todo changed timeout from 0 to -1
|
24 |
|
|
$this->cache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $redis_host,"port" => $redis_port,"read_write_timeout" => -1));
|
25 |
|
|
$this->log->info("redis host: ".$redis_host." and redis port: ".$redis_port);
|
26 |
|
|
} catch(Exception $e) {
|
27 |
|
|
$this->log->error("Error connecting to Redis server: ".$e->getMessage());
|
28 |
|
|
$this->cache = null;
|
29 |
|
|
}
|
30 |
|
|
}
|
31 |
|
|
else{
|
32 |
|
|
$this->log->info("cache does not exist"); //predis
|
33 |
|
|
exit;
|
34 |
|
|
}
|
35 |
|
|
}
|
36 |
|
|
|
37 |
|
|
function backup() {
|
38 |
|
|
|
39 |
|
|
if($this->cache != null){
|
40 |
|
|
|
41 |
|
|
$this->log->info("cache exists");
|
42 |
|
|
$database = new MYDB();
|
43 |
|
|
$database->doConnect($GLOBALS['schema_file']);
|
44 |
|
|
$keys = $this->cache->keys("*");
|
45 |
|
|
|
46 |
|
|
$this->log->info(" *******************BACKING UP NUMS************************");
|
47 |
|
|
|
48 |
|
|
$numKeys=$this->cache->hkeys('STATS_NUMBERS');
|
49 |
|
|
for($x=0;$x<count($numKeys);$x++)
|
50 |
|
|
{$key=$numKeys[$x];
|
51 |
|
|
$value=$this->cache->hget('STATS_NUMBERS',$key);
|
52 |
|
|
$this->cache->hset('STATS_NUMBERS_BACKUP',$key,$value);
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
$this->log->info("All Num Entries Backed up Sucessfully!");
|
56 |
|
|
//NOW PROCEED TO CHARTS AND DATA
|
57 |
|
|
|
58 |
|
|
for($x=0;$x<count($keys);$x++) {
|
59 |
|
|
if ((strpos($keys[$x],'chart')===false)&&(strpos($keys[$x],'table')===false)&&(strpos($keys[$x],'STATS')===false))
|
60 |
|
|
{
|
61 |
|
|
try
|
62 |
|
|
{
|
63 |
|
|
$query = $this->cache->hget($keys[$x],'query');
|
64 |
|
|
$persistent= $this->cache->hget($keys[$x],'persistent');
|
65 |
38202
|
eri.katsar
|
if($query!=null)
|
66 |
37799
|
eri.katsar
|
{ $this->log->info("going tobackup the results for query ".$query );
|
67 |
|
|
$fetchMode = $this->cache->hget($keys[$x], 'fetchMode');
|
68 |
|
|
if($fetchMode==null){ $fetchMode=3; }
|
69 |
|
|
$shadowResults =$this->cache->hget($keys[$x],'shadow');
|
70 |
|
|
$result = $this->cache->hget($keys[$x], 'results');
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
$this->cache->hmset($keys[$x],array("results" => $result, "query" =>$query,"persistent" => $persistent,"shadow" => $shadowResults, "fetchMode" => $fetchMode, "backup" => $result));
|
74 |
|
|
$this->log->info("Stored Entry : ");
|
75 |
|
|
$this->log->info("backup ".$this->cache->hget($keys[$x],'backup'));
|
76 |
|
|
}
|
77 |
|
|
}catch(Exception $e) {
|
78 |
|
|
$this->log->error('Error : '.$e->getMessage()); }
|
79 |
|
|
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
else
|
83 |
|
|
{$this->log->info("Ignoring chart key: ".$keys[$x]); }
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
$database->doDisconnect();
|
87 |
|
|
$this->log->info("Finished Backup! : ");
|
88 |
|
|
}
|
89 |
|
|
}
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
?>
|