dongzhanlu8890 2013-06-17 00:51 采纳率: 0%
浏览 71
已采纳

PHP MySQL数据库备份cron作业

I wanted to have database backup cron in webserver, I use following codes to output sql file:

<?php
include('connectdb.php');

$backupFile = 'database_backup_'.date("YmdHis").'.sql';
$command = 'mysqldump $dbname --password=$dbpass --user=$dbuser --single-transaction >'.$backupFile;
system($command);

include('closedb.php');
?>

but when I open the specific sql file, its only show text like this:

Usage: mysqldump [OPTIONS] database [tables]
OR     mysqldump [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]
OR     mysqldump [OPTIONS] --all-databases [OPTIONS]
For more options, use mysqldump --help

What's wrong with my code?

Thanks.

  • 写回答

4条回答 默认 最新

  • dszdiavv474681 2013-06-17 18:50
    关注

    Try your mysqldump command from the command line with the correct parameters. Does it work? What errors does it report, if any (use the --verbose switch)? Fix them and try again.

    When you've debugged your command, submit it directly to cron - no need to run it through a PHP script.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?