1)
return round($rawSize/1048576, 1) . ' MB';
else if ($rawSize / 1024 > 1)
return round($rawSize/1024, 1) . ' KB';
else
return round($rawSize, 1) . ' bytes';
}
### Check Folder Whether There Is Any File Inside
function is_emtpy_folder($folder){
if(is_dir($folder) ){
$handle = opendir($folder);
while( (gettype( $name = readdir($handle)) != 'boolean')){
$name_array[] = $name;
}
foreach($name_array as $temp)
$folder_content .= $temp;
if($folder_content == '...')
return true;
else
return false;
closedir($handle);
}
else
return true; // folder doesnt exist
}
### Form Processing
if($_POST['do']) {
// Lets Prepare The Variables
$database_file = trim($_POST['database_file']);
$optimize = $_POST['optimize'];
$delete = $_POST['delete'];
$nice_file_date = date('l, jS F Y @ H:i', substr($database_file, 0, 10));
// Decide What To Do
switch($_POST['do']) {
case 'Backup':
$gzip = intval($_POST['gzip']);
if($gzip == 1) {
$backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql.gz';
$backup['filepath'] = $backup['path'].'/'.$backup['filename'];
$backup['command'] = $backup['mysqldumppath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' --add-drop-table '.DB_NAME.' | gzip > '.$backup['filepath'];
} else {
$backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql';
$backup['filepath'] = $backup['path'].'/'.$backup['filename'];
$backup['command'] = $backup['mysqldumppath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' --add-drop-table '.DB_NAME.' > '.$backup['filepath'];
}
passthru($backup['command'], $error);
if(!is_writable($backup['path'])) {
$text = "Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Backup Folder Not Writable";
} elseif(filesize($backup['filepath']) == 0) {
unlink($backup['filepath']);
$text = "Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Backup File Size Is 0KB";
} elseif(!is_file($backup['filepath'])) {
$text = "Database Failed To Backup On '".date('l, jS F Y @ H:i')."'. Invalid Backup File Path";
} elseif($error) {
$text = "Database Failed To Backup On '".date('l, jS F Y @ H:i')."'";
} else {
$text = "Database Backed Up Successfully On '".date('l, jS F Y @ H:i')."'";
}
break;
case 'Restore':
if(!empty($database_file)) {
if(stristr($database_file, '.gz')) {
$backup['command'] = 'gunzip < '.$backup['path'].'/'.$database_file.' | '.$backup['mysqlpath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' '.DB_NAME;
} else {
$backup['command'] = $backup['mysqlpath'].' -h'.DB_HOST.' -u'.DB_USER.' -p'.DB_PASSWORD.' '.DB_NAME.' < '.$backup['path'].'/'.$database_file;
}
passthru($backup['command'], $error);
if($error) {
$text = "Database On '$nice_file_date' Failed To Restore";
} else {
$text = "Database On '$nice_file_date' Restored Successfully";
}
} else {
$text = 'No Backup Database File Selected';
}
break;
case 'Delete':
if(!empty($delete)) {
foreach($delete as $dbbackup) {
$nice_file_date = date('l, jS F Y @ H:i', substr($dbbackup, 0, 10));
if(is_file($backup['path'].'/'.$dbbackup)) {
if(!unlink($backup['path'].'/'.$dbbackup)) {
$text .= "Unable To Delete Database Backup File On '$nice_file_date'
";
} else {
$text .= "Database Backup File On '$nice_file_date' Deleted Successfully
";
}
} else {
$text = "Invalid Database Backup File On '$nice_file_date'";
}
}
} else {
$text = 'No Backup Database File Selected';
}
break;
case 'Download':
if(!empty($database_file)) {
$file_path = $backup['path'].'/'.$database_file;
$nice_file_name = date('jS_F_Y', substr($database_file, 0, 10)).'-'.substr($database_file, 13);
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($nice_file_name).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file_path));
@readfile($file_path);
} else {
$text = 'No Backup Database File Selected';
}
break;
case 'Optimize':
foreach($optimize as $key => $value) {
if($value == 'yes') {
$tables_string .= ', '.$key;
}
}
$selected_tables = substr($tables_string, 2);
if(!empty($selected_tables)) {
$optimize2 = $wpdb->query("OPTIMIZE TABLE $selected_tables");
if(!$optimize2) {
$text = "Table(s) '$selected_tables' Failed To Be Optimized";
} else {
$text = "Table(s) '$selected_tables' Optimized Successfully";
}
} else {
$text = 'No Tables Selected';
}
break;
case 'Run':
$sql_queries2 = trim($_POST['sql_query']);
$totalquerycount = 0;
$successquery = 0;
if($sql_queries2) {
$sql_queries = array();
$sql_queries2 = explode("\n", $sql_queries2);
foreach($sql_queries2 as $sql_query2) {
$sql_query2 = trim(stripslashes($sql_query2));
$sql_query2 = preg_replace("/[\r\n]+/", '', $sql_query2);
if(!empty($sql_query2)) {
$sql_queries[] = $sql_query2;
}
}
if($sql_queries) {
foreach($sql_queries as $sql_query) {
if (preg_match("/^\\s*(insert|update|replace|delete|create) /i",$sql_query)) {
$run_query = $wpdb->query($sql_query);
if(!$run_query) {
$text .= "$sql_query
";
} else {
$successquery++;
$text .= "$sql_query
";
}
$totalquerycount++;
} elseif (preg_match("/^\\s*(select|drop|show|grant) /i",$sql_query)) {
$text .= "$sql_query
";
$totalquerycount++;
}
}
$text .= "$successquery/$totalquerycount Query(s) Executed Successfully";
} else {
$text = "Empty Query";
}
} else {
$text = "Empty Query";
}
break;
}
}
### Switch $mode
switch($mode) {
// Backup Database
case 'backup':
$title = 'Backup Database';
$standalone = 0;
require("./admin-header.php");
if ($user_level < 9) {
die('
Insufficient Level
'); } $backup['filename'] = $backup['date'].'_-_'.DB_NAME.'.sql'; ?>| Setting | Value |
|---|---|
| Database Host | =DB_HOST?> |
| Database Name | =DB_NAME?> |
| Database User | =DB_USER?> |
| Database Type | MYSQL |
| Database Version | v=$sqlversion?> |
| No. | Tables | Records | Data Usage | Index Usage | Overhead |
|---|---|---|---|---|---|
| $no | \n"; echo "$tablestatus->Name | \n"; echo "".number_format($tablestatus->Rows)." | \n"; echo "".format_size($tablestatus->Data_length)." | \n"; echo "".format_size($tablestatus->Index_length)." | \n"; echo "".format_size($tablestatus->Data_free)." | \n"; $row_usage += $tablestatus->Rows; $data_usage += $tablestatus->Data_length; $index_usage += $tablestatus->Index_length; $overhead_usage += $tablestatus->Data_free; } echo "
| Total: | \n"; echo "$no Tables | \n"; echo "".number_format($row_usage)." | \n"; echo "".format_size($data_usage)." | \n"; echo "".format_size($index_usage)." | "; echo "".format_size($overhead_usage)." |
| Could Not Show Table Status Due To Your MYSQL Version Is Lower Than 3.23. | |||||