View file admin_list/backup.php

File size: 3.13Kb
<?
/*
=============================================
Движок: SHCMS Engine
=============================================
Название файла: Бэкап сайта
=============================================
Official website: http://shcms.ru
=============================================
Код зашищен авторскими правами
=============================================
*/
define('SHCMS', true);
include_once'../system/inc/basic_settings.php';
$shcmsengine['title'] = 'SHCMS Engine Сделать бэкап сайта';
include_once'../template/head.php';
registrat();
registrat();
$adminka ->admin();

$user4 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id`='$user_id'"));
if($user4['team'] < 6)
{
echo 'Ошибка';
header('Refresh: 1; url=/index.php?'.$conservation.'&');
	include_once'../template/foot.php';
exit();
}
include_once'secu.php';

base($user_localhost,$user_user,$user_pass,$user_db, '*');
function base($host,$user,$pass,$name,$tables)
{
    $link = mysql_connect($host,$user,$pass);
    mysql_select_db($name,$link);
    if($tables == '*')
    {
        $tables = array();
        $result = mysql_query('SHOW TABLES');
        while($row = mysql_fetch_row($result))
        {
        $tables[] = $row[0];
        }
    }
    else
    {
        $tables = is_array($tables) ? $tables : explode(',',$tables);
    }
    foreach($tables as $table)
    {
        $result = mysql_query('SELECT * FROM '.$table);
        $num_fields = mysql_num_fields($result);
        $mysq_back.= 'DROP TABLE '.$table.';';
        $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table));
        $mysq_back.= "\n\n".$row2[1].";\n\n";
        for ($i = 0; $i < $num_fields; $i++)
        {
            while($row = mysql_fetch_row($result))
            {
                $mysq_back.= 'INSERT INTO '.$table.' VALUES(';
                for($j=0; $j<$num_fields; $j++)
				{
				    $row[$j] = addslashes($row[$j]);
                    $row[$j] = ereg_replace("\n","\\n",$row[$j]);
                    if (isset($row[$j])) { $mysq_back.= '"'.$row[$j].'"' ; } else { $mysq_back.= '""'; }
                    if ($j<($num_fields-1)) { $mysq_back.= ','; }
                }
                $mysq_back.= ");\n";
            }
        }
		$mysq_back.="\n\n\n/*Бэкап сделан на движке SHCMS Engine*/\n\n\n";}
$s = mkdir('Backup',0777,true);
    $handle = fopen('Backup/'.$_SERVER['HTTP_HOST'].'_'.date('d.m.y'). '.sql','w+');
    fwrite($handle,$mysq_back);
    fclose($handle);

	$file = "Backup/".$_SERVER['HTTP_HOST']."_ ".date('d.m.y').".php";
	$person = '
	<?
	/*
	-------------------------------------------------
	Бэкап сделан на движке SHCMS Engine
	Автор Движка SHCMS Engine: Shamsik
	Сайт Shimsidin.ru
	-------------------------------------------------
	*/;
	?>';
	file_put_contents($file,$person,FILE_APPEND | LOCK_EX);
}
echo '<div class="mysql_yes"><center>Бэкап успешно создан и сохранен в папке Backup</center></div>';
include_once'../template/foot.php';
?>