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 ;)
thanks znx,
now the script is working again, however there are still some outstanding issues,
firstly its not completing correct, it reports an error (when run directly from /etc/cron.weekly/apache.cron)
Quote:[root@www cron.weekly]# sh apache.cronApache backup completed. Enjoy
Forums (MySQL) backup completed. Enjoy
du: cannot access `/backup/forums_export.sql': No such file or directory
secondly, the date format is not the way it used to be, and the way i want it should be month/day/year or something along those lines, now instead it appears as this
Quote:[root@www backup]# ls -altotal 2739120
drwxr-xr-x 2 root root 4096 Jan 4 10:00 .
drwxr-xr-x 24 root root 4096 Jan 3 16:09 ..
-rw-r--r-- 1 root root 2756244356 Jan 4 10:00 apache_backup_4_2006.tar.bz2
-rw-r--r-- 1 root root 22908879 Jan 3 16:08 forums_export_Jan_3_2006.sql
-rw-r--r-- 1 root root 22932818 Jan 4 10:00 forums_export_.sql
so you can see the apache_backup does not list the month, just 4 for the day (4th of jan), in addition, the mysql backup does not contain any date whatsoever
can you help me resolve these final issues please ?
cheers
anyweb
i've now altered the script to include the date function for the mysql backup also,
however i still want month/day/year as the format and not the current format
see below
Quote:[root@www backup]# ls -altotal 2739388
drwxr-xr-x 2 root root 4096 Jan 4 12:06 .
drwxr-xr-x 24 root root 4096 Jan 3 16:09 ..
-rw-r--r-- 1 root root 2756485546 Jan 4 12:06 apache_backup_4_2006.tar.bz2
-rw-r--r-- 1 root root 22938116 Jan 4 12:06 forums_export_4_2006.sql
-rw-r--r-- 1 root root 22932818 Jan 4 10:00 forums_export_.sql
also, when the job is complete it generates an error
Quote:[root@www cron.weekly]# sh apache.cronApache backup completed. Enjoy
Forums (MySQL) backup completed. Enjoy
du: cannot access `/backup/forums_export.sql': No such file or directory
in addition, i don't think its doing the root email
cheers
anyweb
ok..
replace a few lines......
Code:
....
# current date
DATE=`date +"%h_%d_%Y`
....
mysqldump -u ***** -p***** ***** >> ${BUPDIR}/forums_export_${DATE}.sql
....
The forums backup is now: `du -sh ${BUPDIR}/forums_export_${DATE}.sql | awk '{print $1}'`
....
done.. :)
thanks again dude
heres the complete script for those that would like to use a similar one in the future
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
##############################
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/mysql/bin
# current date
DATE=`date +"%h_%d_%Y"`
# 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***** DATABASENAME >> ${BUPDIR}/forums_export_${DATE}.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_${DATE}.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
works fine now, as you can see below
Quote:[root@www cron.weekly]# sh apache.cronApache backup completed. Enjoy
Forums (MySQL) backup completed. Enjoy
You have mail in /var/spool/mail/root
and
Code:
-rw-r--r-- 1 root root 2756189055 Jan 4 15:38 apache_backup_Jan_04_2006.tar.bz2
-rw-r--r-- 1 root root 22946133 Jan 4 15:38 forums_export_Jan_04_2006.sql