-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmask.sh
More file actions
executable file
·29 lines (25 loc) · 992 Bytes
/
mask.sh
File metadata and controls
executable file
·29 lines (25 loc) · 992 Bytes
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
#!/bin/sh
set -eu
export MASK_DB=_mask
export MASK_HOST=db
export MASK_USER=root
export MASK_PASSWORD=password
export MASK_PORT=3306
echo $PRODUCTION_GS_UTIL_KEY_FILE > gs.key
gcloud auth activate-service-account --key-file=gs.key
gsutil cp $PRODUCTION_DUMP_OBJECT_URL .
echo $BACKUP_GS_UTIL_KEY_FILE > gs.key
gcloud auth activate-service-account --key-file=gs.key
mysql -u$MASK_USER -h$MASK_HOST -p$MASK_PASSWORD -e "CREATE DATABASE $MASK_DB" || true
mysql -u$MASK_USER -h$MASK_HOST -p$MASK_PASSWORD $MASK_DB < mysql.dump
rm -f mysql.dump
curl $MASK_SETTING_YAML_URL > db_mask_sensitive_data.yml
MASK_LINES=$(wc -l db_mask_sensitive_data.yml | awk '{print $1}')
if [ "$MASK_LINES" -le "1" ];then
echo "Nothing mask setting"
exit 1
fi
bundle exec ruby mask_sensitive_data
mysqldump -u$MASK_USER -h$MASK_HOST -p$MASK_PASSWORD $MASK_DB > masked.dump
gsutil cp masked.dump $BACKUP_DUMP_OBJECT_URL
mysql -u$MASK_USER -h$MASK_HOST -p$MASK_PASSWORD -e "DROP DATABASE $MASK_DB" || true