【发布时间】:2011-12-10 16:58:51
【问题描述】:
我开发了一个脚本,我的公司用来通过创建客户数据库的转储文件在我们的服务器上备份客户的数据库。这是我的代码:
$result=mysql_query("SELECT * FROM backup_sites");
while($row=mysql_fetch_array($result)){
$backup_directory=$row["backup_directory"];
$thishost=$row["host"];
$thisusername=$row["username"];
$thispassword=$row["password"];
$thisdb_name=$row["db_name"];
$link=mysql_connect("$thishost", "$thisusername", "$thispassword");
if($link){
mysql_select_db("$thisdb_name");
$backupFile = $thisdb_name ."-". date("Y-m-d-H-i-s", strtotime ("+1 hour")) . '.sql';
$command = "/usr/bin/mysqldump -h $thishost -u $thisusername -p$thispassword $thisdb_name > site-backups/$backup_directory/$backupFile";
system($command);
}
}
该脚本从一个表 (backup_sites) 中获取所有客户端的数据库信息,并循环遍历每一个以在该客户端的目录中创建备份文件。该脚本在手动执行时效果很好。我遇到的问题是当我将它设置为作为 Cron 作业运行时它不起作用。来自 Cron 作业的电子邮件包含每次数据库备份尝试的此错误:
sh: site-backups/CLIENT_DIRECTORY/DB_DUMP_FILE.sql: No such file or directory
因此,无论出于何种原因,Cron 作业都无法创建/写入 DB 转储文件。我想不通这个。脚本在手动执行时完美运行似乎很奇怪。有人有想法么?提前致谢!
亚当
【问题讨论】:
-
你在用什么 cron 命令?
标签: cron