The FreeBSD Diary

The FreeBSD Diary (TM)

Providing practical examples since 1998

If you buy from Amazon USA, please support us by using this link.
[ HOME | TOPICS | INDEX | WEB RESOURCES | BOOKS | CONTRIBUTE | SEARCH | FEEDBACK | FAQ | FORUMS ]
 New Topic  |  Go to Top  |  Go to Topic  |  Search  |  Log In   Newer Topic  |  Older Topic 
 My script
Author: inZet 
Date:   17-11-09 16:13

I prefer to use a scripted approach.



#!/bin/sh

#
# mysql database backup
# author: Gianluca Sordiglioni
# date: 2002.12.31
#
# Dump all the databases using mysqldump.
#
# put login password in ~/.my.cnf:
#
# [client]
# user=root
# password=yourpassword
#
# Be sure to have enought space left in $BKTEMP and $BKPATH dirs !
#


BKPREF="mysql_backup_`hostname -s`"
BKNAME="$BKPREF.`date +%Y.%m.%d.at.%H.%M.%S`" # how to name your files
BKPATH="/usr/backup" # backup directory
BKFULL=$BKPATH/$BKNAME # backup full pathname
BKTEMP="/usr/tmp" # temporary directory
BKMAX=8 # number of backup files (days?) to keep
BKTOT=`ls $BKPATH/$BKPREF* | wc -l`
BKDEL=`expr $BKTOT - $BKMAX`

# Loop thru all databases and dump them.
echo "Begin MySQL backup at `date`"

mkdir $BKFULL

for db in $(/usr/local/bin/mysqlshow | cut -f2 -d"|" | cut -f2 | tail +4 | tail -r | tail +2)
do
if [ $db != '..' ] && [ $db != '.' ]; then
echo $db
/usr/local/bin/mysqldump -c --add-drop-table --add-drop-database $db | gzip -9 > $BKFULL/$db.gz
fi
done

# (Copy it offsite, if needed)

# Remove the old backup files we created
#
if [ $BKTOT -gt $BKMAX ]
then
for file in $(ls -rt $BKPATH/$BKPREF* | head -n $BKDEL)
do
rm -rf $file
done
fi

echo "End MySQL backup at `date`"

Reply To This Message
 
 Re: My script
Author: Dan 
Date:   18-11-09 03:36

Thank you for posting that.

--
Webmaster

Reply To This Message
 Forum List  |  Threaded View   Newer Topic  |  Older Topic 


 Forum List  |  Need a Login? Register Here 
 User Login
 User Name:
 Password:
 Remember my login:
   
 Forgot Your Password?
Enter your email address or user name below and a new password will be sent to the email address associated with your profile.
How to get the most out of the forum

phorum.org