Skip to content

Commit ea637a0

Browse files
committed
v2.4
1 parent e594053 commit ea637a0

File tree

3 files changed

+54
-8
lines changed

3 files changed

+54
-8
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Change Log
22

3+
## 2.4 - (2006-01-23)
4+
- Fixed bug where weekly backups were not being rotated. (fix by wolf02)
5+
- Added hour an min to backup filename for the case where backups are taken multiple times in a day.
6+
NOTE This is not complete support for mutiple executions of the script in a single day.
7+
- Added MAILCONTENT="quiet" option, see docs for details. (requested by snowsam)
8+
- Updated path statment for compatibility with OSX.
9+
- Added "LATEST" to additionally store the last backup to a standard location. (request by Grant29)
10+
311
## 2.3 - (2005-11-07)
412
- Better error handling and notification of errors (a long time coming).
513
- Compression on Backup server to MySQL server communications.

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ You can change the backup storage location from `/backups` to anything you like
4141

4242
The `MAILCONTENT` and `MAILADDR` options and pretty self explanitory, use these to have the backup log mailed to you at any email address or multiple email addresses in a space seperated list.
4343

44-
> **Note:** If you set mail content to "log" you will require access to the "mail" program on your server. If you set this to "files" you will have to have mutt installed on your server. If you set it sto stdout it will log to the screen if run from the console or to the cron job owner if run through cron.
44+
> **Note:** If you set mail content to "log" you will require access to the "mail" program on your server. If you set this to "files" you will have to have mutt installed on your server. If you set it to "stdout" it will log to the screen if run from the console or to the cron job owner if run through cron. If you set it to "quiet". logs will only be mailed if there are errors reported.
4545
4646
### Email Size
4747

@@ -89,6 +89,10 @@ To set the day of the week that you would like the weekly backup to happen set t
8989

