虛擬主機自動備份 - PCZONE 討論區

返回   PCZONE 討論區 > ▲ ADSL_CABLE_FTTH 寬 頻 上 網 討 論 > -- 網站架設 / 免費空間 / 虛擬主機 專區 > ☉ -- 虛 擬 主 機 討 論 版


PCZONE 討論區



通知

☉ -- 虛 擬 主 機 討 論 版 付費虛擬主機選擇與使用心得交流。

會員
自動備份虛擬主機資料
適用: Linux + Cpanel 代管主機.... 個人試過兩家不同的主機商,都可以用.

目的: 不登入Cpanel, 每天一次自動完整備份到我個人的 Linux server.

Tach-SZ 提供一個教學 http://www.totalchoicehosting.com/fo...showtopic=7787 裡頭有PHP Script 可以用Cpanel 的cron 去自動備份, 自動ftp 到遠端的空間, 很好的東西,但是如果ServerZoo主機的空間不夠(比備份檔小),似乎會碰到失敗的命運. 如果你ServerZoo主機的空間夠大,以上的方式很推薦.

可是我的虛擬主機空間佔用太多... 空間不夠大來實作以上的方式... 所以我想了一個折衷的方式, 前提是你要有一台主機,有足夠的空間,有權限可以用 wget, shell script. 當然一般的Windows PC 也可以, 將script 改寫就可.

Script 裡的Full backup 是虛擬主機每天自動產生的full backup 檔, 在Cpanel 裡頭也看得到.

Code 如下, 複製到你的 linux 帳號下, 填上必須的資訊, change mode 700 (因為有密碼, 怕別人看到), create 一個目錄專門放備份的檔案, 然後在cron 棑個job, 每天就會自動幫你備份. 如果只想做mySQL db 的備份, 將full backup comment 掉就好了, 如果有需要, 你也可以固定每幾個小時做一次DB 的備份, DB 的備份script 會將備份檔自動加time stamp.

語法:
#!/bin/sh
cpuser="username"         # Username used to login to CPanel
cppass="password"         # Password used to login to CPanel
domain="yourdomain.com"   # Domain name where CPanel is run
mydb="mydb_name"           # MySQL DB Name
store_dir="mydirectory"  # The backup file directory path in local ex. /home/test/test1

T=`date '+%m-%d-%Y'`    # system date format MM-DD-YYYY
TS=`date '+%m-%d-%Y-%H%M%S'`# system date format MM-DD-YYYY-HHHRSS


#Full Backup
wget http://$cpuser:$cppass@www.$domain:2082/getbackup/backup-$domain-$T.tar.gz -O $store_dir/backup-$domain-$T.tar.gz

#MySQL Backup -- add the time stamp in the tail of file
wget http://$cpuser:$cppass@www.$domain:2082/getsqlbackup/$mydb.gz -O $store_dir/$mydb.gz-$TS


回覆
會員

有網友反應傳輸過程要有log... wget 本身即可以設定產生.
順便加了自動清理備份檔案的功能, 可以清理n 天前的檔案.

語法:
#!/bin/sh
#
# Cpanel Auto full backup version 1.0 (by Peter email:[email protected])
# Environment: Redhat Linux 8.0 , wget 1.81
#
# History:
# 2004-12-05 Version 1.0
#    1. Add the backup files auto-clean function.
#    2. Add the wget log during backup.
#
cpuser="username"         # Username used to login to CPanel
cppass="password"         # Password used to login to CPanel
domain="yourdomain.com"   # Domain name where CPanel is run

mydb="mydb_name"           # MySQL DB Name
store_dir="mydirectory"              # The backup file directory path in local ex. /home/test/test1

file_keep_day=10         # the days that backup files will be kept (default: 10 day)

T=`date '+%m-%d-%Y'`    # system date format MM-DD-YYYY
TS=`date '+%m-%d-%Y-%H%M%S'`    # system date format MM-DD-YYYY-HhMinSS

#clean the files before $file_keep_day days
find $store_dir -name '*' -mtime +$file_keep_day | /usr/bin/xargs rm -f {}

#Full Backup
wget http://$cpuser:$cppass@www.$domain:2082/getbackup/backup-$domain-$T.tar.gz -O $store_dir/backup-$domain-$T.tar.gz -o $store_dir/backup-$domain-$T.log

#MySQL Backup -- add the time stamp in the tail of file
wget http://$cpuser:$cppass@www.$domain:2082/getsqlbackup/$mydb.gz -O $store_dir/$mydb.gz-$TS -o $store_dir/mysqlbackup-$domain-$TS.log


回覆







 XML   RSS 2.0   RSS 
本站使用 vBulletin 合法版權程式
站務信箱 : [email protected]

本論壇所有文章僅代表留言者個人意見,並不代表本站之立場,討論區以「即時留言」方式運作,故無法完全監察所有即時留言,若您發現文章可能有異議,請 email :[email protected] 處理。