2006-01-03, 10:45 PM
Code:
#!/bin/sh
# from and to directories, and tmp directory
BUPDIR='/backup'
SRCDIR='/usr/local/apache'
TMP='/tmp'
# keep how many?
KEEP=2
# DO NOT CHANGE ANYTHING BELOW <-- this is here for a reason
################################################
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/mysql/bin
# current date
DATE=`date | awk '{ print $3"_"$6 }'`
# filename
FILE="${BUPDIR}/apache_backup_${DATE}.tar.bz2"
# do the backup
tar -jcf $FILE --exclude='*/personal/family/gallery2/g2data/albums/2005/*' $SRCDIR >/dev/null 2>&1
if [ `ls -1 $BUPDIR | wc -l` -gt $KEEP ]; then
i=1
for each in `ls -1t $BUPDIR`; do
if [ $i -gt $KEEP ]; then
rm -f -- ${BUPDIR}/${each}
fi
let "i = i + 1"
done
fi
echo "Apache backup completed. Enjoy"
## STAGE 2
# Backup mysql
mysqldump -u ***** -p***** ***** >> ${BUPDIR}/forums_export_`date | awk '{print $2}'`_`date | awk '{print $3}'`_`date | awk '{print $6}'.sql
echo "Forums (MySQL) backup completed. Enjoy"
## STAGE 3
# Mail the admin
cat > ${TMP}/backup.txt << EOF
Hi anyweb,
I'm the backup tool from linux-noob.com and I've got a new backup for you.
The date of the backup is ${DATE}
Apache:
The new file is ${FILE} and has `du -sh $FILE | awk '{print $1}'`
Forums:
The forums backup is now: `du -sh ${BUPDIR}/forums_export.sql | awk '{print $1}'`
Have a nice day,
:)
EOF
cat ${TMP}/backup.txt | mail anyweb@linux-noob.com -s 'New Backup'
rm -f -- ${TMP}/backup.txt
should be ok..
notice the tar command was mashed in the wrong style...
1. the method is use in this fashion:
tar -jcf ARCHIVE --exclude='stuff' DIRS
2. makes it a little easier to read by using * (notice the ' not the " are used!!!!) tar will expand ..
ok.. so i hope thats all good :)
Quote:--exclude dirName
add that to the tar command
* znx slaps hijinks around with a rather large trout
hehe ;)