9090
`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.
9191

92+
### Latest Backup
93+
94+
`LATEST` is to store an additional copy of the latest backup to a standard location so it can be downloaded by thrid party scripts.
95+
9296
### Pre-Backup and Post-Backup Scripts
9397

9498
Use `PREBACKUP` and `POSTBACKUP` to specify Per and Post backup commands or scripts to perform tasks either before or after the backup process.

automysqlbackup.sh

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
#
33
# MySQL Backup Script
4-
# VER. 2.3 - http://sourceforge.net/projects/automysqlbackup/
4+
# VER. 2.4 - http://sourceforge.net/projects/automysqlbackup/
55
# Copyright (c) 2002-2003 [email protected]
66
#
77
# This program is free software; you can redistribute it and/or modify
@@ -44,6 +44,7 @@ BACKUPDIR="/backups"
4444
# - log : send only log file
4545
# - files : send log file and sql files as attachments (see docs)
4646
# - stdout : will simply output the log to the screen if run manually.
47+
# - quiet : Only send logs if an error occurs to the MAILADDR.
4748
MAILCONTENT="stdout"
4849

4950
# Set the maximum allowed email size in k. (4000 = approx 5MB email [see docs])
@@ -78,6 +79,9 @@ COMP=gzip
7879
# Compress communications between backup server and MySQL server?
7980
COMMCOMP=no
8081

82+
# Additionally keep a copy of the most recent backup in a seperate directory.
83+
LATEST=no
84+
8185
# Command to run before backups (uncomment to use)
8286
#PREBACKUP="/etc/mysql-backup-pre"
8387

@@ -111,8 +115,9 @@ COMMCOMP=no
111115
# email addresses in a space seperated list.
112116
# (If you set mail content to "log" you will require access to the "mail" program
113117
# on your server. If you set this to "files" you will have to have mutt installed
114-
# on your server. If you set it sto stdout it will log to the screen if run from
115-
# the console or to the cron job owner if run through cron)
118+
# on your server. If you set it to "stdout" it will log to the screen if run from
119+
# the console or to the cron job owner if run through cron. If you set it to "quiet"
120+
# logs will only be mailed if there are errors reported. )
116121
#
117122
# MAXATTSIZE sets the largest allowed email attachments total (all backup files) you
118123
# want the script to send. This is the size before it is encoded to be sent as an email
@@ -169,6 +174,9 @@ COMMCOMP=no
169174
# it is useful to save bandwidth when backing up a remote MySQL server over
170175
# the network.
171176
#
177+
# LATEST is to store an additional copy of the latest backup to a standard
178+
# location so it can be downloaded bt thrid party scripts.
179+
#
172180
# Use PREBACKUP and POSTBACKUP to specify Per and Post backup commands
173181
# or scripts to perform tasks either before or after the backup process.
174182
#
@@ -221,6 +229,14 @@ COMMCOMP=no
221229
# Change Log
222230
#=====================================================================
223231
#
232+
# VER 2.4 - (2006-01-23)
233+
# Fixed bug where weekly backups were not being rotated. (Fix by wolf02)
234+
# Added hour an min to backup filename for the case where backups are taken multiple
235+
# times in a day. NOTE This is not complete support for mutiple executions of the script
236+
# in a single day.
237+
# Added MAILCONTENT="quiet" option, see docs for details. (requested by snowsam)
238+
# Updated path statment for compatibility with OSX.
239+
# Added "LATEST" to additionally store the last backup to a standard location. (request by Grant29)
224240
# VER 2.3 - (2005-11-07)
225241
# Better error handling and notification of errors (a long time coming)
226242
# Compression on Backup server to MySQL server communications.
@@ -304,14 +320,14 @@ COMMCOMP=no
304320
#=====================================================================
305321
#=====================================================================
306322
#=====================================================================
307-
PATH=/usr/local/bin:/usr/bin:/bin
308-
DATE=`date +%Y-%m-%d` # Datestamp e.g 2002-09-21
323+
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/mysql/bin
324+
DATE=`date +%Y-%m-%d_%Hh%Mm` # Datestamp e.g 2002-09-21
309325
DOW=`date +%A` # Day of the week e.g. Monday
310326
DNOW=`date +%u` # Day number of the week 1 to 7 where 1 represents Monday
311327
DOM=`date +%d` # Date of the Month e.g. 27
312328
M=`date +%B` # Month e.g January
313329
W=`date +%V` # Week Number e.g 37
314-
VER=2.3 # Version Number
330+
VER=2.4 # Version Number
315331
LOGFILE=$BACKUPDIR/$DBHOST-`date +%N`.log # Logfile Name
316332
LOGERR=$BACKUPDIR/ERRORS_$DBHOST-`date +%N`.log # Logfile Name
317333
BACKUPFILES=""
@@ -344,6 +360,14 @@ if [ ! -e "$BACKUPDIR/monthly" ] # Check Monthly Directory exists.
344360
mkdir -p "$BACKUPDIR/monthly"
345361
fi
346362

363+
if [ "$LATEST" = "yes" ]
364+
then
365+
if [ ! -e "$BACKUPDIR/latest" ] # Check Latest Directory exists.
366+
then
367+
mkdir -p "$BACKUPDIR/latest"
368+
fi
369+
eval rm -fv "$BACKUPDIR/latest/*"
370+
fi
347371

348372
# IO redirection for logging.
349373
touch $LOGFILE
@@ -380,6 +404,9 @@ elif [ "$COMP" = "bzip2" ]; then
380404
else
381405
echo "No compression option set, check advanced settings"
382406
fi
407+
if [ "$LATEST" = "yes" ]; then
408+
cp $1$SUFFIX "$BACKUPDIR/latest/"
409+
fi
383410
return 0
384411
}
385412

@@ -485,7 +512,7 @@ echo ======================================================================
485512
else
486513
REMW=`expr $W - 5`
487514
fi
488-
eval rm -fv "$BACKUPDIR/weekly/$DB/week.$REMW.*"
515+
eval rm -fv "$BACKUPDIR/weekly/$DB_week.$REMW.*"
489516
echo
490517
dbdump "$DB" "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql"
491518
compression "$BACKUPDIR/weekly/$DB/${DB}_week.$W.$DATE.sql"
@@ -602,6 +629,13 @@ then
602629
then
603630
cat "$LOGERR" | mail -s "ERRORS REPORTED: MySQL Backup error Log for $HOST - $DATE" $MAILADDR
604631
fi
632+
elif [ "$MAILCONTENT" = "quiet" ]
633+
then
634+
if [ -s "$LOGERR" ]
635+
then
636+
cat "$LOGERR" | mail -s "ERRORS REPORTED: MySQL Backup error Log for $HOST - $DATE" $MAILADDR
637+
cat "$LOGFILE" | mail -s "MySQL Backup Log for $HOST - $DATE" $MAILADDR
638+
fi
605639
else
606640
if [ -s "$LOGERR" ]
607641
then

0 commit comments

Comments
 (0)