Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(): Failed opening '/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php' for inclusion (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24
cronjob – unethost無限空間虛擬主機 技術分享部落格

排程與效能的問題

cronjobs_wp

我們曾介紹過關於主機效能的文章:
1.用linux的top指令來抓出主機的效能瓶頸
2.php handler
3.如何設定排程 cron jobs,解決fastcgi崩潰問題?

關於排程的狀況,如果將排程都設定在一起,會發生效能的問題。

閱讀全文 排程與效能的問題

如何設定cpanel單一帳戶的遠端自動備份?

cpanel有提供可以從外部呼叫的API,如果活用這些API,就可以做到:定時將帳戶的內容備分到遠端的ftp主機中。

實作方法:

(1) 準備好用來作遠端備分的ftp,並且在ftp的登入目錄裡,加上 /backup/AAA這個目錄,建議AAA的部分,取有意義一點的名稱,最好和網站的名稱相關。

(2)  在cpbackup.php 這個檔案之中,要先做對應的修改,總共需要改九行

// Credentials for cPanel account ( 這邊填原始,要被備分的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 remote site ( 這邊填遠端的ftp資訊 )
$ftphost = “”; // FTP host IP or domain name
$ftpacct = “”; // FTP account
$ftppass = “”; // FTP password
$email_notify = “”; // Email address for backup notification
//
// Delete any other backup before create new backup
$conn_id = ftp_connect($ftphost);
$login_result = ftp_login($conn_id, $ftpacct, $ftppass);
$logs_dir = “/backup/AAA“;
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’,
                           $ftphost,
                           $ftpacct,
                           $ftppass,
                           $email_notify,
                            21,
                            /backup/AAA
                         );

(3) 用ftp 上傳檔案
在account的public_html  下,放上這兩個檔案,( 檔案在此可以下載,選cpbackup script )
xmlapi.php
cpbackup.php

在這邊要特別注意一點:
backup這個功能,因為相對消耗資源,放在public_html下,是說可以透過browser來啟動,很方便。但是,如果是很容易被攻擊的網址。就最好不要放在這麼明顯的地方。

(4) 此處,有兩種方法可以執行這個php來做檔案的備分:
(a)  在browser上, http://你的域名/cpbackup.php
(b)  用該account的id/pw ( 不要用root的 )   ssh 登入這個account, 然後下指令     php -q /home/你的帳戶名稱/public_html/cpbackup.php 

理論上,出現的message應該是長成這樣子:

Warning: ftp_delete(): Could not delete .: Invalid argument in /home/blog66rr/public_html/cpbackup.php on line 28
Warning: ftp_delete(): Could not delete ..: Invalid argument in /home/blog66rr/public_html/cpbackup.php on line 28
{“apiversion”:”1″,”type”:”event”,”module”:”Fileman”,”func”:”fullbackup”,”source”:”module”,”data”:{“result”:””},”evenls -l /home/blog66rr/public_html/cpbakcup.php

這樣子,資料應該就會備分到你的ftp了。

另外,週期性執行不一定需要。如果說只做一次的話,就不用這麼麻煩。用這個方式,因為是透過ftp的關系,比較不會受到browser 斷線的問題。ftp比較適合處理這種大型的backup檔。

(5) 用該account的id/pw ( 不要用root的 )   ssh 登入這個account
下指令:
crontab -e

這樣子是設定每天備分:
0 0 * * *   php -q /home/你的帳戶名稱/public_html/cpbackup.php
這是每週備分
@weekly    php -q /home/你的帳戶名稱/public_html/cpbackup.php
這是每月備分
@monthly  php -q /home/你的帳戶名稱/public_html/cpbackup.php

(6) 最後還有一個但書。在用來backup的ftp這邊,會有一個問題:檔案愈積愈多。所以在用來backup的ftp主機這邊。最好也設置工作排程 ( cronjob )

find /path/to/files* -mtime +5 -exec rm {} \;

這個指令的意思是:到 /path/to/files* 這邊,找出超過5天沒有使用的檔案,將它刪除。

 

(備註:unethost.com虛擬主機,已有每日自動異地備份)