summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2006-03-16 10:28:44 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2006-03-16 10:28:44 +0000
commit22b5aa5e1d12ed55d58013c93c36b2e1ea8ee1b0 (patch)
tree0649ca58a84b3d790e4a31ed75c68ac5bdc857fe
parentc53219a01df0af71b1e4e3de3b811d34433db60f (diff)
Support multiple hosts in backup-mysql
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@62 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
-rwxr-xr-xbackup-mysql67
1 files changed, 51 insertions, 16 deletions
diff --git a/backup-mysql b/backup-mysql
index b964833..f6c8b99 100755
--- a/backup-mysql
+++ b/backup-mysql
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#
# Copyright (c) 2002, 2003, 2004, 2005 Peter Palfrader <peter@palfrader.org>
@@ -21,21 +21,56 @@ else
exit 1
fi
-echo 'SHOW DATABASES;' | mysql | tail -n +2 |
-while read db; do
- if [ "$db" = "innodb" -o "$db" = "test" ] ; then
- continue;
- fi
-
- file="$TARGET/$DATE-$db"
- mysqldump --opt --lock-tables -- "$db" > "$file"
- bzip2 -- "$file"
+HOSTS="$@"
+if [ -z "$HOSTS" ]; then
+ HOSTS="localhost"
+fi
- md5=`md5sum -- "$file.bz2" | awk '{print $1}'`
- if [ -e "$TARGET/MD5-$md5" ]; then
- rm -- "$file.bz2"
- ln "$TARGET/MD5-$md5" "$file.bz2"
+for host in $HOSTS; do
+ if [ "$host" = "localhost" ]; then
+ prefix="";
+ postfix="";
else
- ln "$file.bz2" "$TARGET/MD5-$md5"
+ shorthost=`echo "$host" | sed -e 's/\..*//'`
+ echo $shorthost
+ prefix="$shorthost--";
+ postfix="--$shorthost";
fi
-done | egrep -v 'Database ".*" dropped'
+ mysqlcnf="$HOME/.my.cnf$postfix"
+ if ! [ -e "$mysqlcnf" ]; then
+ echo "Cannot find my.cnf for host $host: $mysqlcnf" >&2
+ exit 1
+ fi
+
+ DBs=$(
+ echo 'SHOW DATABASES;' | mysql --defaults-file="$mysqlcnf" --host="$host" | tail -n +2 |
+ while read db; do
+ if [ "$db" = "innodb" -o "$db" = "test" ] ; then
+ continue;
+ fi
+ echo $db;
+ done
+ );
+
+ for db in $DBs; do
+ file="$TARGET/$DATE-$prefix$db"
+ mysqldump --defaults-file="$mysqlcnf" --host="$host" --opt --lock-tables -- "$db" > "$file"
+ done
+
+ for db in $DBs; do
+ file="$TARGET/$DATE-$prefix$db"
+ echo $file
+ done | xargs --no-run-if-empty --max-procs 4 -n 1 bzip2
+
+ for db in $DBs; do
+ file="$TARGET/$DATE-$prefix$db"
+
+ md5=`md5sum -- "$file.bz2" | awk '{print $1}'`
+ if [ -e "$TARGET/MD5-$md5" ]; then
+ rm -- "$file.bz2"
+ ln "$TARGET/MD5-$md5" "$file.bz2"
+ else
+ ln "$file.bz2" "$TARGET/MD5-$md5"
+ fi
+ done
+done