Database Backup
Posted: Thu Jul 07, 2005 4:11 am
What should i do , if i wanna take backup of a mysql database from my system. and upload it to my web server and apply the backup...
Thx in advance
Thx in advance
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
mysqldump databasename -u username -p > databasename.sqlCode: Select all
//Login to MySQL using
mysql -u username -p
//Then select the database you want to add it to (create one if you dont have one)
use databasename;
//Then insert the backup SQL (note the \. )
\. /path/to/sql/file.sql;Code: Select all
<?php
$maxsize = 1887436;
$file = fopen("hugegreatdumpfile.sql", "r");
$tables = fopen("tables.sql", "w");
$data = fopen("data_".++$d.".sql", "w");
while (!feof($file)) {
if ($count >= $maxsize) {
fclose($data);
$data = fopen("data_".++$d.".sql", "w");
$count = 0;
}
$line = fgets($file, 100000);
if (substr($line,0,6) == "INSERT") {
fwrite($data,$line);
$count += strlen($line);
} elseif (substr($line,0,1) == "#") {
} else {
fwrite($tables,$line);
}
}
echo "Completed: ".$d." data files created.";
?>Code: Select all
<?php
$maxsize = 1887436;
$file = fopen("hugegreatdumpfile.sql", "r");
$tables = fopen("tables.sql", "w");
$data = fopen("data_".++$d.".sql", "w");
while (!feof($file)) {
if ($count >= $maxsize) {
fclose($data);
$data = fopen("data_".++$d.".sql", "w");
$count = 0;
}
$line = fgets($file, 100000);
if (substr($line,0,6) == "INSERT") {
fwrite($data,$line);
$count += strlen($line);
} elseif (substr($line,0,1) == "#") {
} else {
fwrite($tables,$line);
}
}
echo "Completed: ".$d." data files created.";
?>
[/php:1_".++$d.".sql", "w");
while (!feof($file)) {
if ($count >= $maxsize) {
fclose($data);
$data = fopen("e;data_"e;.++$d."e;.sql"e;, "e;w"e;);
$count = 0;
}
$line = fgets($file, 100000);
if (substr($line,0,6) == "INSERT") {
fwrite($data,$line);
$count += strlen($line);
} elseif (substr($line,0,1) == &qudata seperately is a good idea. Generally the data isn't a problem. It just works. However, the structure sometimes needs a bit of a tweak, especially if the mysql versions are different. If you export the structure seperate you won't have to trawl through masses of data to fix things.
Also, if you resort to using PhpMyAdmin, you might find this helpful.. it takes an sql dump and breaks it into 1.8meg chunks (and seperates the structure stuff too).Code: Select all
<?php
$maxsize = 1887436;
$file = fopen("hugegreatdumpfile.sql"e;, "e;r"e;);
$tables = fopen("e;tables.sql"e;, "e;w"e;);
$data = fopen("e;data_"e;.++$d."e;.sql"e;, "e;w"e;);
while (!feof($file)) {
if ($count >= $maxsize) {
fclose($data);
$data = fopen("e;data_"e;.++$d.he structure sometimes needs a bit of a tweak, especially if the mysql versions are different. If you export the structure seperate you won't have to trawl through masses of data to fix things.
Also, if you resort to using PhpMyAdmin, you might find this helpful.. it takes an sql dump and breaks it into 1.8meg chunks (and seperates the structure stuff too).Code: Select all
<?php
$maxsize = 1887436;
$file = fopen("e;hugegreatdumpfile.sql"e;, "e;r"e;);
$tables = fopen("e;tables.sql"e;, "e;w"e;);
$data = fopen("e;data_"e;.++$d."e;.sql"e;, "e;w"e;);
while (!feof($file)) {
if ($count >= $maxsize) {
fclose($data);
$data = fopen("e;data_"e;.++$d."e;.sql"e;, "e;w"e;);
$count = 0;
}
$line = fgets($file, 100000);
if (substr($line,0,6) == "e;INSERT"e;) {
fwrite($data,$line);
$count += strlen($line);
} elseif (substr($line,0,1) == "e;#"e;) {
} else {
fwrite($e data seperately is a good idea. Generally the data isn't a problem. It just works. However, the structure sometimes needs a bit of a tweak, especially if the mysql versions are different. If you export the structure seperate you won't have to trawl through masses of data to fix things.
Also, if you resort to using PhpMyAdmin, you might find this helpful.. it takes an sql dump and breaks it into 1.8meg chunks (and seperates the structure stuff too).Code: Select all
<?php
$maxsize = 1887436;
$file = fopen("hugegreatdumpfile.sql", "r");
$tables = fopen("tables.sql", "w");
$data = fopen("data_".++$d.".sql", "w");
while (!feof($file)) {
if ($count >= $maxsize) {
fclose($data);
$data = fopen("data_".++$d.".sql", "w");
$count = 0;
}
$line = fgets($file, 100000);
if (substr($line,0,6) == "INSERT") {
fwrite($data,$line);
$count += strlen($line);
} elseif (substr($line,0,1) == "#") {
} else {
fwrite($tables,$line);
}
}
echo "Completed: ".$d." data files created.";
?>Code: Select all
mysqldump -u root -pyourpassword yourdatabase > d:\yourpath\yourfile.sqlCode: Select all
mysql -B -u root --password=yourpassword -h localhost yourdatabase < d:\yourpath\yourfile.sql