[Box Backup] Restoring files to the bbstored machine
Dave Bamford
boxbackup@fluffy.co.uk
Wed, 23 Apr 2008 20:48:13 +0100
Hi
here is the code you can probably infer the sql table format from it
it also updates the usage in the table. It needs some refinement but
basically
works. You have to ensure that the folder used to recover files is
writeable by
Apache.
regards
Dave
<?php
session_start(); // start up your PHP session!
function displayfiles($retval)
{
//do the folders first
foreach($retval as $entry) {
// split id flags date file
$flags = substr($entry,9,6);
$file = substr($entry,42);
if (substr($flags,1,1) == 'd'){
echo '<br/>
<img src="icons/folder.png">
<a href="index.php?wd='.$_GET['wd'].'/'.$file.'">
'.$file.'</a>';
}
}
// now do the files
echo '<div style="float: left; width: 100px;">ID</div>
<div style="float:left; width: 100px;">Flags</div>
<div style="float:left; width: 100px;">Date</div>
<div style="float:left; width: 100px;">Time</div>
<div style="float:left; width: 100px;">Size</div>
<div>Name</div>';
foreach($retval as $entry) {
// split id flags date file
$id = substr($entry,0,8);
$flags = substr($entry,9,6);
$date = substr($entry,16,10);
$time = substr($entry,27,8);
$size = substr($entry,36,5);
$file = substr($entry,42);
if (substr($flags,0,1) == 'f'){
echo '<div style="float: left; width: 100px">'.$id.'</div>
<div style="float: left; width: 100px">'.$flags.'</div>
<div style="float: left; width: 100px">'.$date.'</div>
<div style="float: left; width: 100px">'.$time.'</div>
<div style="float: left; width: 100px">'.$size.'</div>
<div><a
href="index.php?wd='.$_GET['wd'].'&id='.$id.'&file='.$file.'">'.$file.'</a></div>';
}
}
}
$chown = 'sudo /usr/sbin/chown _www';
$tmpdir = '/tmp';
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-gb">
<title>box backup query</title>
</head>
<body>
<?php
require ('mysqlinc.php');
//open the database
mysql_pconnect($mysqlpath,$mysqluser,$mysqlpwd) or die("Error connecting
to MySQL server");
mysql_select_db($mysqldb) or die("Error selecting MtSQL database");
// get data
$sql = "SELECT * from account";
$res = mysql_query($sql);
if (isset($_POST['account'])){
echo "<br/>account=".$_POST['account'];
$_SESSION['account'] = $_POST['account'];
}
?>
<form action="index.php" method="post">
<select name="account">
<?php
if ($res) {
echo '<option value="" selected="selected">account</option>';
while ($r1 = mysql_fetch_array($res)) {
echo '<option value='.$r1['num'].' >'.$r1['num'].'
'.$r1['name'].'</option>';
}
}
?>
</select>
<input type="submit" value="submit"/>
</form>
<?php
//program to execute backup list command
$bquery = '/usr/local/bin/bbackupquery -q -c
bbackupd.'.$_SESSION['account'];
echo '<br/><a href="index.php?wd=showusage">show usage</a>';
if (isset($_GET['wd'])){
if (!strcmp($_GET['wd'],'showusage')) {
exec($bquery.' usage exit',$retval);
list($r0,$r1,$used) = split("[\t ]+",$retval[0]);
list($r0,$r1,$r2,$old) = split("[\t ]+",$retval[1]);
list($r0,$r1,$r2,$deleted) = split("[\t ]+",$retval[2]);
list($r0,$r1,$directories) = split("[\t ]+",$retval[3]);
list($r0,$r1,$r2,$softlim) = split("[\t ]+",$retval[4]);
list($r0,$r1,$r2,$hardlim) = split("[\t ]+",$retval[5]);
$used = trim($used,'Mb');
$old = trim($old,'Mb');
$deleted = trim($deleted,'Mb');
$directories = trim($directories,'Mb');
$softlim = trim($softlim,'Mb');
$hardlim = trim($hardlim,'Mb');
$sql = 'UPDATE account SET `usage` ='.$used.',
`old` = '.$old.',
`deleted` = '.$deleted.',
`directories` = '.$directories.',
`softlim` = '.$softlim.',
`hardlim` = '.$hardlim.'
WHERE num = "'.$_SESSION['account'].'"';
//echo "sql=".$sql;
if ($ret = mysql_query ($sql)){
echo "<br/>used=".$used."<br/>";
echo "old=".$old."<br/>";
echo "deleted=".$deleted."<br/>";
echo "directories=".$directories."<br/>";
echo "soft limit=".$softlim."<br/>";
echo "hard limit=".$hardlim."<br/>";
echo "<br/>Database updated";
}
else {
echo "<br/>Failed to update database";
}
}
else {
exec($bquery.' "list -osdt \"'.$_GET['wd'].'\"" exit', $retval);
$parent = substr($_GET['wd'],0,strrpos($_GET['wd'],"/"));
echo '<br/><a href="index.php?wd='.$parent.'">back to
'.$parent.'<a/>';
echo '<br/>current folder = '.$_GET['wd'];
displayfiles($retval);
}
}
else {
exec($bquery.' "list -osdt" exit', $retval);
displayfiles($retval);
}
if (isset($_GET['id'])){
echo "<br/>getting file";
echo($bquery.'"cd \"'.$_GET['wd'].'\"" "get -i '.$_GET['id'].'
\"/home/dave/'.$_GET['file'].'\"" exit');
exec($bquery.' "cd \"'.$_GET['wd'].'\"" "get -i '.$_GET['id'].'
\"/home/dave/'.$_GET['file'].'\"" exit',$retval);
}
?>
</body></html>