Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
[Bug 699530] Add script to anonymize db and copy to stage and dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheeri authored and Sancus committed Nov 26, 2013
1 parent 657075a commit b158ffb
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
51 changes: 51 additions & 0 deletions scripts/mozillians-anonymize.sh
@@ -0,0 +1,51 @@
#!/bin/sh

INSTANCE=generic
DB=mozillians_org
DEVDB=sanitize_dev_$DB
STAGEDB=sanitize_stage_$DB
cd /data/backups/bin/
rm -f anonymize.py anonymize_dev.yml anonymize_stage.yml
/usr/bin/wget -q -nH https://raw.github.com/mozilla/mozillians/master/scripts/mysql-anonymize/anonymize.py
/bin/chmod 755 anonymize.py
/usr/bin/wget -q -nH https://raw.github.com/mozilla/mozillians/master/scripts/mysql-anonymize/anonymize_dev.yml
/usr/bin/wget -q -nH https://raw.github.com/mozilla/mozillians/master/scripts/mysql-anonymize/anonymize_stage.yml

TODAY=`/bin/date +"%Y.%m.%d"`
HOSTNAME=`/bin/hostname`
SQLPATH=/data-2/$HOSTNAME/backups/$INSTANCE/sqlcopies/$DB
SQLFILE=$SQLPATH/$DB.$TODAY.sql
PASS=`/bin/grep ^password /data/$INSTANCE/$INSTANCE.cnf | /bin/cut -f2 -d= | /usr/bin/uniq`
if [ $PASS == ""]
then
P=""
else
P="-p$PASS"
fi

MYSQL="/usr/bin/mysql --defaults-file=/data/$INSTANCE/$INSTANCE.cnf -S /var/lib/mysql/$INSTANCE.sock"

# import db
$MYSQL -e "drop database if exists $DEVDB"
$MYSQL -e "create database if not exists $DEVDB"
$MYSQL $DEVDB < $SQLFILE

$MYSQL -e "drop database if exists $STAGEDB"
$MYSQL -e "create database if not exists $STAGEDB"
$MYSQL $STAGEDB < $SQLFILE

# sanitize dbs
/usr/bin/python anonymize.py anonymize_dev.yml > $SQLPATH/$DB.$TODAY.queries_sanitize_dev.sql
$MYSQL $DEVDB < $SQLPATH/$DB.$TODAY.queries_sanitize_dev.sql

/usr/bin/python anonymize.py anonymize_stage.yml > $SQLPATH/$DB.$TODAY.queries_sanitize_stage.sql
$MYSQL $STAGEDB < $SQLPATH/$DB.$TODAY.queries_sanitize_stage.sql

# export dbs
/usr/bin/mysqldump $DEVDB -u root $P -S /var/lib/mysql/$INSTANCE.sock > $SQLPATH/$DB.$TODAY.sanitized_dev.sql
/usr/bin/mysqldump $STAGEDB -u root $P -S /var/lib/mysql/$INSTANCE.sock > $SQLPATH/$DB.$TODAY.sanitized_stage.sql

# copy dbs
/usr/bin/scp -q $SQLPATH/$DB.$TODAY.sanitized_dev.sql $SQLPATH/$DB.$TODAY.sanitized_stage.sql dev1.db.phx1.mozilla.com:/data/backup-drop/$INSTANCE/$DB

# Done!
2 changes: 1 addition & 1 deletion scripts/mysql-anonymize/anonymize_dev.yml
@@ -1,5 +1,5 @@
databases:
mozillians:
sanitize_dev_mozillians_org:

tables:
auth_user:
Expand Down
2 changes: 1 addition & 1 deletion scripts/mysql-anonymize/anonymize_stage.yml
@@ -1,5 +1,5 @@
databases:
mozillians:
sanitize_stage_mozillians_org:

tables:
auth_user:
Expand Down

0 comments on commit b158ffb

Please sign in to comment.