Changeset 19 for minimanager/backup.php
- Timestamp:
- Aug 13, 2007, 9:05:34 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
minimanager/backup.php
r5 r19 172 172 move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], "$backup_dir/$file_name_new") or die (error("{$lang_backup['upload_err_write_permission']} $backup_dir")); 173 173 if (file_exists("$backup_dir/$file_name_new")){ 174 require_once("scripts/ mysql_lib.php");174 require_once("scripts/db_layer/sql_lib.php"); 175 175 $use_db = addslashes($_POST['use_db']); 176 176 177 if ($use_db == $realm_db['name']) $queries = mysql_run_sql_script($realm_db['addr'], $realm_db['user'], $realm_db['pass'], "$backup_dir/$file_name_new",true);177 if ($use_db == $realm_db['name']) $queries = run_sql_script($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'], "$backup_dir/$file_name_new",true); 178 178 else { 179 179 foreach ($mangos_db as $db) 180 if ($use_db == $db['name']) $queries = mysql_run_sql_script($db['addr'], $db['user'], $db['pass'], "$backup_dir/$file_name_new",true);180 if ($use_db == $db['name']) $queries = run_sql_script($db['addr'], $db['user'], $db['pass'], $db['name'], "$backup_dir/$file_name_new",true); 181 181 } 182 182 … … 191 191 192 192 if (file_exists("$backup_dir/$file_name")){ 193 require_once("scripts/ mysql_lib.php");193 require_once("scripts/db_layer/sql_lib.php"); 194 194 $use_db = addslashes($_POST['use_db']); 195 195 196 if ($use_db == $realm_db['name']) $queries = mysql_run_sql_script($realm_db['addr'], $realm_db['user'], $realm_db['pass'], "$backup_dir/$file_name",false);196 if ($use_db == $realm_db['name']) $queries = run_sql_script($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'], "$backup_dir/$file_name",false); 197 197 else { 198 198 foreach ($mangos_db as $db) 199 if ($use_db == $db['name']) $queries = mysql_run_sql_script($db['addr'], $db['user'], $db['pass'], "$backup_dir/$file_name",false);199 if ($use_db == $db['name']) $queries = run_sql_script($db['addr'], $db['user'], $db['pass'], $db['name'], "$backup_dir/$file_name",false); 200 200 } 201 201 … … 219 219 fclose($fp); 220 220 221 require_once("scripts/ mysql_lib.php");221 require_once("scripts/db_layer/sql_lib.php"); 222 222 223 223 foreach ($tables_backup_realmd as $value) { 224 mysql_table_dump ($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'],$value,$struc_backup,"$backup_dir/$file_name_new");224 sql_table_dump ($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'],$value,$struc_backup,"$backup_dir/$file_name_new"); 225 225 } 226 226 … … 234 234 235 235 foreach ($tables_backup_mangos as $value) { 236 mysql_table_dump ($db['addr'], $db['user'], $db['pass'], $db['name'],$value,$struc_backup,"$backup_dir/$file_name_new");236 sql_table_dump ($db['addr'], $db['user'], $db['pass'], $db['name'],$value,$struc_backup,"$backup_dir/$file_name_new"); 237 237 } 238 238 } … … 245 245 246 246 foreach ($tables_backup_mangos as $value) { 247 mysql_table_dump ($mangos_db[$realm_id]['addr'], $mangos_db[$realm_id]['user'], $mangos_db[$realm_id]['pass'], $mangos_db[$realm_id]['name'],$value,$struc_backup,"$backup_dir/$file_name_new");247 sql_table_dump ($mangos_db[$realm_id]['addr'], $mangos_db[$realm_id]['user'], $mangos_db[$realm_id]['pass'], $mangos_db[$realm_id]['name'],$value,$struc_backup,"$backup_dir/$file_name_new"); 248 248 } 249 249 } … … 273 273 fclose($fp); 274 274 275 require_once("scripts/ mysql_lib.php");275 require_once("scripts/db_layer/sql_lib.php"); 276 276 277 277 foreach ($tables_backup_realmd as $value) { 278 mysql_table_dump ($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'],$value,$struc_backup,"$backup_dir/$file_name_new");278 sql_table_dump ($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name'],$value,$struc_backup,"$backup_dir/$file_name_new"); 279 279 } 280 280 fclose($fp); … … 291 291 292 292 foreach ($tables_backup_mangos as $value) { 293 mysql_table_dump ($db['addr'], $db['user'], $db['pass'], $db['name'],$value,$struc_backup,"$backup_dir/$file_name_new");293 sql_table_dump ($db['addr'], $db['user'], $db['pass'], $db['name'],$value,$struc_backup,"$backup_dir/$file_name_new"); 294 294 } 295 295 fclose($fp); … … 304 304 305 305 foreach ($tables_backup_mangos as $value) { 306 mysql_table_dump ($mangos_db[$realm_id]['addr'], $mangos_db[$realm_id]['user'], $mangos_db[$realm_id]['pass'], $mangos_db[$realm_id]['name'],$value,$struc_backup,"$backup_dir/$file_name_new");306 sql_table_dump ($mangos_db[$realm_id]['addr'], $mangos_db[$realm_id]['user'], $mangos_db[$realm_id]['pass'], $mangos_db[$realm_id]['name'],$value,$struc_backup,"$backup_dir/$file_name_new"); 307 307 } 308 308 fclose($fp); … … 317 317 $save_all_realms = addslashes($_GET['save_all_realms']); 318 318 319 $ mysql = new MySQL;320 $ mysql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']);321 322 $query = $ mysql->query("SELECT id FROM account");319 $sql = new SQL; 320 $sql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']); 321 322 $query = $sql->query("SELECT id FROM account"); 323 323 $subdir = "$backup_dir/accounts/".date("m_d_y_H_i_s"); 324 324 mkdir($subdir, 0750); 325 325 326 326 327 while ($acc = $ mysql->fetch_array($query)){327 while ($acc = $sql->fetch_array($query)){ 328 328 $file_name_new = $acc[0]."_{$realm_db['name']}.sql"; 329 329 $fp = fopen("$subdir/$file_name_new", 'w') or die (error($lang_backup['file_write_err'])); … … 331 331 fwrite($fp, "USE {$realm_db['name']};\n\n")or die (error($lang_backup['file_write_err'])); 332 332 333 $ mysql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']);333 $sql->connect($realm_db['addr'], $realm_db['user'], $realm_db['pass'], $realm_db['name']); 334 334 335 335 foreach ($tab_backup_user_realmd as $value) { 336 $acc_query = $ mysql->query("SELECT * FROM $value[0] WHERE $value[1] = $acc[0]");337 $num_fields = $ mysql->num_fields($acc_query);338 $numrow = $ mysql->num_rows($acc_query);336 $acc_query = $sql->query("SELECT * FROM $value[0] WHERE $value[1] = $acc[0]"); 337 $num_fields = $sql->num_fields($acc_query); 338 $numrow = $sql->num_rows($acc_query); 339 339 340 340 $result = "-- Dumping data for $value[0] ".date("m.d.y_H.i.s")."\n"; … … 346 346 347 347 for($count = 0; $count < $num_fields; $count++) { 348 $result .= "`". mysql_field_name($acc_query,$count)."`";348 $result .= "`".$sql->field_name($acc_query,$count)."`"; 349 349 if ($count < ($num_fields-1)) $result .= ","; 350 350 } … … 353 353 for ($i =0; $i<$numrow; $i++) { 354 354 $result .= "\t("; 355 $row = $ mysql->fetch_row($acc_query);355 $row = $sql->fetch_row($acc_query); 356 356 for($j=0; $j<$num_fields; $j++) { 357 357 $row[$j] = addslashes($row[$j]); 358 358 $row[$j] = ereg_replace("\n","\\n",$row[$j]); 359 359 if (isset($row[$j])) { 360 if ( mysql_field_type($acc_query,$j) == "int") $result .= "$row[$j]";360 if ($sql->field_type($acc_query,$j) == "int") $result .= "$row[$j]"; 361 361 else $result .= "'$row[$j]'" ; 362 362 }else $result .= "''"; … … 378 378 fwrite($fp, "CREATE DATABASE /*!32312 IF NOT EXISTS*/ {$db['name']};\n")or die (error($lang_backup['file_write_err'])); 379 379 fwrite($fp, "USE {$db['name']};\n\n")or die (error($lang_backup['file_write_err'])); 380 $ mysql->connect($db['addr'], $db['user'], $db['pass'], $db['name']);381 $all_char_query = $ mysql->query("SELECT guid,name FROM `character` WHERE account = $acc[0]");382 383 while ($char = $ mysql->fetch_array($all_char_query)){380 $sql->connect($db['addr'], $db['user'], $db['pass'], $db['name']); 381 $all_char_query = $sql->query("SELECT guid,name FROM `character` WHERE account = $acc[0]"); 382 383 while ($char = $sql->fetch_array($all_char_query)){ 384 384 fwrite($fp, "-- Dumping data for character $char[1]\n")or die (error($lang_backup['file_write_err'])); 385 385 foreach ($tab_backup_user_mangos as $value) { 386 $sql = "SELECT * FROM $value[0] WHERE $value[1] = $char[0]"; 387 $char_query = $mysql->query($sql); 388 $num_fields = $mysql->num_fields($char_query); 389 $numrow = $mysql->num_rows($char_query); 386 $char_query = $sql->query("SELECT * FROM $value[0] WHERE $value[1] = $char[0]"); 387 $num_fields = $sql->num_fields($char_query); 388 $numrow = $sql->num_rows($char_query); 390 389 391 390 $result = "LOCK TABLES $value[0] WRITE;\n"; … … 394 393 if ($numrow){ 395 394 $result .= "INSERT INTO $value[0] ("; 396 395 397 396 for($count = 0; $count < $num_fields; $count++) { 398 $result .= "`". mysql_field_name($char_query,$count)."`";397 $result .= "`".$sql->field_name($char_query,$count)."`"; 399 398 if ($count < ($num_fields-1)) $result .= ","; 400 399 } … … 403 402 for ($i =0; $i<$numrow; $i++) { 404 403 $result .= "\t("; 405 $row = $ mysql->fetch_row($char_query);404 $row = $sql->fetch_row($char_query); 406 405 for($j=0; $j<$num_fields; $j++) { 407 406 $row[$j] = addslashes($row[$j]); 408 407 $row[$j] = ereg_replace("\n","\\n",$row[$j]); 409 408 if (isset($row[$j])) { 410 if ( mysql_field_type($char_query,$j) == "int") $result .= "$row[$j]";409 if ($sql->field_type($char_query,$j) == "int") $result .= "$row[$j]"; 411 410 else $result .= "'$row[$j]'" ; 412 411 }else $result .= "''"; … … 426 425 } 427 426 } 428 $ mysql->close();427 $sql->close(); 429 428 redirect("backup.php?error=2"); 430 429 … … 441 440 $file_tmp = "$backup_dir/accounts/$file_dir/".$file_name."_$use_db.sql"; 442 441 if (file_exists($file_tmp)){ 443 require_once("scripts/ mysql_lib.php");444 445 if ($use_db == $realm_db['name']) $queries = mysql_run_sql_script($realm_db['addr'], $realm_db['user'], $realm_db['pass'], "$backup_dir/accounts/$file_dir/$file_name.sql",true);442 require_once("scripts/db_layer/sql_lib.php"); 443 444 if ($use_db == $realm_db['name']) $queries = run_sql_script($realm_db['addr'], $realm_db['user'], $realm_db['pass'],$realm_db['name'], "$backup_dir/accounts/$file_dir/$file_name.sql",true); 446 445 else { 447 446 foreach ($mangos_db as $db) 448 if ($use_db == $db['name']) $queries = mysql_run_sql_script($db['addr'], $db['user'], $db['pass'], "$backup_dir/accounts/$file_dir/$file_name.sql",true);447 if ($use_db == $db['name']) $queries = run_sql_script($db['addr'], $db['user'], $db['pass'],$db['name'], "$backup_dir/accounts/$file_dir/$file_name.sql",true); 449 448 } 450 449
Note:
See TracChangeset
for help on using the changeset viewer.