Skip to content

Commit a2f2059

Browse files
Post db cleanup (#1)
1 parent a6ca559 commit a2f2059

2 files changed

Lines changed: 96 additions & 1 deletion

File tree

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ UPDATE users SET mail=CONCAT('user', uid, '@example.com'), init=CONCAT('user', u
9292
9393
9494
EOF
95-
) | ./vendor/bin/drush @$site.$target_env ah-sql-cli --db=$db_name
95+
) | /var/www/html/$site.$target_env/vendor/bin/drush @$site.$target_env ah-sql-cli --db=$db_name
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/sh
2+
#
3+
# db-copy Cloud hook: db-scrub
4+
#
5+
# Scrub important information from a Drupal database.
6+
#
7+
# Usage: db-scrub.sh site target-env db-name source-env
8+
9+
site="$1"
10+
target_env="$2"
11+
db_name="$3"
12+
source_env="$4"
13+
14+
echo "$site.$target_env: Scrubbing database $db_name"
15+
16+
(cat <<EOF
17+
--
18+
-- Scrub important information from a Drupal database.
19+
--
20+
21+
-- Remove all email addresses.
22+
UPDATE users SET mail=CONCAT('user', uid, '@example.com'), init=CONCAT('user', uid, '@example.com') WHERE uid != 0;
23+
24+
-- Example: Disable a module by setting its system.status value to 0.
25+
-- UPDATE system SET status = 0 WHERE name = 'securepages';
26+
27+
-- Example: Update or delete variables via the variable table.
28+
-- DELETE FROM variable WHERE name='secret_key';
29+
-- Note that to update variables the value must be a properly serialized php array.
30+
-- UPDATE variable SET value='s:24:"http://test.gateway.com/";' WHERE name='payment_gateway';
31+
32+
-- IMPORTANT: If you change the variable table, clear the variables cache.
33+
-- DELETE FROM cache WHERE cid = 'variables';
34+
35+
-- Scrub url aliases for non-admins since these also reveal names
36+
-- Add the IGNORE keyword, since a user may have multiple aliases, and without
37+
-- this keyword the attempt to store duplicate dst values causes the query to fail.
38+
-- UPDATE IGNORE url_alias SET dst = CONCAT('users/', REPLACE(src,'/', '')) WHERE src IN (SELECT CONCAT('user/', u.uid) FROM users u WHERE u.uid NOT IN (SELECT uid FROM users_roles WHERE rid=3) AND u.uid > 0);
39+
40+
-- don't leave e-mail addresses, etc in comments table.
41+
-- UPDATE comments SET name='Anonymous', mail='', homepage='http://example.com' WHERE uid=0;
42+
43+
-- Scrub webform submissions.
44+
-- UPDATE webform_submitted_data set data='*scrubbed*';
45+
46+
-- remove sensitive customer data from custom module
47+
-- TRUNCATE custom_customer_lead_data;
48+
49+
-- USER PASSWORDS
50+
-- These statements assume you want to preserve real passwords for developers. Change 'rid=3' to the
51+
-- developer or test role you want to preserve.
52+
53+
-- DRUPAL 6
54+
-- Remove passwords unless users have 'developer role'
55+
-- UPDATE users SET pass=md5('devpassword') WHERE uid IN (SELECT uid FROM users_roles WHERE rid=3) AND uid > 0;
56+
57+
-- Admin user should not be same but not really well known
58+
-- UPDATE users SET pass = MD5('supersecret!') WHERE uid = 1;
59+
60+
-- DRUPAL 7
61+
-- Drupal 7 requires sites to generate a hashed password specific to their site. A script in the
62+
-- docroot/scripts directory is provided for doing this. From your docroot run the following:
63+
--
64+
-- scripts/password-hash.sh password
65+
--
66+
-- this will generate a hash for the password "password". In the following statements replace
67+
-- $REPLACE THIS$ with your generated hash.
68+
69+
-- Remove passwords unless users have 'developer role'
70+
-- UPDATE users SET pass='$REPLACE THIS$' WHERE uid IN (SELECT uid FROM users_roles WHERE rid=3) AND uid > 0;
71+
72+
-- Admin user should not be same but not really well known
73+
-- UPDATE users SET pass='$REPLACE THIS$' WHERE uid = 1;
74+
75+
-- TRUNCATE accesslog;
76+
-- TRUNCATE access;
77+
-- TRUNCATE cache;
78+
-- TRUNCATE cache_filter;
79+
-- TRUNCATE cache_menu;
80+
-- TRUNCATE cache_page;
81+
-- TRUNCATE cache_views;
82+
-- TRUNCATE cache_views_data;
83+
-- TRUNCATE devel_queries;
84+
-- TRUNCATE devel_times;
85+
-- TRUNCATE flood;
86+
-- TRUNCATE history;
87+
-- TRUNCATE search_dataset;
88+
-- TRUNCATE search_index;
89+
-- TRUNCATE search_total;
90+
-- TRUNCATE sessions;
91+
-- TRUNCATE watchdog;
92+
93+
94+
EOF
95+
) | /var/www/html/$site.$target_env/vendor/bin/drush @$site.$target_env ah-sql-cli --db=$db_name

0 commit comments

Comments
 (0)