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
cron – unethost無限空間虛擬主機 技術分享部落格

如何設定mysql的自動備分

cpanel有一個功能是mysql備分,這個功能有一個不足的地方是,沒有辦法設定成自動化的。然而,只要透過ftp上傳一個shell script,再加上crontab的設定,還是可以完成類似的事。

下方是shell script的內容,將這個shell script用文字編輯器,編輯好之後,存檔成為backup.sh。並且在透過ftp上傳到使用者的家目錄下之後,加上可執行的權限。

#!/bin/sh
receiver=此處填要用來收backup的email
mysql_username=此處填mysql的使用者名稱
mysql_dbname=此處填mysql的資料庫名稱
mysql_userpwd=此處填mysql的密碼
file=./mysqldb_`date ‘+%m-%d-%Y’`.sql.gz
name=mysqldb_`date ‘+%m-%d-%Y’`.sql.gz
mysqldump -u $mysql_username -p$mysql_userpwd -h localhost –routines  –single-transaction  –skip-add-locks –skip-lock-tables –default-character-set=utf8 $mysql_dbname | gzip > $file
uuencode $file $name  | mail -s “Database backup” $receiver
rm $file

 

接著就要來設定cron job,cron job可以透過cpanel的GUI來設定。下方的例子,就是每天的0時0分要執行一次這個backup.sh。

0 0 * * * /home/使用者名稱/backup.sh>/dev/null 2>&1