DB 백업

[crayon lang=”php” toolbar=”false”]
<?
# 디비 정보 입력
$_HOSTNAME=”localhost”;
$_USERNAME=””;
$_PASSWORD=””;
$_DATABASE=””;

$filename = $_DATABASE.”_”.date(’Ymd’).”.sql”;
set_time_limit(0);

if(eregi(”msie”,$HTTP_USER_AGENT)) $browser=”1”; else $browser=”0”;
header(”Content-Type: application/octet-stream”);
if ($browser) {
header(”Content-Disposition: attachment; filename=”$filename””);
header(”Expires: 0”);
header(’Cache-Control: must-revalidate, post-check=0, pre-check=0’);
header(’Pragma: public’);
} else {
header(”Content-Disposition: attachment; filename=”$filename””);
header(”Expires: 0”);
header(”Pragma: public”);
}
flush();

echo ”# enjoyteam Board MySQL Dumpnr”;
echo ”#nr”;
echo ”# Database: $_DATABASEnr”;
echo ”# ——————————————————–nr”;
echo ”#nr”;
echo ”nr”;
flush();

$db_connection = mysql_connect($_HOSTNAME, $_USERNAME, $_PASSWORD) or die(error(’MySQL Server에 접속할수 없습니다.’));
mysql_select_db($_DATABASE, $db_connection) or die(error(’MySQL Server에 접속할수 없습니다’));

function get_fileds($table_name)
{
$db_list = mysql_query(”show fields from $table_name”);
$db_cnt = mysql_affected_rows();

for($i=0; $i<$db_cnt; $i++)
{
$db_data = mysql_fetch_assoc($db_list);
$fields[$i] = $db_data[Field];
flush();
}
return $fields;
}

function make_field_data($table_name, $fields)
{
$db_list = mysql_query(”select * from $table_name”);
$db_cnt = mysql_affected_rows();

for($i=0; $i<$db_cnt; $i++)
{
$db_data = mysql_fetch_assoc($db_list);
echo ”INSERT INTO $table_name VALUES(”;
for($l=0; $l<sizeof($fields); $l++)
{
echo ”””.$db_data[$fields[$l]].”””;
if($l<sizeof($fields)-1) { echo ”, ”; }
flush();
}
echo ”);nr”;
flush();
}
echo ”nr”;
}

$db_list = mysql_query(”show tables”);
$db_cnt = mysql_affected_rows();

for($i=0; $i<$db_cnt; $i++) { $db_data = mysql_fetch_assoc($db_list); $set_fields = get_fileds($db_data[$list_field]); $list_field = ”Tables_in_”.$_DATABASE; $set_create_query = @mysql_result(mysql_query(”show create table $db_data[$list_field]”),0,1); echo ”#nr”; echo ”# Table structure for table ’$db_data[$list_field]’nr”; echo ”#nr”; echo ”nr”; echo ”$set_create_querynr”; echo ”nr”; flush(); make_field_data($db_data[$list_field], $set_fields); } ?>
[/crayon]

enjoyteam 게시판 만들때 사용한 것들~

실행시 DATABASE명_오늘날짜(20070116).sql로 저장~

Leave a Comment

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.