我需要通过 CLI 执行 php 脚本的帮助。不确定这是 Linux 还是 PHP 问题。
当我在 Ubuntu 中执行 /usr/bin/php /var/www/backup.php 时,我得到:
您无权执行此脚本
backup.php 中的代码是:
<?php
// Set default paths
define ("DOCUMENT_ROOT","/var/www");
define ("DATABASE_PATH","/var/lib/mysql/livedb");
define ("BACKUP_PATH","/var/sitebackups");
$filename_suffix = "_" . date("Ymd_his") .".tar.gz";
if ($_GET['key']!="xxx") {
die ("You are not permitted to execute this script");
}
//change working directory to backup directory
if (!chdir(BACKUP_PATH)) {
die ("Failed to change to working directory.");
}
// Tar the web files
$cmd = "tar -cvzf " . BACKUP_PATH. "/webfiles" . $filename_suffix . " " .DOCUMENT_ROOT ;
echo $cmd . "<br/>";
//echo shell_exec($cmd);
// Create link to web files backup
// Tar the mysql DB
$cmd = "tar -cvzf " . BACKUP_PATH. "/dbfiles" . $filename_suffix . " " .DATABASE_PATH ;
echo $cmd . "<br/>";
//echo shell_exec($cmd);
// Move to backup folder
// Create link to DB backups
// Email backup confirmation
?>
我什至尝试通过 crontab 添加这是一个计划任务,但我仍然在日志中收到相同的错误。
请帮忙!