#!/bin/sh

# Version 2.6  -  February 17th 2006
# Script modified by Warren Melnick - [EMAIL PROTECTED]
# Changed the mysqldump command to use database information taken from
the vpopmail
# mysql file instead of hardcoding it to the default toaster values.

# Version 2.5  -  November 29th 2005
# Script modified by Jake Vickers - [EMAIL PROTECTED]
# Going to put the ftp (curl) options back in, and add a couple other
files from
# /var/qmail/control to take into account the new modules added into
Qmail-Toaster (namely
# Simscan, warlord and the likes) to make (hopefully) a "mirror" of the
mail server for
# backup/restore purposes.
# Also added option (rotate) to delete previous backup file before
creating a new one
# (Brent's addition, just modular-ized).

# Version 2.4  -  November 28th 2005
# Script modified by Brent Dacus - [EMAIL PROTECTED]
# Moved the backup tar up above the email so to see ls -l correctly
# Also added rm to remove last backup.  Could not see keeping all the
old backups.  Could be commented so to backup all the old backups inside
the current backup.  Could Grow LARGE if done.

# Version 2.3  -  April 14th 2005

# Script modified by Jake Vickers - [EMAIL PROTECTED]
# Commented out echo's to keep stuff from being sent to console
# Changed '>> /dev/null' to '> /dev/null 2>&1' to keep stuff from going
to console
# Added a final tar-gzip at end of script to put everything into one
nice package, and
# remove backup files created by script. (Easier to CURL and handle later)

# Version 2.2  -  May 22nd 2004

#  Added backup of/var/qmail/users/assign file.
#  Working on making a restore script.

# VERSION 2.1  -  Feb 20th 2004

#  qmailtoaster Backup script written by Nate Davis - [EMAIL PROTECTED]
#  Originally written on Dec 4th 2003.
#  This script will backup your entire qmailtoaster install!

#  Version 2.0 and up is CRON friendly.  Below you will find User Variables.
#
#  I MAKE NO PROMISES THAT IT WILL WORK.  YOU HAVE BEEN WARNED!
#  A few lines of code were copied from Nick Hemmesch <[EMAIL PROTECTED]>
#
#  Changes added by MrBiTs - [EMAIL PROTECTED]
#  Test if backup folder exists. If not, create it
#  Added long date ( YYYYMMDDHHMM ) at filenames
#  Changed filenames and backup folder for its variables

################################
#        User Variables        #
################################

#  backupdest is the Backup Destination on your HD (don't include
trailing /)
#  ex:  backupdest=/backuphd/toasterbackup
backupdest=/backup01/qmailbkup

## FTP Information and Destination
useftp=n    # y or n - This will upload the files backed up via FTP
using Curl

#  Syntax for ftpserver:  ftp://user:[EMAIL PROTECTED]/folder 
(WITHOUT Trailing /)
ftpserver=ftp://

## E-Mail Information and Destination
emailinfo=n    # y or n - This will Send you an e-mail after the Cron
Job Runs each time.

#  Syntax for email:  [EMAIL PROTECTED]
[EMAIL PROTECTED]

## Remove previous backup file before creating a new one? ( y or n )
removeprevious=n

################################
#  Actual Backup Script Below  #
################################

# MYSQL variables
mysqlfile="/home/vpopmail/etc/vpopmail.mysql";
mysqlhost=`cut -d\| -f1 < $mysqlfile`;
mysqlport=`cut -d\| -f2 < $mysqlfile`;
mysqluser=`cut -d\| -f3 < $mysqlfile`;
mysqlpswd=`cut -d\| -f4 < $mysqlfile`;
mysqldb=`cut -d\| -f5 < $mysqlfile`;
if [ $mysqlport == "0" ]; then
mysqlport=""
else
mysqlport="-P$mysqlport"
fi

if [ ! -d $backupdest ] ; then
        mkdir -p $backupdest
echo
fi

#  Creating backup filenames with date
DATENAME=`date +%Y%m%d%H%M`
QMAILCONTROL="$DATENAME-qmailcontrol.tar.bz2"
VPOPMAIL="$DATENAME-vpopmail.tar.bz2"
DATABASE="$DATENAME-vpopmail.sql"
gzmysqldata="$DATENAME-vpopmail.sql.gz"
usersassign="$DATENAME-assign.tar.bz2"
curlfile="$DATENAME-backup.tar.gz"

if [ $removeprevious = y ] ; then
#echo "Removing old backup file"
cd $backupdest
rm -rf *-backup.tar.gz
fi

starttime=`date [EMAIL PROTECTED]
#echo "Backing up qmail config files"
cd /var/qmail/control
tar cfj $backupdest/$QMAILCONTROL rcp* virtual* more* bad* black*
concurrency* data* queue* smtp* > /dev/null 2>&1

#echo "Backing up vpopmail domains"
cd $backupdest
tar cfj $VPOPMAIL /home/vpopmail/domains > /dev/null 2>&1

#echo "Backing up MYSQL Data"
mysqldump -u$mysqluser -p$mysqlpswd -h$mysqlhost $mysqlport $mysqldb >
$backupdest/$DATABASE
gzip $backupdest/$DATABASE 2>&1

#echo "Backup /var/qmail/users/assign file"
tar cfj $backupdest/$usersassign /var/qmail/users/assign > /dev/null 2>&1

#echo "Putting all backup files into one large archive"
cd $backupdest
tar czf $curlfile * > /dev/null 2>&1
rm -rf $QMAILCONTROL
rm -rf $VPOPMAIL
rm -rf $gzmysqldata
rm -rf $usersassign
rm -rf $DATABASE

endtime=`date [EMAIL PROTECTED]

if [ $emailinfo = y ] ; then
echo "The Toaster Backup has Run.  Please verify that it did it
correctly." > /tmp/emailmsg.txt
echo " " >> /tmp/emailmsg.txt
echo "Backup Start Time: $starttime" >> /tmp/emailmsg.txt
echo " " >> /tmp/emailmsg.txt
echo "Backup End Time: $endtime" >> /tmp/emailmsg.txt
echo "  " >> /tmp/emailmsg.txt
echo "ls -lh command on $backupdest" >> /tmp/emailmsg.txt
echo " " >> /tmp/emailmsg.txt
ls -lh $backupdest >> /tmp/emailmsg.txt
cat /tmp/emailmsg.txt | mail -s"Toaster Backup Executed $endtime" $email
rm -f /tmp/emailmsg.txt
fi

if [ $useftp = y ] ; then
curl -T $backupdest/$curlfile $ftpserver/$curlfile

echo " Backup has been uploaded to the FTP Server and"
echo " is also located in: $backupdest"
else
echo " Backup is complete and located in: $backupdest"
fi



---------------------------------------------------------------------
     QmailToaster hosted by: VR Hosted <http://www.vr.org>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to