#!/bin/sh
# Does a backup with date of selected files.
while [ -n "`echo $1 | grep '^-'`" ]; do
case $1 in
-d)
format=date;
shift
;;
-v)
format=version;
shift
;;
-h)
echo "Usage: mtt_backup [-d|-v] [lib|doc]";
exit
;;
*)
format=date;
esac
done
#Name of archive
if [ -z "$1" ]; then
mtt="mtt"
dirs='mtt mtt-lib mtt-cc mtt-doc'
else
mtt="mtt-$1"
dirs=$mtt
fi
## Create appropriate filename
case $format in
date)
filename=`date | gawk '{printf("%s_%s%s_%s.tgz\n", mtt, $2,$3,$6)}' mtt=$mtt`;
shift
;;
version)
filename=`mtt --version | gawk '{printf("%s-%s.tar.gz\n", mtt, $NF)}' mtt=$mtt`;
shift
;;
*)
esac
echo Backup file $filename
#Check whether archive exists here
if [ -f "$filename" ]; then
echo File $filename already exists - exiting
exit
fi
# Listing files to ignore
#echo Finding irrelevant files
#find $dirs -name '*.*' -print |\
# grep 'dvi$\|ps$\|gif$\|log$\|dat$\|MTT_work\|core\|~$' >IGNORE
#wc IGNORE | gawk '{print "Ignoring", $1, "files"}'
#echo examples >> IGNORE
#Inform user
echo Backing up $dirs to $filename
#Tar the files
#tar --exclude-from IGNORE --create --gzip --file $filename $dir
tar --create --gzip --file $filename $dirs
#Size info
ls -l $filename
#