![]() |
|
simple automated backup of apache (your websites) - Printable Version +- Linux-Noob Forums (https://www.linux-noob.com/forums) +-- Forum: Linux Server Administration (https://www.linux-noob.com/forums/forum-8.html) +--- Forum: LAMP (https://www.linux-noob.com/forums/forum-83.html) +--- Thread: simple automated backup of apache (your websites) (/thread-2965.html) |
simple automated backup of apache (your websites) - znx - 2006-01-03 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.txtshould 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 * znx slaps hijinks around with a rather large trout hehe ;) simple automated backup of apache (your websites) - anyweb - 2006-01-04 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 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 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 simple automated backup of apache (your websites) - anyweb - 2006-01-04 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 also, when the job is complete it generates an error Quote:[root@www cron.weekly]# sh apache.cronApache backup completed. Enjoy in addition, i don't think its doing the root email cheers anyweb simple automated backup of apache (your websites) - znx - 2006-01-04 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.. :) simple automated backup of apache (your websites) - anyweb - 2006-01-04 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.txtworks fine now, as you can see below Quote:[root@www cron.weekly]# sh apache.cronApache backup completed. Enjoy 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 |