#!/bin/bash
# Script name : backup script
# plusha@gpl.snu.ac.kr


# directory names
dirList=( \
"." \
)
# exclude dir "/" should be "\/"
excDirList=( \
"UMF" \
"slatec" \
"SU" \
"lib\/dms" \
"lib\/blas" \
"FWM2DA" \
"glibc" \
"Madagascar" \
"nfft-3.0.3" \
"BEM" \
"SpiceCourses" \
"install\/fruit_2.6" \
"install\/pyxplot" \
"install\/gnuplot" \
"dmidecode" \
"PyXGraph" \
"book_src" \
"Progs_py" \
"MUMPS" \
"SuperLU" \
"launchy-2.1.2" \
)
# file extensions
extList=( \
"\.f$" \
"\.f90$" \
"\.py$" \
"\.rb$" \
"\.c$" \
"\.cpp$" \
"\.sh$" \
"Makefile$" \
"SConstruct$" \
)

# backup file base name - basename only, output: backupfileYYYYMMDD-HHMM.tgz
backupdir="/home/happywan/backup/"
backupfilebase=$backupdir"FullBackup"
Date=`date +%Y%m%d-%H%M`
backupfile="$backupfilebase$Date.tgz"

logfile=$backupdir"gplFullbackup.log"
tmpfile=$backupdir"tmpFullBackupList"
tmpfile0=${tmpfile}0

# log
echo "" >> $logfile
date >> $logfile

# log
echo "backup file: $backupfile" >> $logfile
# include dir
for dir in ${dirList[@]}
do
	for ext in ${extList[@]}
	do
		find $dir | grep $ext >> ${tmpfile0} 
	done
done
# exclude dir
for exc in ${excDirList[@]}
do
	sed "/$exc/"d ${tmpfile0} > ${tmpfile}
	mv $tmpfile $tmpfile0
done
# backup
tar -zcf $backupfile --files-from $tmpfile0 >> $logfile 2>&1

echo 'size:' `stat -c %s $backupfile` 'bytes' >> $logfile
rm ${tmpfile0}

