Файл: world-faces.ru/world-faces.ru/sys/fnc/backup.php
Строк: 104
<?
$q=mysql_query("SELECT * FROM `cron` WHERE `id` = 'backup_mysql'");
if (mysql_num_rows($q)==0)mysql_query("INSERT INTO `cron` (`id`, `time`) VALUES ('backup_mysql', '".time()."')");
$backup = mysql_fetch_array($q);
if (eregi('^[^@]*@[^@]*.[^@]*$',$set['mail_backup']) && ($backup==NULL || $backup['time']<time()-60*60*24)){
mysql_query("UPDATE `cron` SET `time` = '".time()."' WHERE `id` = 'backup_mysql'");
@unlink(H."sys/tmp/MySQL.sql.gz");
$list_tables=NULL;
$tab=mysql_list_tables($set['mysql_db_name']);
for($i=0;$i<mysql_num_rows($tab);$i++)
{
$sql=NULL;
$table=mysql_tablename($tab,$i);
$sql.="DROP TABLE IF EXISTS `$table`;rn";
$res=@mysql_query("SHOW CREATE TABLE `$table`");
$row=@mysql_fetch_row($res);
$sql.=$row[1].";rnrn";
$res = @mysql_query("SELECT * FROM `$table`");
if (@mysql_num_rows($res) > 0) {
while (($row = @mysql_fetch_assoc($res))) {
$keys = @implode("`, `", @array_keys($row));
$values = @array_values($row);
foreach($values as $k=>$v) {
$values[$k] = mysql_real_escape_string($v);
$values[$k]=ereg_replace("(n|r){1,}", 'n', $values[$k]);
}
$values2 = @implode("', '", $values);
$values2 = "'".$values2."'";
$values2= str_replace("''", "null", $values2);
$sql .= "INSERT INTO `$table` (`$keys`) VALUES ($values2);rn";
}
$sql .= "rnrn";
}
$fopen_mysql=fopen(H."sys/tmp/MySQL.sql.gz",'a');
//if (strlen($sql)<5*1024*1024)
fwrite($fopen_mysql, gzencode($sql,9));
fclose($fopen_mysql);
}
$subj="Бэкап MySQL";
$bound="--".md5(uniqid(time()));
$headers="From: "BackUP@$_SERVER[HTTP_HOST]" <BackUp@$_SERVER[HTTP_HOST]>rn";
$headers.="To: $set[mail_backup]rn";
$headers.="Subject: $subjrn";
$headers.="Mime-Version: 1.0rn";
$headers.="Content-Type: multipart/alternative; boundary="$bound"rn";
$body="--$boundrn";
$body.="Content-type: text/html; charset="utf-8"rn";
$body.="Content-Transfer-Encoding: 8bitrn";
$body.="rn";
$body.="<h3>Автоматическая отправка BackUp базы данных</h3>";
$body.="rn";
$body.="--$boundrn";
$body.="Content-Disposition: attachment;rn";
$body.="Content-Type: application/x-gzip; name="MySQL.sql.gz"rn";
$body.="Content-Transfer-Encoding:base64rn";
$body.="rn";
$body.=base64_encode(file_get_contents(H."sys/tmp/MySQL.sql.gz"))."rn";
$body.="--$boundrn";
$body.="Content-Disposition: attachment;rn";
$body.="Content-Type: text/plain; name="settings_6.2.dat"rn";
$body.="Content-Transfer-Encoding:base64rn";
$body.=base64_encode(file_get_contents(H."sys/dat/settings_6.2.dat"))."rn";
$body.="--$bound";
$body.="--rn";
mail("$set[mail_backup]", $subj, $body, $headers);
unlink(H."sys/tmp/MySQL.sql.gz");
}
?>