Well, here's the story, i needed a backup for a webserver (CentOS5.2) that backed up mySQL and directories that i specified, ftp'd them to TWO ftp servers and emailed me the result. I couldn't find one that would do it, so i gathered idea's from other scripts that i found until i ended up with this (NOTE: all credit goes to original authors, i just complied it into one...) :
Simply comment out the bits you won't use...
Save as filename.sh
Remember to chmod +x filename.sh and add it into cron for automated backup.
#!/bin/sh #Script Modified Maintained by Bradly Sharpe #ALL CREDIT BELONGS TO ORIGINAL AUTHORS #Version 0.2 #-------------------------------------------------------------------------- ### START OF USER CONFIGURATION ### ### System Setup ### DIRS="/opt/data /var/www/html" #Directories to backup NOW=$(date +"%d-%m-%Y") #Date format applied to backups BACKUP=/etc/backup/$NOW #Where backups are stored before FTP INCFILE="/root/tar-inc-backup.dat" #Leave as is ### MySQL Setup ### MUSER="mySQLuser" #mySQL Username (must have suffice permissions MPASS="mySQLpass" #mySQL Password MHOST="mySQLhost" #mySQL Host (localhost, 192.168.0.x) MYSQL="$(which mysql)" #Leave as is MYSQLDUMP="$(which mysqldump)" #Leave as is GZIP="$(which gzip)" #Leave as is ### FTP server Setup ### NCFTP="$(which ncftpput)" #Leave as is (Uses ncftp client) ### FTP SERVER 1 ### FTPD="/directory" #Directory on FTP server to save files to FTPU="ftpuser" #FTP username FTPP="ftppass" #FTP password FTPS="serverIP" #FTP server hostname or IP ### FTP SERVER 2 ### #FTPD2="/directory" #Same as above #FTPU2="ftpuser" #Uncomment here and section #FTPP2="ftppass" #below to FTP to multiple #FTPS2="serverIP" #FTP servers. ### Email Configuration ### MAILADDR="emailaddress" #Where to send backup email ### END OF USER CONFIGURATION ### ### Start Backup for file system ### [ ! -d $BACKUP ] && mkdir -p $BACKUP || : FILE="FileSystem-$NOW.tar.gz" tar -g $INCFILE -zcvf $BACKUP/$FILE $DIRS ### MySQL Databases Backup ### DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')" for db in $DBS do FILE=$BACKUP/mysql-$db.$NOW.gz $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db | $GZIP -9 > $FILE done ### Dump backup using FTP SERVER 1 ### ncftp -u"$FTPU" -p"$FTPP" $FTPS<<EOF mkdir $FTPD mkdir $FTPD/$NOW cd $FTPD/$NOW lcd $BACKUP mput * quit EOF ### Dump backup using FTP SERVER 2 ### #ncftp -u"$FTPU2" -p"$FTPP2" $FTPS2<<EOF #mkdir $FTPD2 #mkdir $FTPD2/$NOW #cd $FTPD2/$NOW #lcd $BACKUP #mput * #quit #EOF ### Did ftp backup failed? ### if [ "$?" == "0" ]; then mail -s "Backup Finished Successfully" $MAILADDR < /dev/null rm -rf $BACKUP else mail -s "Backup Failed" $MAILADDR < /dev/null fi
Simply comment out the bits you won't use...
Save as filename.sh
Remember to chmod +x filename.sh and add it into cron for automated backup.
This post has been edited by KamakaZ: 11 September 2009 - 05:59 AM

Help
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Back to top








