Project

General

Profile

MySQLMaintenanceScripts » mysqldump-dbfilter.sh

Andreas Kohlbecker, 02/12/2010 12:11 PM

 
1
#!/bin/sh
2
BACKUPDIR="/backups/db";
3
DBFILTER="(information_schema|dev|tmp)";
4
MYSQLDUMP="$(which mysqldump) --opt";
5
DIRNAME=`date +%Y-%m`;
6
 
7
MYSQL=$(which mysql);
8
TAR=$(which tar);
9
GZIP=$(which gzip);
10
NICE=$(which nice);
11
EGREP=$(which egrep);
12
 
13
mkdir -p "$BACKUPDIR/$DIRNAME";
14
 
15
DBS=$($MYSQL -Bse "show databases");
16
for db in $DBS
17
do
18
    if !(echo $db | $EGREP $DBFILTER > /dev/null);
19
    then
20
        FILENAME="$db-`date +%Y_%m_%d_%H_%M_%S`.sql.gz";
21
$NICE -n 20 $MYSQLDUMP $db | $NICE -n 20 $GZIP -c > "$BACKUPDIR/$DIRNAME/$FILENAME";
22
    fi
23
done
(1-1/3)