#!/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


Back to top








