#!/sbin/sh

bak() { 
  mv -f old/${1}.6.gz old/${1}.7.gz 2>/dev/null
  mv -f old/${1}.5.gz old/${1}.6.gz 2>/dev/null
  mv -f old/${1}.4.gz old/${1}.5.gz 2>/dev/null
  mv -f old/${1}.3.gz old/${1}.4.gz 2>/dev/null
  mv -f old/${1}.2.gz old/${1}.3.gz 2>/dev/null
  mv -f old/${1}.1.gz old/${1}.2.gz 2>/dev/null
  mv -f ${1} old/${1}.1
  touch ${1}
  files="${files} old/${1}.1"
}

umask 022
cd /var/log/mail
files=


case $1 in
    daily)
	bak mail.info
	bak mailbox
	bak router
	bak smtpserver
	bak smtp
	bak scheduler
	kill -HUP `cat /etc/syslog.pid`
	;;
    weekly)
	sleep 1
#	bak cron
#	chmod 600 cron
#	kill -HUP `cat /var/run/crond.pid`
	;;
    monthly)
	bak wtmp
	bak xferlog
	bak lastlog
	chmod 640 xferlog
	chown ftp.ftp xferlog
	;;
  *) echo "Start with 'daily', 'monthly' or 'weekly'" ; exit ;;
esac

sleep 10

if [ "x${files}" != "x" ]; then
  nice gzip -9f ${files}
fi
