The first very simple backup/restore scripts added.
This commit is contained in:
parent
e45836788c
commit
756d368463
5 changed files with 678 additions and 0 deletions
118
livesupport/modules/storageAdmin/bin/backup.sh
Executable file
118
livesupport/modules/storageAdmin/bin/backup.sh
Executable file
|
@ -0,0 +1,118 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2004 Media Development Loan Fund
|
||||||
|
#
|
||||||
|
# This file is part of the LiveSupport project.
|
||||||
|
# http://livesupport.campware.org/
|
||||||
|
# To report bugs, send an e-mail to bugs@campware.org
|
||||||
|
#
|
||||||
|
# LiveSupport is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# LiveSupport is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with LiveSupport; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Author : $Author: tomas $
|
||||||
|
# Version : $Revision: 1.1 $
|
||||||
|
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageAdmin/bin/backup.sh,v $
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# This script creates the tar archiv with backup of LS data
|
||||||
|
#
|
||||||
|
# To get usage help, try the -h option
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Determine directories, files
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
reldir=`dirname $0`/..
|
||||||
|
basedir=`cd $reldir/var; pwd`
|
||||||
|
phpdir=`cd $reldir/var; pwd`
|
||||||
|
mkdir -p $reldir/tmp
|
||||||
|
tmpmaindir=`cd $reldir/tmp; pwd`
|
||||||
|
dbxml="db.xml"
|
||||||
|
datestr=`date '+%Y%m%d%H%M%S'`
|
||||||
|
tarfile0="xmls.tar"
|
||||||
|
tarfile="storage$datestr.tar"
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Print the usage information for this script.
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
printUsage()
|
||||||
|
{
|
||||||
|
echo "This script creates the tgz archiv with backup of LS data.";
|
||||||
|
echo "parameters:";
|
||||||
|
echo "";
|
||||||
|
echo " -d, --destination Destination directory [default:$tmpmaindir].";
|
||||||
|
echo " -h, --help Print this message and exit.";
|
||||||
|
echo "";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Process command line parameters
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
CMD=${0##*/}
|
||||||
|
|
||||||
|
opts=$(getopt -o hd: -l help,destinantion: -n $CMD -- "$@") || exit 1
|
||||||
|
eval set -- "$opts"
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printUsage;
|
||||||
|
exit 0;;
|
||||||
|
-d|--destinantion)
|
||||||
|
destdir=$2
|
||||||
|
shift; shift;;
|
||||||
|
--)
|
||||||
|
shift;
|
||||||
|
break;;
|
||||||
|
*)
|
||||||
|
echo "Unrecognized option $1.";
|
||||||
|
printUsage;
|
||||||
|
exit 1;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "x$destdir" == "x" ]; then
|
||||||
|
destdir=$tmpmaindir
|
||||||
|
fi
|
||||||
|
destdir=`cd $destdir; pwd`
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Do backup
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
tmpdir=`mktemp -dp $tmpmaindir`
|
||||||
|
|
||||||
|
echo "Backuping to $destdir/$tarfile :"
|
||||||
|
echo "Dumping database ..."
|
||||||
|
cd $phpdir
|
||||||
|
php -q backup.php > $tmpdir/$dbxml
|
||||||
|
echo "Packaging stored files ..."
|
||||||
|
cd $phpdir
|
||||||
|
storpath=`php -q getStorPath.php`
|
||||||
|
cd $storpath/..
|
||||||
|
find stor -name "*.xml" -print | tar cf $tmpdir/$tarfile0 -T -
|
||||||
|
find stor ! -name "*.xml" -a -type f -print | tar cf $tmpdir/$tarfile -T -
|
||||||
|
cd $tmpdir
|
||||||
|
tar rf $tarfile0 $dbxml --remove-files
|
||||||
|
echo "Compressing XML part ..."
|
||||||
|
bzip2 $tarfile0
|
||||||
|
tar rf $tarfile $tarfile0.bz2 --remove-files
|
||||||
|
mv $tarfile "$destdir"
|
||||||
|
rm -rf $tmpdir
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Say goodbye
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
echo "done"
|
115
livesupport/modules/storageAdmin/bin/restore.sh
Executable file
115
livesupport/modules/storageAdmin/bin/restore.sh
Executable file
|
@ -0,0 +1,115 @@
|
||||||
|
#!/bin/bash
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2004 Media Development Loan Fund
|
||||||
|
#
|
||||||
|
# This file is part of the LiveSupport project.
|
||||||
|
# http://livesupport.campware.org/
|
||||||
|
# To report bugs, send an e-mail to bugs@campware.org
|
||||||
|
#
|
||||||
|
# LiveSupport is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# LiveSupport is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with LiveSupport; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Author : $Author: tomas $
|
||||||
|
# Version : $Revision: 1.1 $
|
||||||
|
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageAdmin/bin/restore.sh,v $
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# This script restores LS data previously backuped by backup.sh
|
||||||
|
#
|
||||||
|
# To get usage help, try the -h option
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Determine directories, files
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
reldir=`dirname $0`/..
|
||||||
|
basedir=`cd $reldir/var; pwd`
|
||||||
|
phpdir=`cd $reldir/var; pwd`
|
||||||
|
mkdir -p $reldir/tmp
|
||||||
|
tmpmaindir=`cd $reldir/tmp; pwd`
|
||||||
|
dbxml="db.xml"
|
||||||
|
#datestr=`date '+%Y%m%d%H%M%S'`
|
||||||
|
tarfile0="xmls.tar"
|
||||||
|
#tarfile="storage$datestr.tar"
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Print the usage information for this script.
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
printUsage()
|
||||||
|
{
|
||||||
|
echo "This script restores LS data previously backuped by backup.sh.";
|
||||||
|
echo "parameters:";
|
||||||
|
echo "";
|
||||||
|
echo " -f, --file File with backuped data, required.";
|
||||||
|
echo " -h, --help Print this message and exit.";
|
||||||
|
echo "";
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Process command line parameters
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
CMD=${0##*/}
|
||||||
|
|
||||||
|
opts=$(getopt -o hf: -l help,file -n $CMD -- "$@") || exit 1
|
||||||
|
eval set -- "$opts"
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printUsage;
|
||||||
|
exit 0;;
|
||||||
|
-f|--file)
|
||||||
|
tarfile=$2
|
||||||
|
shift; shift;;
|
||||||
|
--)
|
||||||
|
shift;
|
||||||
|
break;;
|
||||||
|
*)
|
||||||
|
echo "Unrecognized option $1.";
|
||||||
|
printUsage;
|
||||||
|
exit 1;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "x$tarfile" == "x" ]; then
|
||||||
|
echo "Required parameter file not specified.";
|
||||||
|
printUsage;
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
tfdir=`dirname $tarfile`
|
||||||
|
tfdir=`cd $tfdir; pwd`
|
||||||
|
tfbname=`basename $tarfile`
|
||||||
|
tarfile="$tfdir/$tfbname"
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Do restore
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
tmpdir=`mktemp -dp $tmpmaindir`
|
||||||
|
|
||||||
|
echo "Restoring database from $tarfile ..."
|
||||||
|
cd $tmpdir
|
||||||
|
tar xf $tarfile
|
||||||
|
tar xjf $tarfile0.bz2
|
||||||
|
rm -f $tarfile0.bz2
|
||||||
|
cd $phpdir
|
||||||
|
php -q restore.php $tmpdir/$dbxml $tmpdir
|
||||||
|
rm -rf $tmpdir
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Say goodbye
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
echo "done"
|
184
livesupport/modules/storageAdmin/var/backup.php
Normal file
184
livesupport/modules/storageAdmin/var/backup.php
Normal file
|
@ -0,0 +1,184 @@
|
||||||
|
<?php
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2004 Media Development Loan Fund
|
||||||
|
|
||||||
|
This file is part of the LiveSupport project.
|
||||||
|
http://livesupport.campware.org/
|
||||||
|
To report bugs, send an e-mail to bugs@campware.org
|
||||||
|
|
||||||
|
LiveSupport is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
LiveSupport is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with LiveSupport; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
|
||||||
|
Author : $Author: tomas $
|
||||||
|
Version : $Revision: 1.1 $
|
||||||
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageAdmin/var/backup.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
define('NSPACE', 'lse');
|
||||||
|
|
||||||
|
header("Content-type: text/plain");
|
||||||
|
require_once 'conf.php';
|
||||||
|
require_once "$storageServerPath/var/conf.php";
|
||||||
|
require_once 'DB.php';
|
||||||
|
require_once "XML/Util.php";
|
||||||
|
require_once "XML/Beautifier.php";
|
||||||
|
require_once "$storageServerPath/var/BasicStor.php";
|
||||||
|
|
||||||
|
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||||
|
$dbc = DB::connect($config['dsn'], TRUE);
|
||||||
|
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||||
|
$bs = &new BasicStor($dbc, $config);
|
||||||
|
|
||||||
|
$stid = $bs->storId;
|
||||||
|
#var_dump($stid); exit;
|
||||||
|
#$farr = $bs->bsListFolder($stid); var_dump($farr); exit;
|
||||||
|
|
||||||
|
function admDumpFolder(&$bs, $fid, $ind=''){
|
||||||
|
$name = $bs->getObjName($fid);
|
||||||
|
if(PEAR::isError($name)){ echo $name->getMessage(); exit; }
|
||||||
|
$type = $bs->getObjType($fid);
|
||||||
|
if(PEAR::isError($type)){ echo $type->getMessage(); exit; }
|
||||||
|
$gunid = $bs->_gunidFromId($fid);
|
||||||
|
if(PEAR::isError($gunid)){ echo $gunid->getMessage(); exit; }
|
||||||
|
$pars = array();
|
||||||
|
if($gunid){ $pars['id']="$gunid"; }
|
||||||
|
$pars['name']="$name";
|
||||||
|
switch($type){
|
||||||
|
case"Folder":
|
||||||
|
$farr = $bs->bsListFolder($fid);
|
||||||
|
if(PEAR::isError($farr)){ echo $farr->getMessage(); exit; }
|
||||||
|
$res = '';
|
||||||
|
foreach($farr as $i =>$folder){
|
||||||
|
$fid2 = $folder['id'];
|
||||||
|
$res .= admDumpFolder($bs, $fid2, "$ind ");
|
||||||
|
}
|
||||||
|
if(!$res){
|
||||||
|
return XML_Util::createTagFromArray(array(
|
||||||
|
'namespace' => NSPACE,
|
||||||
|
'localPart' => 'folder',
|
||||||
|
'attributes'=> $pars,
|
||||||
|
));
|
||||||
|
}else{
|
||||||
|
return XML_Util::createTagFromArray(array(
|
||||||
|
'namespace' => NSPACE,
|
||||||
|
'localPart' => 'folder',
|
||||||
|
'attributes'=> $pars,
|
||||||
|
'content' => $res,
|
||||||
|
), FALSE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case"audioclip":
|
||||||
|
return XML_Util::createTagFromArray(array(
|
||||||
|
'namespace' => NSPACE,
|
||||||
|
'localPart' => 'audioClip',
|
||||||
|
'attributes'=> $pars,
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
case"webstream":
|
||||||
|
return XML_Util::createTagFromArray(array(
|
||||||
|
'namespace' => NSPACE,
|
||||||
|
'localPart' => 'webstream',
|
||||||
|
'attributes'=> $pars,
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
case"playlist":
|
||||||
|
return XML_Util::createTagFromArray(array(
|
||||||
|
'namespace' => NSPACE,
|
||||||
|
'localPart' => 'playlist',
|
||||||
|
'attributes'=> $pars,
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
function admDumpGroup(&$bs, $gid, $ind=''){
|
||||||
|
$name = $bs->getSubjName($gid);
|
||||||
|
if(PEAR::isError($name)){ echo $name->getMessage(); exit; }
|
||||||
|
$isGr = $bs->isGroup($gid);
|
||||||
|
if(PEAR::isError($isGr)){ echo $isGr->getMessage(); exit; }
|
||||||
|
$pars = array('name'=>"$name");
|
||||||
|
if(!$isGr){
|
||||||
|
return XML_Util::createTagFromArray(array(
|
||||||
|
'namespace' => NSPACE,
|
||||||
|
'localPart' => 'member',
|
||||||
|
'attributes'=> $pars,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
$garr = $bs->listGroup($gid);
|
||||||
|
if(PEAR::isError($farr)){ echo $farr->getMessage(); exit; }
|
||||||
|
$res = '';
|
||||||
|
foreach($garr as $i =>$member){
|
||||||
|
$fid2 = $member['id'];
|
||||||
|
$res .= admDumpGroup($bs, $fid2, "$ind ");
|
||||||
|
}
|
||||||
|
if(!$res){
|
||||||
|
return XML_Util::createTagFromArray(array(
|
||||||
|
'namespace' => NSPACE,
|
||||||
|
'localPart' => 'group',
|
||||||
|
'attributes'=> $pars,
|
||||||
|
));
|
||||||
|
}else{
|
||||||
|
return XML_Util::createTagFromArray(array(
|
||||||
|
'namespace' => NSPACE,
|
||||||
|
'localPart' => 'group',
|
||||||
|
'attributes'=> $pars,
|
||||||
|
'content' => $res,
|
||||||
|
), FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
function admDumpSubjects(&$bs, $ind=''){
|
||||||
|
$res ='';
|
||||||
|
$subjs = $bs->getSubjects('id, login, pass, type');
|
||||||
|
foreach($subjs as $i =>$member){
|
||||||
|
switch($member['type']){
|
||||||
|
case"U":
|
||||||
|
$pars = array('login'=>"{$member['login']}", 'pass'=>"{$member['pass']}");
|
||||||
|
$res .= XML_Util::createTagFromArray(array(
|
||||||
|
#'namespace' => 'ls',
|
||||||
|
'localPart' => 'user',
|
||||||
|
'attributes'=> $pars,
|
||||||
|
));
|
||||||
|
break;
|
||||||
|
case"G":
|
||||||
|
$res .= admDumpGroup($bs, $member['id'], "$ind ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "$ind<subjects>\n$res$ind</subjects>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$subjects = admDumpSubjects($bs, ' ');
|
||||||
|
$tree = admDumpFolder($bs, $stid, ' ');
|
||||||
|
|
||||||
|
$res = XML_Util::getXMLDeclaration("1.0", "UTF-8")."\n";
|
||||||
|
$node = XML_Util::createTagFromArray(array(
|
||||||
|
'namespace' => NSPACE,
|
||||||
|
'localPart' => 'storageServer',
|
||||||
|
'content' => "$subjects$tree",
|
||||||
|
), FALSE);
|
||||||
|
$res .= $node;
|
||||||
|
|
||||||
|
$fmt = new XML_Beautifier();
|
||||||
|
$res = $fmt->formatString($res);
|
||||||
|
|
||||||
|
#var_export($res);
|
||||||
|
#var_dump($res);
|
||||||
|
echo "$res";
|
||||||
|
|
||||||
|
?>
|
35
livesupport/modules/storageAdmin/var/getStorPath.php
Normal file
35
livesupport/modules/storageAdmin/var/getStorPath.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2004 Media Development Loan Fund
|
||||||
|
|
||||||
|
This file is part of the LiveSupport project.
|
||||||
|
http://livesupport.campware.org/
|
||||||
|
To report bugs, send an e-mail to bugs@campware.org
|
||||||
|
|
||||||
|
LiveSupport is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
LiveSupport is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with LiveSupport; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
|
||||||
|
Author : $Author: tomas $
|
||||||
|
Version : $Revision: 1.1 $
|
||||||
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageAdmin/var/getStorPath.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
header("Content-type: text/plain");
|
||||||
|
require_once 'conf.php';
|
||||||
|
require_once "$storageServerPath/var/conf.php";
|
||||||
|
|
||||||
|
echo "{$config['storageDir']}\n";
|
||||||
|
?>
|
226
livesupport/modules/storageAdmin/var/restore.php
Normal file
226
livesupport/modules/storageAdmin/var/restore.php
Normal file
|
@ -0,0 +1,226 @@
|
||||||
|
<?php
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2004 Media Development Loan Fund
|
||||||
|
|
||||||
|
This file is part of the LiveSupport project.
|
||||||
|
http://livesupport.campware.org/
|
||||||
|
To report bugs, send an e-mail to bugs@campware.org
|
||||||
|
|
||||||
|
LiveSupport is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
LiveSupport is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with LiveSupport; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
|
||||||
|
Author : $Author: tomas $
|
||||||
|
Version : $Revision: 1.1 $
|
||||||
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storageAdmin/var/restore.php,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
define('NSPACE', 'lse');
|
||||||
|
|
||||||
|
header("Content-type: text/plain");
|
||||||
|
require_once 'conf.php';
|
||||||
|
require_once "$storageServerPath/var/conf.php";
|
||||||
|
require_once 'DB.php';
|
||||||
|
require_once "XML/Util.php";
|
||||||
|
require_once "XML/Beautifier.php";
|
||||||
|
require_once "$storageServerPath/var/BasicStor.php";
|
||||||
|
|
||||||
|
/* =========================================================== misc functions */
|
||||||
|
function ls_restore_processObject($el){
|
||||||
|
$res = array(
|
||||||
|
'name' => $el->attrs['name']->val,
|
||||||
|
'type' => $el->name,
|
||||||
|
);
|
||||||
|
switch($res['type']){
|
||||||
|
case'folder':
|
||||||
|
foreach($el->children as $i=>$o){
|
||||||
|
$res['children'][] = ls_restore_processObject($o);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$res['gunid'] = $el->attrs['id']->val;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ls_restore_checkErr($r, $ln=''){
|
||||||
|
if(PEAR::isError($r)){
|
||||||
|
echo "ERROR $ln: ".$r->getMessage()." ".$r->getUserInfo()."\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ls_restore_restoreObject($obj, $parid, $reallyInsert=TRUE){
|
||||||
|
global $tmpdir, $bs;
|
||||||
|
switch($obj['type']){
|
||||||
|
case"folder";
|
||||||
|
if($reallyInsert){
|
||||||
|
$r = $bs->bsCreateFolder($parid, $obj['name']);
|
||||||
|
ls_restore_checkErr($r, __LINE__);
|
||||||
|
}else $r=$parid;
|
||||||
|
if(is_array($obj['children'])){
|
||||||
|
foreach($obj['children'] as $i=>$ch){
|
||||||
|
ls_restore_restoreObject($ch, $r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case"audioClip";
|
||||||
|
case"webstream";
|
||||||
|
case"playlist";
|
||||||
|
$gunid = $obj['gunid'];
|
||||||
|
$gunid3 = substr($gunid, 0, 3);
|
||||||
|
$mediaFile = "$tmpdir/stor/$gunid3/$gunid";
|
||||||
|
if(!file_exists($mediaFile)) $mediaFile = NULL;
|
||||||
|
$mdataFile = "$tmpdir/stor/$gunid3/$gunid.xml";
|
||||||
|
if(!file_exists($mdataFile)) $mdataFile = NULL;
|
||||||
|
if($reallyInsert){
|
||||||
|
$r = $bs->bsPutFile($parid, $obj['name'],
|
||||||
|
$mediaFile, $mdataFile, $obj['gunid'],
|
||||||
|
strtolower($obj['type']));
|
||||||
|
ls_restore_checkErr($r, __LINE__);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* =============================================================== processing */
|
||||||
|
|
||||||
|
PEAR::setErrorHandling(PEAR_ERROR_RETURN);
|
||||||
|
$dbc = DB::connect($config['dsn'], TRUE);
|
||||||
|
$dbc->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||||
|
$bs = &new BasicStor($dbc, $config);
|
||||||
|
|
||||||
|
$dbxml = file_get_contents($argv[1]);
|
||||||
|
$tmpdir = $argv[2];
|
||||||
|
|
||||||
|
require_once"$storageServerPath/var/XmlParser.php";
|
||||||
|
$parser =& new XmlParser($dbxml);
|
||||||
|
if($parser->isError()){
|
||||||
|
return PEAR::raiseError(
|
||||||
|
"MetaData::parse: ".$parser->getError()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$xmlTree = $parser->getTree();
|
||||||
|
|
||||||
|
|
||||||
|
/* ----------------------------------------- processing storageServer element */
|
||||||
|
$subjArr = FALSE;
|
||||||
|
$tree = FALSE;
|
||||||
|
foreach($xmlTree->children as $i=>$el){
|
||||||
|
switch($el->name){
|
||||||
|
case"subjects":
|
||||||
|
if($subjArr !== FALSE){
|
||||||
|
echo"ERROR: unexpected subjects element\n";
|
||||||
|
}
|
||||||
|
$subjArr=$el->children;
|
||||||
|
break;
|
||||||
|
case"folder":
|
||||||
|
if($tree !== FALSE){
|
||||||
|
echo"ERROR: unexpected folder element\n";
|
||||||
|
}
|
||||||
|
$tree = ls_restore_processObject($el);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
echo"ERROR: unknown element name {$el->name}\n";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
# echo "{$el->name}\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------- processing subjects element */
|
||||||
|
$subjects = array();
|
||||||
|
$groups = array();
|
||||||
|
foreach($subjArr as $i=>$el){
|
||||||
|
switch($el->name){
|
||||||
|
case"group":
|
||||||
|
$groups[$el->attrs['name']->val] = $el->children;
|
||||||
|
$subjects[$el->attrs['name']->val] = array(
|
||||||
|
'type' => 'group',
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case"user":
|
||||||
|
$subjects[$el->attrs['login']->val] = array(
|
||||||
|
'type' => 'user',
|
||||||
|
'pass' => $el->attrs['pass']->val,
|
||||||
|
# 'realname' => $el->attrs['realname']->val,
|
||||||
|
'realname' => '',
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------- processing groups */
|
||||||
|
foreach($groups as $grname=>$group){
|
||||||
|
foreach($group as $i=>$el){
|
||||||
|
$groups[$grname][$i] = $el->attrs['name']->val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#var_dump($xmlTree);
|
||||||
|
#var_dump($subjArr);
|
||||||
|
#var_dump($groups);
|
||||||
|
#var_dump($subjects);
|
||||||
|
#var_dump($tree);
|
||||||
|
|
||||||
|
#exit;
|
||||||
|
|
||||||
|
/* ================================================================ restoring */
|
||||||
|
|
||||||
|
$bs->resetStorage(FALSE);
|
||||||
|
$storId = $bs->storId;
|
||||||
|
|
||||||
|
/* ------------------------------------------------------- restoring subjects */
|
||||||
|
foreach($subjects as $login=>$subj){
|
||||||
|
$uid = $bs->getSubjId($login);
|
||||||
|
ls_restore_checkErr($uid);
|
||||||
|
switch($subj['type']){
|
||||||
|
case"user":
|
||||||
|
if($login=='root'){
|
||||||
|
$r = $bs->passwd($login, NULL, $subj['pass'], TRUE);
|
||||||
|
ls_restore_checkErr($r, __LINE__);
|
||||||
|
}else{
|
||||||
|
if(!is_null($uid)){
|
||||||
|
$r = $bs->removeSubj($login);
|
||||||
|
ls_restore_checkErr($r, __LINE__);
|
||||||
|
}
|
||||||
|
$bs->addSubj($login, $subj['pass'], $subj['realname'], TRUE);
|
||||||
|
ls_restore_checkErr($r, __LINE__);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case"group":
|
||||||
|
if(!is_null($uid)){
|
||||||
|
$r = $bs->removeSubj($login);
|
||||||
|
if(PEAR::isError($r)) break;
|
||||||
|
//ls_restore_checkErr($r, __LINE__);
|
||||||
|
}
|
||||||
|
$r = $bs->addSubj($login, NULL);
|
||||||
|
ls_restore_checkErr($r, __LINE__);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------- restoring groups */
|
||||||
|
foreach($groups as $grname=>$group){
|
||||||
|
foreach($group as $i=>$login){
|
||||||
|
$r = $bs->addSubj2Gr($login, $grname);
|
||||||
|
ls_restore_checkErr($r, __LINE__);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------- restoring objects */
|
||||||
|
ls_restore_restoreObject($tree, $storId, FALSE);
|
||||||
|
|
||||||
|
?>
|
Loading…
Add table
Add a link
Reference in a new issue