前提:具有ssh登陸權限
工作步驟:
格式:
pXXXXXXX@kundenserver:~ > mysqldump -hdbXX.puretec.de -upXXXXXXX -p******** dbXXXXXXX > dbXXXXXXXX.sql
pXXXXXXX@kundenserver:~ > mysql -hdbXX.puretec.de -upXXXXXXX -p******** dbXXXXXXX < dbXXXXXXXX.sql
你也可以寫一個php腳本,來完成以上操作:
備份文件
include "../config.php";
MYSQL_CONNECT($dbhost, $dbuser, $dbpw) or die ( "<H3>無法訪問數據庫</H3>");
MYSQL_SELECT_DB($dbname) or die ( "<H3>數據庫尚未建立</H3>");
$path = getenv('DOCUMENT_ROOT')."/DB_backup";
$result = MYSQL_QUERY("SHOW TABLES");
$numrow = MYSQL_NUM_ROWS($result);
for($i = 0;$i < $numrow;$i++) {
$table = MYSQL_RESULT($result,$i);
echo "$table ... ";
system(sprintf("mysqldump --opt -h $dbhost -u $dbuser -p$dbpw $dbname $table | gzip > %s/$table.sql.gz",$path));
echo "DONE\n\n";
}
MYSQL_CLOSE();
恢復文件
include "../config.php";
system(sprintf(
'gunzip -c %s/dump.sql.gz | mysql -h %s -u %s -p%s %s',
getenv('DOCUMENT_ROOT'),
$dbhost,
$dbuser,
$dbpw,
$dbname
));
echo '+DONE';