Skip to content

Instantly share code, notes, and snippets.

@namenu
Last active August 29, 2015 13:58
Show Gist options
  • Save namenu/9950090 to your computer and use it in GitHub Desktop.
Save namenu/9950090 to your computer and use it in GitHub Desktop.
Commit DB scheme daily
#!/bin/bash
REPO=
BRANCH=Release
DB=bom_$(date +%Y%m%d)
set -x
cd /htdocs/dev/repo/release
hg pull $REPO && hg up $BRANCH -C
mysqldump --single-transaction --no-create-db --no-create-info --no-data --skip-triggers --routines -u -p -hlocalhost $DB > docs/db/procedure.sql
hg ci -u db-agent -m "[db] procedure - $(date +%Y-%m-%d)"
hg push -r $BRANCH $REPO
#!/bin/bash
REPO=
BRANCH=Release
DB=bom_$(date +%Y%m%d)
hg pull $REPO && hg up $BRANCH -C
mysqldump --no-data --compact -u -p -hlocalhost $DB | sed 's/ AUTO_INCREMENT=[0-9]*\b//' > docs/db/db.sql
hg ci -u db-agent -m "[db] schema - $(date +%Y-%m-%d)"
hg push -r $BRANCH $REPO
#!/bin/bash
REPO=
DB=
USER=
PASSWORD=
HOST=
SRC_DIR=
DST_DIR=
set -x
cd $SRC_DIR
git pull
for T in `mysql -u$USER -p$PASSWORD -h$HOST --skip-column-names --batch -e "show tables from $DB"`; do
if [[ $T =~ ^(__deprecated|tmp) ]]; then
continue
fi
mysqldump --skip-comments --compact --no-data -u$USER -p$PASSWORD -h$HOST $DB $T | sed 's/ AUTO_INCREMENT=[0-9]*\b//' > $DST_DIR/$DB/$T.sql
done
git add $DST_DIR/$DB
git commit --author="db-agent" -m "[db] tables - $(date +%Y-%m-%d)"
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment