|
| cool Statistics |
| | coolcommands: | 1313 | | Categories: | 82 | | Total queries: | 520244 | | Members: | 4224 | |
|
|
|
 |
|
|
Advanced Search coolcommands.com
 |
Submitted by:
lvo   |
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
|  |  |  |  |
|
|
|
|
 |
|
|
|
Top 5 Submitters
|
|---|
| lvo | 1138 |
| audet | 37 |
| kah00na | 32 |
| Mariom | 24 |
| lebjf000 | 13 |
Top 5 Searches
|
| Category Solaris | 42397 |
| Category AIX | 37570 |
| Category General UNIX | 33788 |
| solaris | 20551 |
| aix | 19172 |
|
|
|
|