Skip to content

Instantly share code, notes, and snippets.

@lukesUbuntu
Last active July 27, 2017 07:04
Show Gist options
  • Save lukesUbuntu/8e0d1ada7338a0b2ad5f1e01624087b2 to your computer and use it in GitHub Desktop.
Save lukesUbuntu/8e0d1ada7338a0b2ad5f1e01624087b2 to your computer and use it in GitHub Desktop.
#!/bin/sh
echo "Usage: dbdiff [user1:pass1@dbname1] [user2:pass2@dbname2] [ignore_table1:ignore_table2...]"
dump () {
up=${1%%@*}; user=${up%%:*}; pass=${up##*:}; dbname=${1##*@};
mysqldump --opt --compact --skip-extended-insert -u $user -p$pass $dbname $table > $2
}
rm -f /tmp/db.diff
# 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'..."
dump $1 /tmp/file1.sql
dump $2 /tmp/file2.sql
diff -up /tmp/file1.sql /tmp/file2.sql >> /tmp/db.diff
else
echo "Ignored '$table'..."
fi
done
less /tmp/db.diff
rm -f /tmp/file1.sql /tmp/file2.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment