Showing posts with label backup. Show all posts
Showing posts with label backup. Show all posts

Mar 28, 2008

自動分割大型檔案備份至GMail

前陣子還有一台Lab的備份主機可以放系統備份,可惜在當兵期間系統就蒙主恩招,現在沒有異地備份總有一種不踏實的感覺,要定期下載備份存檔總會忘記,好在網路上也有許多免費空間可以利用,尤其是GMail這樣好用又大碗的選擇不好好利用實在是太浪費了 :P

1.申請GMail

2.安裝軟體(Postfix、Mutt、Rar)
選擇Rar的原因是只用Tar加split哪怕是傳輸中+-1Byte,就完了,rar有的加入還原資訊的選項,比較保險!!!。
Ps.執行rar指令若出現下行訊息
rar: /lib/tls/i686/cmov/libc.so.6: version `GLIBC_2.4' not found (required by rar)
表示需要GLIBC_2.4。如果沒有GLIBC_2.4可以使用rar_static
cp rar_static /usr/local/bin/rar

3.Script
#!/bin/bash
#backup to local and mail
#Author: Brandon Chen
#Email: parkghost@gmail.com

src_path=/var/www/html
dst_path=/var/www/alumni/backup/

bak_file="alumni"`date +%Y%m%d%H%M`
bak_data_recovery=15%
bak_split_size=19m
bak_mail_to=*****@gmail.com

db_user=*****
db_name=*****
db_password=*****

if ! test -d $dst_path"/mail"
then
mkdir -p $dst_path"/mail"
fi

cd $dst_path
mysqldump -u$db_user -p$db_password $db_name > $bak_file".sql"
tar --exclude .svn -zcf $bak_file".tar.gz" $src_path

cd mail
rm -rf * #remove old files
rar a -rr$bak_data_recovery -m5 -v$bak_split_size $bak_file".rar" ../$bak_file".tar.gz" > /dev/null
rar a -rr$bak_data_recovery -m5 $bak_file".sql.rar" ../$bak_file".sql" > /dev/null

for name in `ls`
do
mutt -s $bak_file -a $name $bak_mail_to < /dev/null
done

4.修改Postfix的最大寄送郵件大小
[root@alumni ~]# vi /etc/postfix/main.cf
message_size_limit = 40960000 #增加此行

5.加入系統排程
[root@alumni ~]# crontab -e
0 0 15,30 * * /var/www/alumni/scripts/backup.sh

May 12, 2007

remote backup to tape

#Server

  useradd backup
su - backup
ssh-keygen -t rsa
mv .ssh/id_dsa.pub .ssh/authorized_keys
mt -f /dev/st0 rewind
chown backup /bin/st0

#copy your key to client
(use vi to copy and past) or scp etc..

#Client

  vi backup.sh
#!/bin/sh
#remote backup to tape
#Author: Yu-Jen Chen
filename="www_"`date +%Y%m%d_%H%M%S`".tar.gz"
remote="203.64.178.107"
tar -zcf $filename /var/www/html/
scp -i id_rsa $filename backup@$remote:~
ssh -i id_rsa backup@$remote "tar -rvf /dev/st0 "$filename

#set crontab
 crontab -e
0 3 15,30 * * /var/www/backup/backup.sh