[Autobackupmysql-svnmail] SF.net SVN: autobackupmysql:[2] autobackupmysql.sh
Brought to you by:
infyquest
From: <inf...@us...> - 2009-12-09 10:57:01
|
Revision: 2 http://autobackupmysql.svn.sourceforge.net/autobackupmysql/?rev=2&view=rev Author: infyquest Date: 2009-12-09 10:56:50 +0000 (Wed, 09 Dec 2009) Log Message: ----------- Fix Suffix issue Some text changes Add ignore table(s) feature Make bzip2 as default compression Modified Paths: -------------- autobackupmysql.sh Modified: autobackupmysql.sh =================================================================== --- autobackupmysql.sh 2009-12-08 13:48:36 UTC (rev 1) +++ autobackupmysql.sh 2009-12-09 10:56:50 UTC (rev 2) @@ -1,7 +1,7 @@ #!/bin/bash # # Automatic MySQL Backup Script -# VER. 1.0 - http://sourceforge.net/projects/autobackupmysql/ +# VER. 1.1 - http://sourceforge.net/projects/autobackupmysql/ # Copyright (c) 2009 inf...@gm... # Copyright (c) 2002-2006 wip...@ly... # @@ -34,7 +34,7 @@ PASSWORD='password' # Host name (or IP address) of MySQL server e.g localhost -DBHOST=localhost +DBHOST='localhost' # List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3" DBNAMES="DB1 DB2 DB3" @@ -67,6 +67,9 @@ # List of DBNAMES to EXLUCDE if DBNAMES are set to all (must be in " quotes) DBEXCLUDE="" +# List of tables to exclude from the backup (in form db.table) +TABLEEXCLUDE="" + # Include CREATE DATABASE in backup? CREATE_DATABASE=yes @@ -77,8 +80,11 @@ DOWEEKLY=6 # Choose Compression type. (gzip or bzip2) -COMP=gzip +COMP=bzip2 +# Enable inline or piped compression. +PIPECOMP=yes + # Compress communications between backup server and MySQL server? COMMCOMP=no @@ -133,13 +139,13 @@ # so if your mail server will allow a maximum mail size of 5MB I would suggest setting # MAXATTSIZE to be 25% smaller than that so a setting of 4000 would probably be fine. # -# Finally copy automysqlbackup.sh to anywhere on your server and make sure +# Finally copy autobackupmysql.sh to anywhere on your server and make sure # to set executable permission. You can also copy the script to # /etc/cron.daily to have it execute automatically every night or simply # place a symlink in /etc/cron.daily to the file if you wish to keep it # somwhere else. # NOTE:On Debian copy the file with no extention for it to be run -# by cron e.g just name the file "automysqlbackup" +# by cron e.g just name the file "autobackupmysql" # # Thats it.. # @@ -175,10 +181,13 @@ # set the DOWEEKLY setting, this can be a value from 1 to 7 where 1 is Monday, # The default is 6 which means that weekly backups are done on a Saturday. # -# COMP is used to choose the copmression used, options are gzip or bzip2. +# COMP is used to choose the compression used, options are gzip or bzip2. # bzip2 will produce slightly smaller files but is more processor intensive so # may take longer to complete. # +# PIPECOMP is used to make the compression inline. This may reduce the time +# taken for completion. +# # COMMCOMP is used to enable or diable mysql client to server compression, so # it is useful to save bandwidth when backing up a remote MySQL server over # the network. @@ -245,6 +254,11 @@ # Change Log #===================================================================== # +# VER 1.1 - (2009-12-10) +# Fix for missing suffix +# Some text changes +# Add ignore table(s) feature +# Make bzip2 as default compression # VER 1.0 - (2009-12-09) # Initial Revamped Release # @@ -264,7 +278,7 @@ DOM=`date +%d` # Date of the Month e.g. 27 M=`date +%B` # Month e.g January W=`date +%V` # Week Number e.g 37 -VER=1.0 # Version Number +VER=1.1 # Version Number LOGFILE=$BACKUPDIR/$DBHOST-`date +%N`.log # Logfile Name LOGERR=$BACKUPDIR/ERRORS_$DBHOST-`date +%N`.log # Logfile Name BACKUPFILES="" @@ -282,6 +296,17 @@ 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" +else + SUFFIX="" +fi + # Create required directories if [ ! -e "$BACKUPDIR" ] # Check Backup Directory exists. then @@ -327,28 +352,33 @@ # Database dump function dbdump () { -mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT $1 > $2 +if [ "$PIPECOMP" = "yes" ]; then + mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT $1 | $COMP > "$2$SUFFIX" +else + mysqldump --user=$USERNAME --password=$PASSWORD --host=$DBHOST $OPT $1 > $2 +fi return 0 } # Compression function plus latest copy -SUFFIX="" compression () { if [ "$COMP" = "gzip" ]; then - gzip -f "$1" - echo - echo Backup Information for "$1" - gzip -l "$1.gz" - SUFFIX=".gz" + if [ "$PIPECOMP" = "no" ]; then + gzip -f "$1" + echo + echo Backup Information for "$1" + gzip -l "$1.gz" + fi elif [ "$COMP" = "bzip2" ]; then - echo Compression information for "$1.bz2" - bzip2 -f -v $1 2>&1 - SUFFIX=".bz2" + if [ "$PIPECOMP" = "no" ]; then + echo Compression information for "$1.bz2" + bzip2 -f -v $1 2>&1 + fi else echo "No compression option set, check advanced settings" fi if [ "$LATEST" = "yes" ]; then - cp $1$SUFFIX "$BACKUPDIR/latest/" + cp "$1$SUFFIX" "$BACKUPDIR/latest/" fi return 0 } @@ -366,7 +396,14 @@ echo fi +# Add --ignore-table options to $OPT +if [ -n "$TABLEEXCLUDE" ]; then + for table in $TABLEEXCLUDE ; do + OPT="${OPT} --ignore-table=${table}" + done +fi + if [ "$SEPDIR" = "yes" ]; then # Check if CREATE DATABSE should be included in Dump if [ "$CREATE_DATABASE" = "no" ]; then OPT="$OPT --no-create-db" @@ -401,7 +438,7 @@ fi echo ====================================================================== -echo AutoBackupMySQL VER $VER +echo AutoBackupMySQL Version $VER echo http://sourceforge.net/projects/autobackupmysql/ echo echo Backup of Database Server - $HOST @@ -532,8 +569,8 @@ echo `du -hs "$BACKUPDIR"` echo echo ====================================================================== -echo If you find AutoMySQLBackup valuable please make a donation at -echo http://sourceforge.net/project/project_donations.php?group_id=101066 +#echo If you find AutoBackupMySQL valuable please make a donation at +#echo http://sourceforge.net/project/project_donations.php?group_id=101066 echo ====================================================================== # Run command when we're done @@ -588,7 +625,7 @@ cat "$LOGFILE" echo echo "###### WARNING ######" - echo "Errors reported during AutoMySQLBackup execution.. Backup failed" + echo "Errors reported during AutoBackupMySQL execution.. Backup failed" echo "Error log below.." cat "$LOGERR" else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |