-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_diff.sh
More file actions
33 lines (28 loc) · 1.11 KB
/
db_diff.sh
File metadata and controls
33 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
function db_diff() {
timestamp=`date +%s`
result_path="/tmp/result_$timestamp"
mkdir -p $result_path
dump () {
up=${1%%@*}; user=${up%%:*}; pass=${up##*:}; dbname=${1##*@};
mysqldump --opt --compact --skip-extended-insert -u $user -p$pass $dbname $table > $2
}
cur_dir=$( dirname "${BASH_SOURCE[0]}" )
[ -z "$1" -o -z "$2" ] && echo "Usage: db_diff [user1:pass1@dbname1] [user2:pass2@dbname2] [ignore_table1:ignore_table2...]" && return
# Compare
up=${1%%@*}; user=${up%%:*}; pass=${up##*:}; dbname=${1##*@};
for table in `mysql -u $user -p$pass $dbname -N -e "show tables" --batch`; do
if [ "`echo $3 | grep $table`" = "" ]; then
echo "Comparing '$table'..."
db1file=$(mktemp /tmp/db1.$table.XXXXXX.sql)
db2file=$(mktemp /tmp/db2.$table.XXXXXX.sql)
dump $1 $db1file
dump $2 $db2file
diff -up $db1file $db2file >> $(mktemp $result_path/diff.$table.XXXXXX.diff)
rm -f $db1file $db2file
else
echo "Ignored '$table'..."
fi
done
echo "check results by reading $result_path/diff.* files"
}