3 # Exit immediately on uninitialized variable or error, and print each command.
6 # Run a snapshot phase. See below for how it is called. ${suffix} is the phase
7 # and used in filenames.
9 # Allow skipping common sanitization. For CiviCRM and anything else
11 if [ ! "${skip_common-}" ]; then
12 # Execute common SQL commands.
13 [ -f "snapshot/common${suffix}.sql" ] && mysql -o ${tmp_args} < "snapshot/common${suffix}.sql"
14 # Execute common SQL commands, but don't exit if they fail.
15 [ -f "snapshot/common-force${suffix}.sql" ] && mysql -f -o ${tmp_args} < "snapshot/common-force${suffix}.sql"
18 # Skip if this sanitization and phase does not exit.
19 [ ! -f "snapshot/${sanitization}${suffix}.sql" ] && return
20 # Execute SQL for this sanitization and phase.
21 mysql -o ${tmp_args} < "snapshot/${sanitization}${suffix}.sql"
24 subdir=$(echo "${suffix}" | sed -e 's/^\.//')
25 # Store reduce with dev, they are the same level of sanitization.
26 if [ "${subdir}" = 'reduce' ]; then
30 mysqldump --single-transaction --quick ${tmp_args} | sed -e 's/^) ENGINE=[^ ]*/)/' | bzip2 > "/var/dumps/${subdir}/${JOB_NAME}${suffix}-${BUILD_NUMBER}-in-progress.sql.bz2"
31 mv -v "/var/dumps/${subdir}/${JOB_NAME}${suffix}-${BUILD_NUMBER}-in-progress.sql.bz2" "/var/dumps/${subdir}/${JOB_NAME}${suffix}-${BUILD_NUMBER}.sql.bz2"
32 ln -sfv "${JOB_NAME}${suffix}-${BUILD_NUMBER}.sql.bz2" "/var/dumps/${subdir}/${JOB_NAME}${suffix}-current.sql.bz2"
34 # Remove old snapshots.
35 old_snapshots=$(ls -t /var/dumps/${subdir}/${JOB_NAME}${suffix}-[0-9]*.sql.{bz2,gz} | tail -n +2)
36 if [ -n "${old_snapshots}" ]; then
37 rm -v ${old_snapshots}
42 echo "DROP DATABASE ${tmp_db}; CREATE DATABASE ${tmp_db};" | mysql ${tmp_args}
45 # Configure credentials
50 # If the sanitization is not set, use the DB name.
51 [ "${sanitization-}" ] || sanitization=${db_name}
52 # If the DB host is not set, use db3-vip.
53 [ "${db_host-}" ] || db_host=db3-vip.drupal.org
55 tmp_db=drupal_sanitize
58 tmp_host=db3-vip.drupal.org
59 tmp_args="-h${tmp_host} -u${tmp_user} -p${tmp_pass} ${tmp_db}"
63 # Make a copy of live.
64 mysqldump -h$db_host -u$db_user -p$db_pass --single-transaction --quick $db_name 2> "${WORKSPACE}/mysqldump-errors.txt" | gzip > "${WORKSPACE}/tmp.mysql.gz"
66 if [ -s "${WORKSPACE}/mysqldump-errors.txt" ]; then
67 rm "${WORKSPACE}/tmp.mysql.gz"
68 cat "${WORKSPACE}/mysqldump-errors.txt"
71 # Copy live to tmp database.
72 gunzip < "${WORKSPACE}/tmp.mysql.gz" | mysql -o ${tmp_args}
73 rm "${WORKSPACE}/tmp.mysql.gz"
75 # Save a copy of the schema.
76 mysqldump --single-transaction --quick ${tmp_args} -d --compact --skip-opt > "${WORKSPACE}/schema.mysql"
78 # Truncate all tables with cache in the name.
79 echo "SHOW TABLES LIKE '%cache%';" | mysql -o ${tmp_args} | tail -n +2 | sed -e "s/^\(.*\)$/TRUNCATE \1;/" | mysql -o ${tmp_args}
80 echo "SHOW TABLES LIKE 'civicrm_export_temp%';" | mysql -o ${tmp_args} | tail -n +2 | sed -e "s/^\(.*\)$/TRUNCATE \1;/" | mysql -o ${tmp_args}
81 echo "SHOW TABLES LIKE 'civicrm_import_job%';" | mysql -o ${tmp_args} | tail -n +2 | sed -e "s/^\(.*\)$/TRUNCATE \1;/" | mysql -o ${tmp_args}
85 # Raw is nearly unsanitized, excpet for some keys. Git-dev uses this for emails.
89 # A snapshot suitable for staging. We remove emails to avoid emailing people.
93 # A snapshot suitable for dev. We remove all private information.
97 # A smaller snapshot for taking up less space on dev.