前提:具有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
";
}
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";