#!/bin/sh
# Backup /var/local/ and /home using "dump"
# also backs up /root
# intended to be run by cron.daily [which happens at 4 a.m.]
#
# call manually with "backup -7" to create the level 0 dump
# creates a level 1 on Tuesday, level 2 on Wednesday, etc.
# This is done because occasionally a backup file will become humongous,
# and the memory stick can't accommodate a week's worth of these.
# Note: the name of the file is the "data" day, not the day the
# backup was physically made.
#

# if it's mounted something is wrong.
if mount|grep "media/flash"; then
	exit -1
fi

LEVEL=9	# safety fallback; should never happen
FILENAME=9

DOW=`date +%w`	# day of week (0-6; 0 = Sunday)
#DOM=`date +%d`	# day of month (1-31)

if [ $1 -gt 6 ]; then	# manual dump 0
	DOW=7
fi

if [ $DOW == 1 ]; then	# monday: make level 0
	LEVEL=0
	FILENAME=0
elif [ $DOW == 2 ]; then	# tuesday
	LEVEL=1
	FILENAME=1_mon
elif [ $DOW == 3 ]; then	# wednesday
	LEVEL=2
	FILENAME=2_tue
elif [ $DOW == 4 ]; then	# thursday
	LEVEL=3
	FILENAME=3_wed
elif [ $DOW == 5 ]; then	# friday
	LEVEL=4
	FILENAME=4_thu
elif [ $DOW == 6 ]; then	# saturday
	LEVEL=5
	FILENAME=5_fri
elif [ $DOW == 0 ]; then	# sunday
	LEVEL=6		
	FILENAME=6_sat
else			 # level 0
	LEVEL=0
	FILENAME=0
fi

export LEVEL
export FILENAME

mount /media/flash || exit -1
# exclude (-e <inode list>)
/sbin/dump -$LEVEL -q -u -e 29,34,625,1238 -f /media/flash/home$FILENAME /dev/mapper/vg_wstock-LogVol02 || exit -1

cp -pr /etc/hosts /root/conf.d
cp -pr /etc/passwd /root/conf.d
cp -pr /etc/group /root/conf.d
cp -pr /etc/shadow /root/conf.d
/bin/tar -czf /media/flash/root.tgz /root || exit -1

umount /media/flash

