Integration of backup/restore with storageServer.
Janos, please, check your tests.
This commit is contained in:
parent
5c2677c841
commit
eb41c67fb6
4 changed files with 58 additions and 23 deletions
|
@ -9,10 +9,10 @@ echo "backup2.sh: create tarball $1 to $2"
|
||||||
echo "backup2.sh: status: #$3#"
|
echo "backup2.sh: status: #$3#"
|
||||||
echo "<=="
|
echo "<=="
|
||||||
echo -n "working" > $3;
|
echo -n "working" > $3;
|
||||||
touch $2 || { echo -n "fail" > $3; exit 1; }
|
touch $2 || { echo -n "fault" > $3; exit 1; }
|
||||||
#sleep 120
|
#sleep 120
|
||||||
cd $1
|
cd $1
|
||||||
tar cf $2 * || { echo -n "fail" > $3; exit 1; }
|
tar cf $2 * || { echo -n "fault" > $3; exit 1; }
|
||||||
chmod 666 $2
|
chmod 666 $2
|
||||||
|
|
||||||
echo -n "success" > $3
|
echo -n "success" > $3
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
require_once dirname(__FILE__).'/../var/Restore.php';
|
require_once dirname(__FILE__).'/../var/Restore.php';
|
||||||
include_once 'DB.php';
|
include_once 'DB.php';
|
||||||
|
|
||||||
|
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||||
$dbc = DB::connect($config['dsn'], TRUE);
|
$dbc = DB::connect($config['dsn'], TRUE);
|
||||||
if (DB::isError($dbc)) {
|
if (DB::isError($dbc)) {
|
||||||
die($dbc->getMessage());
|
die($dbc->getMessage());
|
||||||
|
|
|
@ -33,7 +33,7 @@ class Backup
|
||||||
/**
|
/**
|
||||||
* array - array of affected filenames
|
* array - array of affected filenames
|
||||||
*/
|
*/
|
||||||
var $filenames;
|
var $filenames = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* string - base tmp name
|
* string - base tmp name
|
||||||
|
@ -101,12 +101,14 @@ class Backup
|
||||||
$this->criteria = $criteria;
|
$this->criteria = $criteria;
|
||||||
|
|
||||||
# get ids (and real filenames) which files match with criteria
|
# get ids (and real filenames) which files match with criteria
|
||||||
$this->setIDs($this->gb->localSearch($this->criteria,$this->sessid));
|
$srch = $r = $this->gb->localSearch($this->criteria,$this->sessid);
|
||||||
|
if(PEAR::isError($r)){ return $r; }
|
||||||
|
$this->setIDs($srch);
|
||||||
#echo '<XMP>this->ids:'; print_r($this->ids); echo '</XMP>';
|
#echo '<XMP>this->ids:'; print_r($this->ids); echo '</XMP>';
|
||||||
|
|
||||||
# get real filenames
|
# get real filenames
|
||||||
if (is_array($this->ids)) {
|
if (is_array($this->ids)) {
|
||||||
$this->setFileNames();
|
$this->setFilenames();
|
||||||
#echo '<XMP>this->filenames:'; print_r($this->filenames); echo '</XMP>';
|
#echo '<XMP>this->filenames:'; print_r($this->filenames); echo '</XMP>';
|
||||||
|
|
||||||
$this->setEnviroment(true);
|
$this->setEnviroment(true);
|
||||||
|
@ -246,7 +248,8 @@ class Backup
|
||||||
$this->addLogItem("-I- ".date("Ymd-H:i:s")." setFilenames\n");
|
$this->addLogItem("-I- ".date("Ymd-H:i:s")." setFilenames\n");
|
||||||
}
|
}
|
||||||
if (is_array($this->ids)) {
|
if (is_array($this->ids)) {
|
||||||
foreach ($this->ids as $gunid) {
|
foreach ($this->ids as $i=>$item) {
|
||||||
|
$gunid = $item['gunid'];
|
||||||
# get a stored file object of this gunid
|
# get a stored file object of this gunid
|
||||||
$sf = $r = StoredFile::recallByGunid($this->gb, $gunid);
|
$sf = $r = StoredFile::recallByGunid($this->gb, $gunid);
|
||||||
if(PEAR::isError($r)) return $r;
|
if(PEAR::isError($r)) return $r;
|
||||||
|
|
|
@ -28,7 +28,8 @@ class Restore {
|
||||||
/**
|
/**
|
||||||
* string - loglevel
|
* string - loglevel
|
||||||
*/
|
*/
|
||||||
var $loglevel = 'warn'; # 'debug';
|
var $loglevel = 'warn';
|
||||||
|
#var $loglevel = 'debug';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* greenbox object reference
|
* greenbox object reference
|
||||||
|
@ -73,7 +74,8 @@ class Restore {
|
||||||
|
|
||||||
//call the restore script in background
|
//call the restore script in background
|
||||||
$command = dirname(__FILE__).'/../bin/restore.php';
|
$command = dirname(__FILE__).'/../bin/restore.php';
|
||||||
$params = "{$backup_file} {$this->statusFile} {$this->token} {$sessid}>> /dev/null &";
|
$runLog = "/dev/null";
|
||||||
|
$params = "{$backup_file} {$this->statusFile} {$this->token} {$sessid}>> $runLog &";
|
||||||
system("$command $params");
|
system("$command $params");
|
||||||
|
|
||||||
return array('token'=>$this->token);
|
return array('token'=>$this->token);
|
||||||
|
@ -115,7 +117,7 @@ class Restore {
|
||||||
$this->setEnviroment();
|
$this->setEnviroment();
|
||||||
$this->rRmDir($this->tmpDir);
|
$this->rRmDir($this->tmpDir);
|
||||||
unlink($this->statusFile);
|
unlink($this->statusFile);
|
||||||
return !is_file($this->stausFile);
|
return !is_file($this->statusFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -151,11 +153,20 @@ class Restore {
|
||||||
#$this->addLogItem('metafiles:'.print_r($this->metafiles,true));
|
#$this->addLogItem('metafiles:'.print_r($this->metafiles,true));
|
||||||
//add to storage server
|
//add to storage server
|
||||||
foreach ($this->metafiles as $info) {
|
foreach ($this->metafiles as $info) {
|
||||||
$this->addFileToStorage($info['file'],$info['type'],$info['id']);
|
$r = $this->addFileToStorage($info['file'],$info['type'],$info['id']);
|
||||||
|
if(PEAR::isError($r)){
|
||||||
|
$this->addLogItem("-E- ".date("Ymd-H:i:s").
|
||||||
|
" startRestore - addFileToStorage \n".
|
||||||
|
"(".$put->getMessage()."/".$put->getUserInfo().")\n"
|
||||||
|
);
|
||||||
|
file_put_contents($this->statusFile, 'fault');
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->addLogItem("-E- ".date("Ymd-H:i:s")." startRestore - invalid archive format\n");
|
$this->addLogItem("-E- ".date("Ymd-H:i:s")." startRestore - invalid archive format\n");
|
||||||
file_put_contents($this->statusFile, 'fault');
|
file_put_contents($this->statusFile, 'fault');
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
file_put_contents($this->statusFile, 'success');
|
file_put_contents($this->statusFile, 'success');
|
||||||
}
|
}
|
||||||
|
@ -204,18 +215,28 @@ class Restore {
|
||||||
}
|
}
|
||||||
require_once "XmlParser.php";
|
require_once "XmlParser.php";
|
||||||
$tree = XmlParser::parse($file);
|
$tree = XmlParser::parse($file);
|
||||||
$id = $this->gb->_idFromGunid($gunid);
|
|
||||||
$mediaFileLP = str_replace('.xml','',$file);
|
$mediaFileLP = str_replace('.xml','',$file);
|
||||||
$mediaFileLP = ($type=='audioClip' && is_file($mediaFileLP))?$mediaFileLP:'';
|
$mediaFileLP = ($type=='audioClip' && is_file($mediaFileLP))?$mediaFileLP:'';
|
||||||
if (!PEAR::isError($this->gb->existsFile($this->sessid,$gunid))) { // file is exists in storage server
|
$ex = $r = $this->gb->existsFile($this->sessid,$gunid);
|
||||||
|
if (PEAR::isError($r)) {
|
||||||
|
$this->addLogItem("-E- ".date("Ymd-H:i:s").
|
||||||
|
" addFileToStorage - existsFile($gunid) ".
|
||||||
|
"(".$r->getMessage()."/".$r->getUserInfo().")\n"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (!PEAR::isError($ex) && $ex) { // file is exists in storage server
|
||||||
//replace it
|
//replace it
|
||||||
|
$id = $this->gb->_idFromGunid($gunid);
|
||||||
$replace = $this->gb->replaceFile(
|
$replace = $this->gb->replaceFile(
|
||||||
$id, # id int, virt.file's local id
|
$id, # id int, virt.file's local id
|
||||||
$mediaFileLP, # mediaFileLP string, local path of media file
|
$mediaFileLP, # mediaFileLP string, local path of media file
|
||||||
$file, # mdataFileLP string, local path of metadata file
|
$file, # mdataFileLP string, local path of metadata file
|
||||||
$this->sessid); # sessid string, session id
|
$this->sessid); # sessid string, session id
|
||||||
if (PEAR::isError($replace)) {
|
if (PEAR::isError($replace)) {
|
||||||
$this->addLogItem("-E- ".date("Ymd-H:i:s")." addFileToStorage - replaceFile Error\n");
|
$this->addLogItem("-E- ".date("Ymd-H:i:s").
|
||||||
|
" addFileToStorage - replaceFile Error ".
|
||||||
|
"(".$replace->getMessage()."/".$replace->getUserInfo().")\n"
|
||||||
|
);
|
||||||
file_put_contents($this->statusFile, 'fault');
|
file_put_contents($this->statusFile, 'fault');
|
||||||
return $replace;
|
return $replace;
|
||||||
}
|
}
|
||||||
|
@ -225,6 +246,13 @@ class Restore {
|
||||||
$parid = $this->gb->_getHomeDirIdFromSess($this->sessid);
|
$parid = $this->gb->_getHomeDirIdFromSess($this->sessid);
|
||||||
#$this->addLogItem("Parid:$parid\n");
|
#$this->addLogItem("Parid:$parid\n");
|
||||||
$name = $tree->children[0]->children[0]->content;
|
$name = $tree->children[0]->children[0]->content;
|
||||||
|
if(empty($name)) $name = $tree->attrs['title']->val;
|
||||||
|
if(empty($name)) $name = '???';
|
||||||
|
if ($this->loglevel=='debug') {
|
||||||
|
$this->addLogItem("-I- ".date("Ymd-H:i:s")." putFile\n".
|
||||||
|
"$parid, $name, $mediaFileLP, $file, {$this->sessid}, $gunid, $type \n"
|
||||||
|
);
|
||||||
|
}
|
||||||
$put = $this->gb->putFile(
|
$put = $this->gb->putFile(
|
||||||
$parid, # parent id
|
$parid, # parent id
|
||||||
$name, # name of original file
|
$name, # name of original file
|
||||||
|
@ -232,23 +260,24 @@ class Restore {
|
||||||
$file, # meta file
|
$file, # meta file
|
||||||
$this->sessid, # sessid
|
$this->sessid, # sessid
|
||||||
$gunid, # gunid
|
$gunid, # gunid
|
||||||
$type); # type
|
$type # type
|
||||||
|
);
|
||||||
# $this->addLogItem("add as new \n");
|
# $this->addLogItem("add as new \n");
|
||||||
if (PEAR::isError($put)) {
|
if (PEAR::isError($put)) {
|
||||||
$this->addLogItem("-E- ".date("Ymd-H:i:s")." addFileToStorage - putFile Error\n");
|
$this->addLogItem("-E- ".date("Ymd-H:i:s").
|
||||||
|
" addFileToStorage - putFile Error ".
|
||||||
|
"(".$put->getMessage()."/".$put->getUserInfo().")\n"
|
||||||
|
."\n---\n".file_get_contents($file)."\n---\n"
|
||||||
|
);
|
||||||
file_put_contents($this->statusFile, 'fault');
|
file_put_contents($this->statusFile, 'fault');
|
||||||
//$this->addLogItem("Error Object: ".print_r($put,true)."\n");
|
//$this->addLogItem("Error Object: ".print_r($put,true)."\n");
|
||||||
return $put;
|
return $put;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$ac = StoredFile::recall($this->gb, $id);
|
$ac = $r = StoredFile::recallByGunid($this->gb, $gunid);
|
||||||
$res = $ac->setState('ready');
|
if (PEAR::isError($r)) { return $r; }
|
||||||
#$this->addLogItem("setReadyState - res:".print_r($res,true)."\n");
|
$res = $r = $ac->setState('ready');
|
||||||
$r = $this->gb->dbc->isError($res);
|
if (PEAR::isError($r)) { return $r; }
|
||||||
if ($r) {
|
|
||||||
$this->addLogItem("-E- ".date("Ymd-H:i:s")." addFileToStorage - setReadyState Error\n");
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +303,9 @@ class Restore {
|
||||||
*/
|
*/
|
||||||
function addLogItem($item) {
|
function addLogItem($item) {
|
||||||
$f = fopen ($this->logFile,'a');
|
$f = fopen ($this->logFile,'a');
|
||||||
|
flock($f,LOCK_SH);
|
||||||
fwrite($f,$item);
|
fwrite($f,$item);
|
||||||
|
flock($f,LOCK_UN);
|
||||||
fclose($f);
|
fclose($f);
|
||||||
//echo file_get_contents($this->logFile)."<BR><BR>\n\n";
|
//echo file_get_contents($this->logFile)."<BR><BR>\n\n";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue