![]() |
|
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) - anyweb - 2004-12-30 the lan ftp server is a windows box, its only a local ftp, no access from the outside (internet) so i was hoping to modify the above script to do the following: * after the backup file has been created, login to the ftp server, and check if there are any files present * if the number of files present is 2 or less then start uploading the current backup * if the number of files present is 3 or more, delete the oldest file, and start uploading the current backup that's all i want it to do help ! cheers anyweb simple automated backup of apache (your websites) - xDamox - 2004-12-31 Hi, I aint that good with shell script but heres a solution in perl :) you can run it via command prompt: Code: perl -e 'use Net::FTP; $Host = "10.0.0.14"; $username = "test"; $password = "test123"; $ftp = Net::FTP->new($Host, Debug => 0) || die "Could not connect to ftp $@"; $ftp->login($username, $password) || die "Could not login" .$ftp->message; $ftp->put("Test.log", "Test.log") || die "failed to upload" . ftp->message; $ftp->quit;'well thats all thats needed ;) simple automated backup of apache (your websites) - JerLasVegas - 2005-01-20 As an alternative you can always set up a ssh connection between the two computers using ssh-keygen and then use rsync -ave ssh! simple automated backup of apache (your websites) - anyweb - 2005-02-02 ok i'm still playing with this and now i want to backup the mysql database weekly also, the exact same way as i am doing with apache. the command to backup the database is executed from /usr/local/mysql/bin and it's Code: ./mysqldump -u USER -p DATA >> forums_export.sqli then have to input the root password so, how can i automate this ? any ideas :) cheers anyweb simple automated backup of apache (your websites) - KobrAs - 2005-02-02 you almost figure it out youreself :) after the -p etner the password Code: ./mysqldump -u USER -p password DATA >> forums_export.sqlsimple automated backup of apache (your websites) - anyweb - 2005-02-03 ok i've tried but its not working totally right have a look at my script now Code: #!/bin/sh
/bin/tar -jcf /backup/apache_backup_`date | awk '{print $2}'`_`date | awk '{print $3}'`_`date | awk '{print $6}'`.tar.bz2 /usr/local/apache/ 1&>/dev/null 2&>/dev/null
# How many files would you like to keep?
KEEP=2
# Where are the files stored?
BACKUPDIR=./backup
# DO NOT CHANGE ANYTHING BELOW
if [ `ls -1 $BACKUPDIR|wc -l` -gt $KEEP ]; then
i=1
for each in `ls -1t $BACKUPDIR`; do
if [ $i -gt $KEEP ]; then
rm -f $BACKUPDIR/$each
fi
i=`expr $i + 1`
done
fi
#setting paths and files
#setting log path
tmp=$tmp
file=/backup/apache_backup_`date | awk '{print $2}'`_`date | awk '{print $3}'`_`date | awk '{print $6}'`.tar.bz2 >>$tmp/apachebackup.txt
space=`du -sh $file | awk '{print $1}'`
date=`date`
echo -n "" >$tmp/apachebackup.txt
echo "Hi anyweb, i am the backup tool from linux-noob.com, i got a new backup for you" >>$tmp/apachebackup.txt
echo "the new file is $file and has $space" >>$tmp/apachebackup.txt
echo "the date is $date" >>$tmp/apachebackup.txt
cat $tmp/apachebackup.txt | mail anyweb@linux-noob.com -s 'new backup'
rm -rf $tmp/apachebackup.txt
echo -e "Enjoy"
#backup mysql
./mysqldump -u USER-p PASSWORD DATABASENAME >> /backup/forums_export_`date | awk '{print $2}'`_`date | awk '{print $3}'`_`date | awk '{print $6}'`.sqlchecking /backup i now have as follows: Quote:ls -al /backuptotal 5433644there should only be TWO apache backups, and one forums backup. That part looks ok but the script is erroring out on me...\ the errors i get after the script is done are Quote:[root@www cron.weekly]# ./apache.cronls: ./backup: No such file or directory i've fixed the mysqldump error with cd /usr/local/mysql/bin && ./mysqldump...... but i don't get the other one ? simple automated backup of apache (your websites) - znx - 2005-08-25 Hey, stray . in the BACKUPDIR=/backup <-- Slight cleaning of the script (which I like btw :)) 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 | awk '{ print $3"_"$6 }'`
# filename
FILE="${BUPDIR}/apache_backup_${DATE}.tar.bz2"
# do the backup
tar -jcf $FILE $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 USER-p PASSWORD DATABASENAME >> ${BUPDIR}/forums_export.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.txtsimple automated backup of apache (your websites) - anyweb - 2006-01-03 thanks znx ! now onto my next issue, ive installed Gallery, and its working nicely, however by copying over the entire photos from 2005 to my personal website, the backup file is going to be close to 7GB in size, so what i want to do is to exclude the following path from the backup Code: /usr/local/apache/websites/.../family/gallery2/g2data/albums/2005how do i EXCLUDE the above path and all files in it from the backup script i'm currently using ? thanks in advance ! the ... is simply representing some other folders removed for clarity simple automated backup of apache (your websites) - hijinks - 2006-01-03 --exclude dirName add that to the tar command simple automated backup of apache (your websites) - anyweb - 2006-01-03 thanks dude but something is seriously wrong here, i've changed the script and ran it to test it, before i ran it, approx 15gb free on the hdd (if not more) now its at Code: [root@www /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup01-LogVol00
36G 27G 6.7G 81% /
/dev/hda1 99M 23M 72M 24% /boot
/dev/shm 125M 0 125M 0% /dev/shmand the script isnt complete yet (started hours ago, 5 or six hours ago....) here's a copy of the script, please tell me what is causing it to nosedive my server 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 | awk '{ print $3"_"$6 }'`
# filename
FILE="${BUPDIR}/apache_backup_${DATE}.tar.bz2"
# do the backup
tar -jcf --exclude /usr/local/apache/websites/kicks-ass/personal/family/gallery2/g2data/albums/2005 $FILE $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.txthelp ! cheers anyweb |