前天下午,學校突然發生大停電,讓我回想起自己好像三月份起就忘了備份自己的 project 了,這個原因是基於壓縮後的單檔已經超過 Gmail 附件的檔案大小的關係,前陣子 bluesway 恰好有提到自己的備份 script ,就要來稍微修改修改。
使用上非常懶,直接對 svn db 壓縮,然後丟到 gmail 上,在透過 filter 將帶有 "[Backup] My Project with SVN Servce" 字樣的標題信件進行管理即可。最後就是搭配 crontab 來執行囉。
#!/bin/sh
DATE=`date +%Y%m%d%H%M`
BASE_PATH="/tmp"
BACKUP_PATH="/home/uid/svn/"
BACKUP_TEMP="${BASE_PATH}/project_svn.${DATE}.tgz"
BACKUP_EMAIL="email@gmail.com"
PREFIX_NAME="${BACKUP_TEMP}."
MAIL_SUBJECT="[Backup] My Project with SVN Servce"
/usr/bin/tar -zcvf ${BACKUP_TEMP} ${BACKUP_PATH} > /dev/null 2>&1
if [ -f ${BACKUP_TEMP} ]; then
/usr/bin/split -b 14m ${BACKUP_TEMP} ${PREFIX_NAME}
filelist=`/bin/ls ${PREFIX_NAME}*`
for fn in ${filelist}
do
#echo "/usr/local/bin/mutt -s \"${MAIL_SUBJECT} - Part - ${fn}\" -a ${fn} ${BACKUP_EMAIL}"
test -r ${fn} && /bin/ls -la ${BACKUP_PATH} | /usr/local/bin/mutt -s "${MAIL_SUBJECT} - Part - ${fn}" -a ${fn} -b ${BACKUP_EMAIL}
done
#ls -1d ${PREFIX_NAME}* | xargs -n 1 -J % /usr/local/bin/mpack -s ${BACKUP_TEMP} % ${BACKUP_EMAIL}
rm -rf ${BACKUP_TEMP}*
fi
#restore: cat ${PREFIX_NAME}* >> RESTORE_NAME
沒有留言:
張貼留言