coolcommands.com - the search engine for unix sysadmins :: unix commands and scripts
Saturday July 31, 2010


 Home
 Search
 Advanced Search
 Category Search
 Affiliates
 Acknowledgements
 Cool Links

Username

Password

Remember me
Forgot your password?
Create an account

Who's Online
We have 18 guests online

Newest Member

solten

Hit Counter
4558371 Visitors

cool Statistics
coolcommands:1313
Categories:82
Total queries:520244
Members:4224





Advanced Search coolcommands.com
Search Keyword:   Help
Exact match Match any (part of) word Full text search


coolcommand

mysqldumpsh - script to backup MySQL databases with backup rotation
Description

Here is a small script which does a mysqldump of your databases:

#!/bin/sh

# Customizable parameters
DATABASES="db1 db2"
MYSQLDUMPDIR=/mysqldumps
MYSQLDUMPFILE=mysqldump_`/usr/bin/date "+%Y%m%d"`.sql

if [[ ! -d $MYSQLDUMPDIR ]];
then
mkdir -p $MYSQLDUMPDIR
fi

# Verify we don't have more than 50 backups
DUMPCOUNT=`ls $MYSQLDUMPDIR/*|wc -l|sed -e 's/ //g'`
if [[ $DUMPCOUNT -gt 50 ]];
then
HEADCOUNT=`expr $DUMPCOUNT - 50`
DELETEFILES=`ls -tr $MYSQLDUMPDIR/* | head -$HEADCOUNT`
rm -f $DELETEFILES
fi

/usr/bin/mysqldump --quote-names --opt -u root --password=badpass --databases \
$DATABASES > $MYSQLDUMPDIR/$MYSQLDUMPFILE

Notes:

1) You do not have to worry about your password being shown when you do a ps -ef during a mysqldump. mysqldump is intelligent enough to hide the password. Here is an example of ps -ef command during the dump:

/usr/bin/mysqldump --quote-names --opt -u root --password=x --databases db1 db2

2) Since you have hardcoded the mysql password in this script, make sure the permission are 700 for the owner of the script:

# chown root mysqldump.sh

# chmod 700 mysqldump.sh

3) To restore the databases:

# mysql -u root -p < mysqldump.sql

4) Using this command, you will restore all databases. So, if you want the capability to restore just one db at a time, run the script multiple times setting the variable for $DATABASES to just a single database.

5) If you don't want 50 backups, just modify the value.

6) Run through cron as often as required (hourly, daily, weekly, etc).
Example

mysqldump.sh

Return to search results

Random coolcommands

coolcommand: how to see all the IP addresses used by the HMC private network for communication to IBM frames
Example: ssysconn -r all -F type_model_serial_num,ipaddr
[show me the details]
coolcommand: how to login to a Sybase database
Example: isql -U sa password
[show me the details]
coolcommand: TZ - how to determine your timezone variable
Example: echo $TZ
[show me the details]
coolcommand: how to test if a file exists and is a symbolic link in a korn shell script
Example: test -L file; [ -L file ]
[show me the details]

coolcommands.com - the search engine for UNIX sysadmins :: unix commands and scripts



FREE
myPMS

Password
Management
System

by

LVOware.com




Top 5 Submitters

lvo1138
audet37
kah00na32
Mariom24
lebjf00013

Top 5 Searches

Category Solaris42397
Category AIX37570
Category General UNIX33788
solaris20551
aix19172

Terms of Use
Privacy
Contact


 
coolcommands.com © 2010. All Right Reserved.
Programming by PRATTICO Consulting . Hosting by Apricusum