GnuBoard Backup Practice
To convert the existing DB from euc-kr to utf8, I carefully took a backup (??),
When I opened it with editplus, it mentioned that there are characters that might be lost in the current encoding,
I ignored it for now and switched to UTF8 and imported… Damn, it didn’t work because of the broken characters ㅠㅠ
I started frantically searching~~~~ but I couldn’t find a solution..
(Even when I provide all options including -default-character-set while dumping, it doesn't work like this ㅠㅠ)
Reluctantly, I found the source below and modified it to my taste (UTF8 conversion, select desired tables)
Migration check complete!!!! - Migrating is always a hassle, so tiring ㅠㅠ
[PHP]
$mysql_host = '********';
$mysql_db = '********';
$mysql_user = '********';
$mysql_pass = '********';
$fileName = 'db-backup';
$extention = "sql";
// Only the necessary tables~
$select[] = 'g4_board';
$select[] = 'g4_board_file';
$select[] = 'g4_board_good';
$select[] = 'g4_board_new';
$select[] = 'g4_config';
$select[] = 'g4_group';
$select[] = 'g4_group_member';
$select[] = 'g4_write_cast';
$select[] = 'g4_write_delphibbs';
$select[] = 'g4_write_english';
$select[] = 'g4_write_girl';
$select[] = 'g4_write_gy';
$select[] = 'g4_write_humor';
$select[] = 'g4_write_module';
$select[] = 'g4_write_mypage';
$select[] = 'g4_write_notice';
$select[] = 'g4_write_poll';
$select[] = 'g4_write_qna';
$select[] = 'g4_write_skin';
$select[] = 'g4_write_talk';
$select[] = 'g4_write_temp';
$select[] = 'g4_write_temppds';
$select[] = 'g4_write_test';
$select[] = 'g4_write_tiptech';
$select[] = 'g4_write_varios';
$all = false; // Set to true to create complete Insert statements
$drop = true; // Set to true to include drop table statements
mysql_connect( $mysql_host, $mysql_user, $mysql_pass ) || die("Failed to connect to the database.");
mysql_select_db( $mysql_db ) || die("Failed to access DB");
function bak_getTableNames($db)
{
$result[0] = mysql_list_tables($db);
$result[1] = mysql_num_rows($result[0]);
return $result;
}
function bak_getFields($table)
{
global $all;
$result = mysql_query("show fields from $table");
$i = 0;
while($keys = mysql_fetch_array($result))
{
if(!$i) $defaultOrder = $keys[Field];
if($keys[Key] == 'PRI')
{
$orderby = $keys[Field];
break;
}
$i++;
}
if(!$orderby) $orderby = $defaultOrder;
$result = mysql_query("select * from $table order by $orderby");
$nums = mysql_num_fields($result);
if($all == true)
{
for($i=0;$i<$nums;$i++)
{
$fields[] = mysql_field_name($result,$i);
}
$fields = "(".implode(",",$fields).") ";
}
while($rows = mysql_fetch_row($result))
{
for($i=0;$i<$nums;$i++)
{
$temp = $rows[$i];
$temp = str_replace("'","''", $temp);
$temp = str_replace("","", $temp);
$temp = str_replace("n",'n', $temp);
$temp = str_replace("r",'r', $temp);
$temp = iconv('CP949', 'UTF-8', $temp);
$insertValues[$i] = $temp;
}
$return .= "INSERT INTO $table ".$fields."values ('".implode("','",
$insertValues)."');n";
}
return $return;
}
$tables = bak_getTableNames($mysql_db);
if($tables[1] > 0)
{
$backText = ”
# MysqlDump
# Host: “.$mysql_host.”
# Processed time: “.date(‘Y년 n월 j일 H시 i분’).”
# Server version: “.mysql_get_server_info().”
# Database : `”.$mysql_db.”`
# ——————————————————–nnnnn”;
while($rows = mysql_fetch_row($tables[0]))
{
$chk = false;
for($i=0;$i
[/PHP]











Leave a Reply