[Autobackupmysql-svnmail] SF.net SVN: autobackupmysql:[6] autobackupmysql.sh
Brought to you by:
infyquest
From: <inf...@us...> - 2010-11-17 22:15:48
|
Revision: 6 http://autobackupmysql.svn.sourceforge.net/autobackupmysql/?rev=6&view=rev Author: infyquest Date: 2010-11-17 22:15:41 +0000 (Wed, 17 Nov 2010) Log Message: ----------- Add mysql server port support Modified Paths: -------------- autobackupmysql.sh Modified: autobackupmysql.sh =================================================================== --- autobackupmysql.sh 2009-12-22 11:39:58 UTC (rev 5) +++ autobackupmysql.sh 2010-11-17 22:15:41 UTC (rev 6) @@ -1,7 +1,7 @@ #!/bin/bash # # Automatic MySQL Backup Script -# VER. 1.3 - http://sourceforge.net/projects/autobackupmysql/ +# VER. 1.4 - http://sourceforge.net/projects/autobackupmysql/ # Copyright (c) 2009 inf...@gm... # Copyright (c) 2002-2006 wip...@ly... # @@ -27,7 +27,7 @@ # (Detailed instructions below variables) #===================================================================== -# Check configuration files +# Check configuration iles if [ -f "autobackupmysql.conf" ] ; then source "autobackupmysql.conf" elif [ -f "/etc/autobackupmysql.conf" ] ; then @@ -44,6 +44,9 @@ # Host name (or IP address) of MySQL server e.g localhost DBHOST='localhost' +# Port on which the MySQL server is reachable e.g. 5710 +PORT=5710 + # List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3" DBNAMES="DB1 DB2 DB3" @@ -52,10 +55,10 @@ # Mail setup # What would you like to be mailed to you? -# - log : send only log file -# - files : send log file and sql files as attachments (see docs) +# - log : send only log file +# - files : send log file and sql files as attachments (see docs) # - stdout : will simply output the log to the screen if run manually. -# - quiet : Only send logs if an error occurs to the MAILADDR. +# - quiet : Only send logs if an error occurs to the MAILADDR. MAILCONTENT="stdout" # Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs]) @@ -232,7 +235,7 @@ # Please Note!! #===================================================================== # -# I take no resposibility for any data loss or corruption when using +# I take no responsibility for any data loss or corruption when using # this script.. # This script will not help in the event of a hard drive crash. If a # copy of the backup has not be stored offline or on another PC.. @@ -263,9 +266,11 @@ # Change Log #===================================================================== # +# VER 1.4 - (2010-11-17) +# Add mysql server port support (based on patch by Eike Starkman) # VER 1.3 - (2009-12-22) -# Add FreeBSD specific configuration check (thanks fraenski) -# Fix typo in the configuration file check (thanks fraenski) +# Add FreeBSD specific configuration check (patch by Frank Wall) +# Fix typo in the configuration file check (patch by Frank Wall) # Fix for Socket file ignored when DBNAMES="all" given # Minor IO redirection fix # VER 1.2 - (2009-12-18) @@ -301,26 +306,22 @@ OPT="--quote-names --opt" # OPT string for use with mysqldump ( see man mysqldump ) # Add --compress mysqldump option to $OPT -if [ "$COMMCOMP" = "yes" ]; - then - OPT="$OPT --compress" - fi +if [ "$COMMCOMP" = "yes" ]; then + OPT="$OPT --compress" +fi # Add --compress mysqldump option to $OPT -if [ "$MAX_ALLOWED_PACKET" ]; - then - OPT="$OPT --max_allowed_packet=$MAX_ALLOWED_PACKET" - fi +if [ "$MAX_ALLOWED_PACKET" ]; then + OPT="$OPT --max_allowed_packet=$MAX_ALLOWED_PACKET" +fi # Set the suffix for compressed file -if [ "$COMP" = "gzip" ]; - then - SUFFIX=".gz" -elif [ "$COMP" = "bzip2" ]; - then - SUFFIX=".bz2" +if [ "$COMP" = "gzip" ]; then + SUFFIX=".gz" +elif [ "$COMP" = "bzip2" ]; then + SUFFIX=".bz2" else - SUFFIX="" + SUFFIX="" fi # Create required directories @@ -345,12 +346,12 @@ fi if [ "$LATEST" = "yes" ] -then - if [ ! -e "$BACKUPDIR/latest" ] # Check Latest Directory exists. then + if [ ! -e "$BACKUPDIR/latest" ] # Check Latest Directory exists. + then mkdir -p "$BACKUPDIR/latest" fi -eval rm -fv "$BACKUPDIR/latest/*" + eval rm -fv "$BACKUPDIR/latest/*" fi # IO redirection for logging. @@ -369,9 +370,9 @@ # Database dump function dbdump () { if [ "$PIPECOMP" = "yes" ]; then - mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT $1 | $COMP > "$2$SUFFIX" + mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST --port=$PORT $OPT $1 | $COMP > "$2$SUFFIX" else - mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT $1 > $2 + mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST --port=$PORT $OPT $1 > $2 fi return 0 } @@ -443,9 +444,9 @@ # If backing up all DBs on the server if [ "$DBNAMES" = "all" ]; then if [ "$SOCKET" ]; then - DBNAMES="`mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST --socket=$SOCKET --batch --skip-column-names -e "show databases"| sed 's/ /%/g'`" + DBNAMES="`mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST --port=$PORT --socket=$SOCKET --batch --skip-column-names -e "show databases"| sed 's/ /%/g'`" else - DBNAMES="`mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST --batch --skip-column-names -e "show databases"| sed 's/ /%/g'`" + DBNAMES="`mysql --user=$USERNAME --password=$PASSWORD --host=$DBHOST --port=$PORT --batch --skip-column-names -e "show databases"| sed 's/ /%/g'`" fi # If DBs are excluded for exclude in $DBEXCLUDE @@ -476,7 +477,7 @@ MDB="`echo $MDB | sed 's/%/ /g'`" if [ ! -e "$BACKUPDIR/monthly/$MDB" ] # Check Monthly DB Directory exists. - then + then mkdir -p "$BACKUPDIR/monthly/$MDB" fi echo Monthly Backup of $MDB... @@ -593,8 +594,7 @@ echo ====================================================================== # Run command when we're done -if [ "$POSTBACKUP" ] - then +if [ "$POSTBACKUP" ]; then echo ====================================================================== echo "Postbackup command output." echo @@ -607,56 +607,47 @@ exec 1>&6 6>&- # Restore stdout and close file descriptor #6. exec 2>&7 7>&- # Restore stderr and close file descriptor #7. -if [ "$MAILCONTENT" = "files" ] -then - if [ -s "$LOGERR" ] - then +if [ "$MAILCONTENT" = "files" ]; then + if [ -s "$LOGERR" ]; then # Include error log if is larger than zero. BACKUPFILES="$BACKUPFILES $LOGERR" ERRORNOTE="WARNING: Error Reported - " fi #Get backup size ATTSIZE=`du -c $BACKUPFILES | grep "[[:digit:][:space:]]total$" |sed s/\s*total//` - if [ $MAXATTSIZE -ge $ATTSIZE ] - then + if [ $MAXATTSIZE -ge $ATTSIZE ]; then BACKUPFILES=`echo "$BACKUPFILES" | sed -e "s# # -a #g"` #enable multiple attachments mutt -s "$ERRORNOTE MySQL Backup Log and SQL Files for $HOST - $DATE" $BACKUPFILES $MAILADDR < $LOGFILE #send via mutt else cat "$LOGFILE" | mail -s "WARNING! - MySQL Backup exceeds set maximum attachment size on $HOST - $DATE" $MAILADDR fi -elif [ "$MAILCONTENT" = "log" ] -then +elif [ "$MAILCONTENT" = "log" ]; then cat "$LOGFILE" | mail -s "MySQL Backup Log for $HOST - $DATE" $MAILADDR - if [ -s "$LOGERR" ] - then - cat "$LOGERR" | mail -s "ERRORS REPORTED: MySQL Backup error Log for $HOST - $DATE" $MAILADDR + if [ -s "$LOGERR" ]; then + cat "$LOGERR" | mail -s "ERRORS REPORTED: MySQL Backup error Log for $HOST - $DATE" $MAILADDR fi -elif [ "$MAILCONTENT" = "quiet" ] -then - if [ -s "$LOGERR" ] - then - cat "$LOGERR" | mail -s "ERRORS REPORTED: MySQL Backup error Log for $HOST - $DATE" $MAILADDR - cat "$LOGFILE" | mail -s "MySQL Backup Log for $HOST - $DATE" $MAILADDR +elif [ "$MAILCONTENT" = "quiet" ]; then + if [ -s "$LOGERR" ]; then + cat "$LOGERR" | mail -s "ERRORS REPORTED: MySQL Backup error Log for $HOST - $DATE" $MAILADDR + cat "$LOGFILE" | mail -s "MySQL Backup Log for $HOST - $DATE" $MAILADDR fi else - if [ -s "$LOGERR" ] - then - cat "$LOGFILE" - echo - echo "###### WARNING ######" - echo "Errors reported during AutoBackupMySQL execution.. Backup failed" - echo "Error log below.." - cat "$LOGERR" + if [ -s "$LOGERR" ]; then + cat "$LOGFILE" + echo + echo "###### WARNING ######" + echo "Errors reported during AutoBackupMySQL execution.. Backup failed" + echo "Error log below.." + cat "$LOGERR" else cat "$LOGFILE" fi fi -if [ -s "$LOGERR" ] - then - STATUS=1 - else - STATUS=0 +if [ -s "$LOGERR" ]; then + STATUS=1 +else + STATUS=0 fi # Clean up Logfile This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |