#!/bin/bash

DIR=/var/backup/hordebackup/
OUT=imapfix`date +%y%m%d`
TMP=/tmp/5daysago$$
VMAIL=vmail.bak.`date +%y%m%d`

# Backup the current vmail file
mv /etc/vmail/ $DIR/$VMAIL
tar zcf $DIR$VMAIL.tar.gz $DIR$VMAIL 2>> $DIR/$OUT
rm -rf $DIR$VMAIL

# Updateuserdomains script
/scripts/updateuserdomains > $DIR/$OUT

# Fix mail permissions
/scripts/mailperm >> $DIR/$OUT

# The following looks for files in the /root/hordebackup directory, and deletes any that are over 5 days old. 
/bin/touch -t `/bin/date --date='5 days ago' +%Y%m%d%H%M` $TMP >> $DIR/$OUT
/usr/bin/find $DIR -type f ! -newer $TMP -exec rm -f {} \; 2>> $DIR/$OUT
/usr/bin/find $DIR -type d -empty -exec rmdir {} \; 2>> $DIR/$OUT
/bin/rm -f $TMP >> $DIR/$OUT
