0

我有一个备份我的 cPanel 主目录的脚本。它首先清空目标文件夹(以删除旧备份),然后运行主目录备份。我使用 cron 作业运行此脚本,但在删除阶段出现错误。我正在使用只能访问特定备份文件夹的 FTP 帐户。

<?php
// Must include cPanel API
include "xmlapi.php.inc";

// Credentials for cPanel account
$source_server_ip = ""; // Server IP or domain name eg: 212.122.3.77 or cpanel.domain.tld
$cpanel_account = ""; // cPanel username
$cpanel_password = ""; // cPanel password

// Credentials for FTP to Backup Box
$ftpacct = ""; // FTP account
$ftppass = ""; // FTP password
$email_notify = ''; // Email address for backup notification

$xmlapi = new xmlapi($source_server_ip);
$xmlapi->password_auth($cpanel_account,$cpanel_password);
$xmlapi->set_port('2083');

// Delete any other backup before create new backup
$conn_id = ftp_connect($source_server_ip);
$login_result = ftp_login($conn_id, $ftpacct, $ftppass);
$logs_dir = "/";

ftp_chdir($conn_id, $logs_dir);
$files = ftp_nlist($conn_id, ".");
foreach ($files as $file){
    ftp_delete($conn_id, $file); }

ftp_close($conn_id);

$api_args = array( 
                           'passiveftp',
                           $source_server_ip,
                           $ftpacct,
                           $ftppass,
                           $email_notify,
                            21,
                            '/'
                         );

$xmlapi->api1_query($cpanel_account,'Fileman','fullbackup',$api_args);

?>

cron错误如下。我也尝试将 $logs_dir 更改为绝对路径,但得到相同的错误。

<br />
<b>Warning</b>:  ftp_delete() [<a href='function.ftp-delete'>function.ftp-delete</a>]: Could not delete .: Invalid argument in <b>/xxxxxxxx/cpanel-backup.php</b> on line <b>27</b><br /> <br />
<b>Warning</b>:  ftp_delete() [<a href='function.ftp-delete'>function.ftp-delete</a>]: Could not delete ..: Invalid argument in <b>/xxxxxxxx/cpanel-backup.php</b> on line <b>27</b><br /> <br />

定时任务:

0   0   1   1   *   php -q /path/cpanel-backup.php
4

0 回答 0