yonash wrote:I'll build plugin for my self, and then give it to you all
I've done it
Please help me to check language. My english isn't great.
<?php
/***********************************************************************
Copyright (C) 2007 YonasH (yonash@yonash.pl)
This software 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.
This software 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 this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston,
MA 02111-1307 USA
************************************************************************/
// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
exit;
// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);
define('PLUGIN_VERSION', '1.0');
// If you want to backup search tables as default
//define('PUN_BACKUP_SEARCH', 1);
// If you want to backup online table as default
//define('PUN_BACKUP_ONLINE', 1);
// Default compression 0 - none ; 1 - zip ; 2 - gzip
define('PUN_BACKUP_COMP', 1);
// Default backup dir
define('PUN_BACKUP_DIR', 'backup');
//
// Increase maximum execution time, but don't complain about it if it isn't
// allowed.
//
@set_time_limit(0);
if (isset($_POST['backup']))
{
$skip_tables = (!empty($_POST['skip_table'])) ? ($_POST['skip_table']) : array();
$compress = (isset($_POST['compression'])) ? ($_POST['compression']) : 'none';
$backup_host = (strpos($db_host,':')) ? substr($db_host,0,strpos($db_host,':')) : $db_host;
$backup_port = (strpos($db_host,':')) ? substr($db_host,strpos($db_host,':')+1,255) : '3306';
$backup_file = PUN_BACKUP_DIR."/";
$backup_file .= ($db_prefix) ? $db_prefix : $db_name."_";
$backup_file .= date('ymd');
$skip_temp = '';
for($i = 0; $i < count($skip_tables); $i++)
$skip_temp .= "--ignore-table=".$db_name.".".$skip_tables[$i]." ";
if(system("mysqldump --host=".$backup_host." --port=".$backup_port." --user=".$db_username." --password=".$db_password." --quick ".$skip_temp.$db_name." > ".$backup_file.".sql",$rtrn) === false)
message('Shell mysqldump error: '.$rtrn);
if ($compress == 'zip')
if(system("zip -q ".$backup_file.".zip ".$backup_file.".sql",$rtrn) === false)
message('Shell zip error: '.$rtrn);
if ($compress == 'gzip')
if(system("gzip ".$backup_file.".gz ".$backup_file.".sql",$rtrn) === false)
message('Shell gzip error: '.$rtrn);
if ($compress != 'none')
system("rm ".$backup_file.".sql",$rtrn);
generate_admin_menu($plugin);
?>
<div class="block">
<h2><span>Database Shell Backup - v<?php echo PLUGIN_VERSION ?></span></h2>
<div class="box">
<div class="inbox">
<p>Database backup successed.</p>
</div>
</div>
</div>
<?php
}
else
{
generate_admin_menu($plugin);
?>
<div class="block">
<h2><span>Database Shell Backup - v<?php echo PLUGIN_VERSION ?></span></h2>
<div class="box">
<div class="inbox">
<p>Lets you perform complete database backup. You must have permit to use PHP "system" command.<br />Created by: YonasH (with some use of DB Management plugin code)</p>
</div>
</div>
</div>
<div class="blockform">
<h2 class="block2"><span>Database Backup</span></h2>
<div class="box">
<form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
<div class="inform">
<fieldset>
<legend>Backup options</legend>
<div class="infldset">
<p>Here you can back up all your PunBB-related data. If your server supports it you may also compress the file to reduce its size before download.</p>
<table cellspacing="0">
<tr>
<th scope="row">Select tables to SKIP</th>
<td>
<?php
$sql = 'SHOW TABLE STATUS';
if (!$result = $db->query($sql))
{
message('Tables error');
}
//autoskip some tables
$pun_skip_tables = array();
if (!defined('PUN_BACKUP_SEARCH'))
$pun_skip_tables = array('search_cache', 'search_matches', 'search_words');
if (!defined('PUN_BACKUP_ONLINE'))
$pun_skip_tables[] = 'online';
//default compression metod autocheck
$comp_temp = array();
$comp_temp[PUN_BACKUP_COMP] = ' checked="checked"';
while ($row = $db->fetch_assoc($result))
{
$name_tabl = $row['Name'];
$name_temp = ($db->prefix) ? substr($name_tabl,strlen($db->prefix),255) : $name_tabl; //name without prefix
if (in_array($name_temp,$pun_skip_tables))
echo "\t\t\t\t\t\t\t\t\t\t".'<input name="skip_table[]" type="checkbox" value="'.$name_tabl.'" checked="checked" /> '.$name_tabl.'<br />'."\n";
else
echo "\t\t\t\t\t\t\t\t\t\t".'<input name="skip_table[]" type="checkbox" value="'.$name_tabl.'" /> '.$name_tabl.'<br />'."\n";
}
?>
</td>
</tr>
<tr>
<th scope="row">Compression type</th>
<td>
<input type="radio" name="compression" value="none"<?php echo $comp_temp[0] ?> /> None<br />
<input type="radio" name="compression" value="zip"<?php echo $comp_temp[1] ?> /> Zip<br />
<input type="radio" name="compression" value="gzip"<?php echo $comp_temp[2] ?> /> Gzip<br />
</td>
</tr>
</table>
</div>
</fieldset>
</div>
<p class="submitend"><input type="submit" name="backup" value="Start backup" class="mainoption" /></p>
</form>
</div>
</div>
<?php
}
YonasH's repository +
Extensions Directory =
PunBB Extensions Online Library (in progress....)
Away. I will be back soon.