Jcrespo has submitted this change and it was merged.

Change subject: Migrate redact_sanitarium.sh script from software to puppet
......................................................................


Migrate redact_sanitarium.sh script from software to puppet

Deploy it on sanitarium2 role automatically.

Bug: T150802
Change-Id: I99ed073159c07c62c86516fc8b1888c8b915b85a
---
A modules/role/files/mariadb/redact_sanitarium.sh
M modules/role/manifests/mariadb.pp
2 files changed, 97 insertions(+), 0 deletions(-)

Approvals:
  Jcrespo: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/role/files/mariadb/redact_sanitarium.sh 
b/modules/role/files/mariadb/redact_sanitarium.sh
new file mode 100755
index 0000000..eefd3f2
--- /dev/null
+++ b/modules/role/files/mariadb/redact_sanitarium.sh
@@ -0,0 +1,88 @@
+#!/bin/bash
+
+db=$1
+host=${2:-localhost}
+port=${3:-3306}
+
+if [ -z "$db" ]; then
+    echo "usage: <script> <db> [<host> [<port>]]" 1>&2
+    exit 1
+fi
+
+if [[ ! "$host" =~ ^(db10(69|95)(\..+)?|localhost)$ ]]; then
+    echo "unexpected sanitarium host! $host" 2>&1
+    exit 1
+fi
+
+if [[ ! "$port" =~ ^33(06|1[1234567])$ ]]; then
+    echo "unexpected sanitarium port! $port" 2>&1
+    exit 1
+fi
+
+if [[ "$host" == "localhost" && "$port" == "3306" ]]; then
+    dsn=""
+else
+    dsn="-h $host -P $port"
+fi
+
+query="mysql --skip-column-names $dsn -e "
+
+for tbl in $(egrep ',F' /etc/mysql/filtered_tables.txt | awk -F ',' '{print 
$1}' | uniq); do
+
+    echo "-- $tbl"
+
+    insert="SET SESSION sql_log_bin = 0; CREATE DEFINER='root'@'localhost' 
TRIGGER ${db}.${tbl}_insert BEFORE INSERT ON ${db}.${tbl} FOR EACH ROW SET"
+    update="SET SESSION sql_log_bin = 0; CREATE DEFINER='root'@'localhost' 
TRIGGER ${db}.${tbl}_update BEFORE UPDATE ON ${db}.${tbl} FOR EACH ROW SET"
+    remove="SET SESSION sql_log_bin = 1; UPDATE ${db}.${tbl} SET"
+
+    for col in $(egrep "${tbl},.*,F" /etc/mysql/filtered_tables.txt | awk -F 
',' '{print $2}'); do
+
+        datatype=$($query "select data_type from columns where table_schema = 
'${db}' and table_name = '${tbl}' and column_name = '${col}'" 
information_schema)
+
+        if [ -n "$datatype" ]; then
+
+            echo "-- $col found"
+
+            if [[ "$datatype" =~ int ]]; then
+                insert="$insert NEW.${col} = 0,"
+                update="$update NEW.${col} = 0,"
+                remove="$remove ${col} = 0,"
+            else
+                insert="$insert NEW.${col} = '',"
+                update="$update NEW.${col} = '',"
+                remove="$remove ${col} = '',"
+            fi
+
+        else
+            echo "-- $col MISSING"
+        fi
+
+    done
+
+    if [[ "$insert" =~ ^(.*),$ ]]; then
+        insert="${BASH_REMATCH[1]}"
+    fi
+
+    if [[ "$update" =~ ^(.*),$ ]]; then
+        update="${BASH_REMATCH[1]}"
+    fi
+
+    if [[ "$remove" =~ ^(.*),$ ]]; then
+        remove="${BASH_REMATCH[1]}"
+    fi
+
+    echo "DROP TRIGGER IF EXISTS ${db}.${tbl}_insert;"
+    echo "DROP TRIGGER IF EXISTS ${db}.${tbl}_update;"
+
+    if [[ ! "$insert" =~ SET$ ]]; then
+
+        echo "-- $insert"
+        echo "$insert;"
+        echo "-- $update"
+        echo "$update;"
+        echo "-- $remove"
+        echo "set session binlog_format = 'STATEMENT'; $remove;"
+
+    fi
+
+done
diff --git a/modules/role/manifests/mariadb.pp 
b/modules/role/manifests/mariadb.pp
index 13c6fee..e9c9ee6 100644
--- a/modules/role/manifests/mariadb.pp
+++ b/modules/role/manifests/mariadb.pp
@@ -821,6 +821,15 @@
     class { 'mariadb::monitor_process':
         contact_group => 'admins',
     }
+
+    file { '/usr/local/sbin/redact_sanitarium.sh':
+        ensure  => file,
+        source  => 'puppet:///modules/role/mariadb/redact_sanitarium.sh',
+        owner   => 'root',
+        group   => 'root',
+        mode    => '0744',
+        require => File['/etc/mysql/filtered_tables.txt'],
+    }
 }
 
 # MariaDB 10 labsdb multiple-shards slave.

-- 
To view, visit https://gerrit.wikimedia.org/r/324208
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I99ed073159c07c62c86516fc8b1888c8b915b85a
Gerrit-PatchSet: 4
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Jcrespo <jcre...@wikimedia.org>
Gerrit-Reviewer: Jcrespo <jcre...@wikimedia.org>
Gerrit-Reviewer: Marostegui <maroste...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to