View Single Post
Old 08-15-2003, 04:06 PM   #36
Steve_S
I am a Contributing Geek. Are You?
 
Steve_S's Avatar
 
Join Date: Aug 1998
Location: Las Vegas, Nevada, USA
Posts: 5,224
Default

funny, I was thinking the same thing last night but since my middle name is "redundancy" I had a good nights sleep.

Compliments of the vB GODS and a valuable solution for backups via crontab. Edit to suite your mood and good for any MySQL db.

----Begin:

#!/bin/sh

echo<<header "
################################################## ###
# ---> ATTENTION funky duck ONLY <--- #
# #
# ---> HAVE YOU DOWNLOADED YOUR BACKUPS? PLEASE! #
# #
# Makes multiple backups of my vB mysql data #
# Makes up to 7 backups and then starts over #
# test and run from root as----> sh filename #
# Archives are located in /bath/to/archives #
################################################## ###
"
header

# List all of the MySQL databases that you want to backup in here,
# each seperated by a space
databases="mydbname"

# Directory where you want the backup files to be placed
backupdir=/path/to/store/backups

# Directory where you want an extra backup placed at a specified interval
extra_backupdir=/path/to/store/backups

# MySQL dump command, use the full path name here
mysqldumpcmd=/usr/bin/mysqldump

# MySQL Username and password
userpassword="-uname -pyourpassword"

# MySQL dump options
dumpoptions=""

# Unix Commands
gzip="/bin/gzip -f"
uuencode="/usr/bin/uuencode"
mail="/usr/sbin"

# Maximum number of backups to keep around
max_backups=7

# Backup number at which an extra backup should be made (set to
# zero if you don't want extra backups)
extra_backup=0

# Send Incremental Backup? Would you like the more frequent backup emailed to you?
# Set to "y" if you do or n
sendincbackup="n"

# Send Extra Backup? Would you like the extra backup emailed to you?
# Set to "y" if you do
sendextrabackup="n"

subject="vB_Database"
mailto="webmaster@yourdomain.com"

################################################## ##############

DAY=$(/bin/date '+%Y.%m.%d-%H%M')

for database in $databases
do
sequence_file="${backupdir**/${database**.seq"
if [ -e "$sequence_file" ]
then
read backup_count < $sequence_file
else
echo 1 >> $sequence_file
backup_count=1
fi

# Dump out the database
echo "Working on ${database** database:"
echo -n "-> Dumping database............... "
$mysqldumpcmd $userpassword $dumpoptions $database >${backupdir**/${database**.sql.backup${backup_count**
echo "done."

# Compress all of our backup files
echo -n "-> Compressing database dump...... "
$gzip ${backupdir**/${database**.sql.backup${backup_count**
echo "done."

# Make the additional backup
if [ "$backup_count" = "$extra_backup" ];
then
echo -n "-> Creating additional backup..... "
cp ${backupdir**/${database**.sql.backup${backup_count**.gz ${extra_backupdir**/${database**.sql.$DAY.gz
echo "done."
if [ $sendincbackup = "y" ];
then
echo -n "-> E-mailing additional backup.... "
#$uuencode ${extra_backupdir**/${database**.sql.$DAY.gz ${database**.sql.$DAY.gz > ${extra_backupdir**/${database**.sql.$DAY.gz.uu
#$mail -s "$subject : ${database**.sql.$DAY.gz" $mailto < ${extra_backupdir**/${database**.sql.$DAY.gz.uu
#rm ${extra_backupdir**/${database**.sql.$DAY.gz.uu
echo "done."
fi
fi

# Send the incremental backups via email
if [ $sendincbackup = "y" ];
then
echo -n "-> E-mailing incremental backup... "
# $uuencode ${backupdir**/${database**.sql.backup${backup_count**.gz ${database**.sql.backup${backup_count**.gz > ${backupdir**/${database**.sql.backup${backup_count**.gz.uu
# $mail -s "$subject : ${database**.sql.backup${backup_count**.gz" $mailto < ${backupdir**/${database**.sql.backup${backup_count**.gz.uu
# rm ${backupdir**/${database**.sql.backup${backup_count**.gz.uu
echo "done."
fi

backup_count=`expr $backup_count + 1`
if [ "$backup_count" -gt "$max_backups" ];
then
backup_count=1
fi
echo $backup_count>$sequence_file
echo "Finished with ${database** database! --> funky duck, don't forget to download your archives. PLEASE!"
echo ""

done


----------------------end

Last edited by Steve_S; 08-15-2003 at 04:09 PM.
Steve_S is offline