Skip to content

Commit

Permalink
Fixed table exclusion issue
Browse files Browse the repository at this point in the history
* Fixed an issue where remote db pulls wouldn't exclude db tables that should have been ignored (such as the templatecaches table)

Signed-off-by: Andrew Welch <[email protected]>
  • Loading branch information
khalwat committed Sep 7, 2017
1 parent 8475526 commit 5395d57
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Craft-Scripts Changelog

## 1.2.3 - 2017.09.07
### Changed
* Fixed an issue where remote db pulls wouldn't exclude db tables that should have been ignored (such as the templatecaches table)

## 1.2.2 - 2017.08.08
### Changed
* Added support for pulling db dumps directly from hosted MySQL/Postgres servers (needed for Heroku and other environments)
Expand Down
4 changes: 2 additions & 2 deletions scripts/backup_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ fi
# Backup the local db
if [ "${GLOBAL_DB_DRIVER}" == "mysql" ] ; then
$LOCAL_MYSQLDUMP_CMD $LOCAL_DB_CREDS $MYSQLDUMP_SCHEMA_ARGS > "$BACKUP_DB_PATH"
$LOCAL_MYSQLDUMP_CMD $LOCAL_DB_CREDS $MYSQLDUMP_DATA_ARGS >> "$BACKUP_DB_PATH"
$LOCAL_MYSQLDUMP_CMD $LOCAL_DB_CREDS $LOCAL_IGNORED_DB_TABLES_STRING $MYSQLDUMP_DATA_ARGS >> "$BACKUP_DB_PATH"
fi
if [ "${GLOBAL_DB_DRIVER}" == "pgsql" ] ; then
echo ${LOCAL_DB_HOST}:${LOCAL_DB_PORT}:${LOCAL_DB_NAME}:${LOCAL_DB_USER}:${LOCAL_DB_PASSWORD} > "${TMP_DB_DUMP_CREDS_PATH}"
chmod 600 "${TMP_DB_DUMP_CREDS_PATH}"
PGPASSFILE="${TMP_DB_DUMP_CREDS_PATH}" $LOCAL_PG_DUMP_CMD $LOCAL_DB_CREDS $PG_DUMP_ARGS --schema="${LOCAL_DB_SCHEMA}" --file="${BACKUP_DB_PATH}"
PGPASSFILE="${TMP_DB_DUMP_CREDS_PATH}" $LOCAL_PG_DUMP_CMD $LOCAL_DB_CREDS $LOCAL_IGNORED_DB_TABLES_STRING $PG_DUMP_ARGS --schema="${LOCAL_DB_SCHEMA}" --file="${BACKUP_DB_PATH}"
rm "${TMP_DB_DUMP_CREDS_PATH}"
fi
gzip -f "$BACKUP_DB_PATH"
Expand Down
7 changes: 4 additions & 3 deletions scripts/common/common_mysql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
# @license MIT


IGNORED_DB_TABLES_STRING=""
LOCAL_IGNORED_DB_TABLES_STRING=""
REMOTE_IGNORED_DB_TABLES_STRING=""
for TABLE in "${EXCLUDED_DB_TABLES[@]}"
do
IGNORED_DB_TABLES_STRING+="--ignore-table=${LOCAL_DB_NAME}.${GLOBAL_DB_TABLE_PREFIX}${TABLE} "
LOCAL_IGNORED_DB_TABLES_STRING+="--ignore-table=${LOCAL_DB_NAME}.${GLOBAL_DB_TABLE_PREFIX}${TABLE} "
REMOTE_IGNORED_DB_TABLES_STRING+="--ignore-table=${REMOTE_DB_NAME}.${GLOBAL_DB_TABLE_PREFIX}${TABLE} "
done

# Additional arguments for mysqldump
Expand All @@ -38,7 +40,6 @@ MYSQLDUMP_SCHEMA_ARGS+=$MYSQLDUMP_ADDITIONAL_ARGS
# Arguments to dump just the data
MYSQLDUMP_DATA_ARGS=""
MYSQLDUMP_DATA_ARGS+="--no-create-info "
MYSQLDUMP_DATA_ARGS+=$IGNORED_DB_TABLES_STRING
MYSQLDUMP_DATA_ARGS+=$MYSQLDUMP_ADDITIONAL_ARGS

# Build the remote mysql credentials
Expand Down
8 changes: 4 additions & 4 deletions scripts/common/common_pgsql.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
# @since 1.2.0
# @license MIT


IGNORED_DB_TABLES_STRING=""
LOCAL_IGNORED_DB_TABLES_STRING=""
REMOTE_IGNORED_DB_TABLES_STRING=""
for TABLE in "${EXCLUDED_DB_TABLES[@]}"
do
IGNORED_DB_TABLES_STRING+="--exclude-table-data=${LOCAL_DB_SCHEMA}.${GLOBAL_DB_TABLE_PREFIX}${TABLE} "
LOCAL_IGNORED_DB_TABLES_STRING+="--exclude-table-data=${LOCAL_DB_SCHEMA}.${GLOBAL_DB_TABLE_PREFIX}${TABLE} "
REMOTE_IGNORED_DB_TABLES_STRING+="--exclude-table-data=${REMOTE_DB_SCHEMA}.${GLOBAL_DB_TABLE_PREFIX}${TABLE} "
done

# Additional arguments for mysqldump
Expand All @@ -27,7 +28,6 @@ PG_DUMP_ADDITIONAL_ARGS+="--clean "
# Arguments to dump just the data
PG_DUMP_ARGS=""
PG_DUMP_ARGS+=$PG_DUMP_ADDITIONAL_ARGS
PG_DUMP_ARGS+=$IGNORED_DB_TABLES_STRING

# Build the remote psql credentials
REMOTE_DB_CREDS=""
Expand Down
12 changes: 6 additions & 6 deletions scripts/pull_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ BACKUP_DB_PATH="/tmp/${LOCAL_DB_NAME}-db-backup-$(date '+%Y%m%d').sql"
if [ "${GLOBAL_DB_DRIVER}" == "mysql" ] ; then
if [ "${REMOTE_DB_USING_SSH}" == "yes" ] ; then
# The database server requires ssh'ing in to connect to it
ssh $REMOTE_SSH_LOGIN -p $REMOTE_SSH_PORT "$REMOTE_MYSQLDUMP_CMD $REMOTE_DB_CREDS $MYSQLDUMP_SCHEMA_ARGS > '$TMP_DB_PATH' ; $REMOTE_MYSQLDUMP_CMD $REMOTE_DB_CREDS $MYSQLDUMP_DATA_ARGS >> '$TMP_DB_PATH' ; gzip -f '$TMP_DB_PATH'"
ssh $REMOTE_SSH_LOGIN -p $REMOTE_SSH_PORT "$REMOTE_MYSQLDUMP_CMD $REMOTE_DB_CREDS $MYSQLDUMP_SCHEMA_ARGS > '$TMP_DB_PATH' ; $REMOTE_MYSQLDUMP_CMD $REMOTE_DB_CREDS $REMOTE_IGNORED_DB_TABLES_STRING $MYSQLDUMP_DATA_ARGS >> '$TMP_DB_PATH' ; gzip -f '$TMP_DB_PATH'"
else
# Connect to the database server directly
$REMOTE_MYSQLDUMP_CMD $REMOTE_DB_CREDS $MYSQLDUMP_SCHEMA_ARGS > "${TMP_DB_PATH}"
$REMOTE_MYSQLDUMP_CMD $REMOTE_DB_CREDS $MYSQLDUMP_DATA_ARGS >> "${TMP_DB_PATH}"
$REMOTE_MYSQLDUMP_CMD $REMOTE_DB_CREDS $REMOTE_IGNORED_DB_TABLES_STRING $MYSQLDUMP_DATA_ARGS >> "${TMP_DB_PATH}"
gzip -f "${TMP_DB_PATH}"
fi
fi
if [ "${GLOBAL_DB_DRIVER}" == "pgsql" ] ; then
if [ "${REMOTE_DB_USING_SSH}" == "yes" ] ; then
# The database server requires ssh'ing in to connect to it
ssh $REMOTE_SSH_LOGIN -p $REMOTE_SSH_PORT "echo ${REMOTE_DB_HOST}:${REMOTE_DB_PORT}:${REMOTE_DB_NAME}:${REMOTE_DB_USER}:${REMOTE_DB_PASSWORD} > '$TMP_DB_DUMP_CREDS_PATH' ; chmod 600 '$TMP_DB_DUMP_CREDS_PATH' ; PGPASSFILE='$TMP_DB_DUMP_CREDS_PATH' $REMOTE_PG_DUMP_CMD $REMOTE_DB_CREDS $PG_DUMP_ARGS --schema='$REMOTE_DB_SCHEMA' --file='$TMP_DB_PATH' ; rm '$TMP_DB_DUMP_CREDS_PATH' ; gzip -f '$TMP_DB_PATH'"
ssh $REMOTE_SSH_LOGIN -p $REMOTE_SSH_PORT "echo ${REMOTE_DB_HOST}:${REMOTE_DB_PORT}:${REMOTE_DB_NAME}:${REMOTE_DB_USER}:${REMOTE_DB_PASSWORD} > '$TMP_DB_DUMP_CREDS_PATH' ; chmod 600 '$TMP_DB_DUMP_CREDS_PATH' ; PGPASSFILE='$TMP_DB_DUMP_CREDS_PATH' $REMOTE_PG_DUMP_CMD $REMOTE_DB_CREDS $REMOTE_IGNORED_DB_TABLES_STRING $PG_DUMP_ARGS --schema='$REMOTE_DB_SCHEMA' --file='$TMP_DB_PATH' ; rm '$TMP_DB_DUMP_CREDS_PATH' ; gzip -f '$TMP_DB_PATH'"
else
# Connect to the database server directly
echo ${REMOTE_DB_HOST}:${REMOTE_DB_PORT}:${REMOTE_DB_NAME}:${REMOTE_DB_USER}:${REMOTE_DB_PASSWORD} > "${TMP_DB_DUMP_CREDS_PATH}"
chmod 600 "${TMP_DB_DUMP_CREDS_PATH}"
PGPASSFILE="${TMP_DB_DUMP_CREDS_PATH}" $REMOTE_PG_DUMP_CMD $REMOTE_DB_CREDS $PG_DUMP_ARGS --schema="${REMOTE_DB_SCHEMA}" --file="${TMP_DB_PATH}"
PGPASSFILE="${TMP_DB_DUMP_CREDS_PATH}" $REMOTE_PG_DUMP_CMD $REMOTE_DB_CREDS $REMOTE_IGNORED_DB_TABLES_STRING $PG_DUMP_ARGS --schema="${REMOTE_DB_SCHEMA}" --file="${TMP_DB_PATH}"
rm "${TMP_DB_DUMP_CREDS_PATH}"
gzip -f "${TMP_DB_PATH}"
fi
Expand All @@ -75,12 +75,12 @@ fi
# Backup the local db
if [ "${GLOBAL_DB_DRIVER}" == "mysql" ] ; then
$LOCAL_MYSQLDUMP_CMD $LOCAL_DB_CREDS $MYSQLDUMP_SCHEMA_ARGS > "$BACKUP_DB_PATH"
$LOCAL_MYSQLDUMP_CMD $LOCAL_DB_CREDS $MYSQLDUMP_DATA_ARGS >> "$BACKUP_DB_PATH"
$LOCAL_MYSQLDUMP_CMD $LOCAL_DB_CREDS $LOCAL_IGNORED_DB_TABLES_STRING $MYSQLDUMP_DATA_ARGS >> "$BACKUP_DB_PATH"
fi
if [ "${GLOBAL_DB_DRIVER}" == "pgsql" ] ; then
echo ${LOCAL_DB_HOST}:${LOCAL_DB_PORT}:${LOCAL_DB_NAME}:${LOCAL_DB_USER}:${LOCAL_DB_PASSWORD} > "${TMP_DB_DUMP_CREDS_PATH}"
chmod 600 "${TMP_DB_DUMP_CREDS_PATH}"
PGPASSFILE="${TMP_DB_DUMP_CREDS_PATH}" $LOCAL_PG_DUMP_CMD $LOCAL_DB_CREDS $PG_DUMP_ARGS --schema="${LOCAL_DB_SCHEMA}" --file="${BACKUP_DB_PATH}"
PGPASSFILE="${TMP_DB_DUMP_CREDS_PATH}" $LOCAL_PG_DUMP_CMD $LOCAL_DB_CREDS $LOCAL_IGNORED_DB_TABLES_STRING $PG_DUMP_ARGS --schema="${LOCAL_DB_SCHEMA}" --file="${BACKUP_DB_PATH}"
rm "${TMP_DB_DUMP_CREDS_PATH}"
fi
gzip -f "$BACKUP_DB_PATH"
Expand Down
4 changes: 2 additions & 2 deletions scripts/restore_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ BACKUP_DB_PATH="/tmp/${LOCAL_DB_NAME}-db-backup-$(date '+%Y%m%d').sql"
# Backup the local db
if [ "${GLOBAL_DB_DRIVER}" == "mysql" ] ; then
$LOCAL_MYSQLDUMP_CMD $LOCAL_DB_CREDS $MYSQLDUMP_SCHEMA_ARGS > "$BACKUP_DB_PATH"
$LOCAL_MYSQLDUMP_CMD $LOCAL_DB_CREDS $MYSQLDUMP_DATA_ARGS >> "$BACKUP_DB_PATH"
$LOCAL_MYSQLDUMP_CMD $LOCAL_DB_CREDS $LOCAL_IGNORED_DB_TABLES_STRING $MYSQLDUMP_DATA_ARGS >> "$BACKUP_DB_PATH"
fi
if [ "${GLOBAL_DB_DRIVER}" == "pgsql" ] ; then
echo ${LOCAL_DB_HOST}:${LOCAL_DB_PORT}:${LOCAL_DB_NAME}:${LOCAL_DB_USER}:${LOCAL_DB_PASSWORD} > "${TMP_DB_DUMP_CREDS_PATH}"
chmod 600 "${TMP_DB_DUMP_CREDS_PATH}"
PGPASSFILE="${TMP_DB_DUMP_CREDS_PATH}" $LOCAL_PG_DUMP_CMD $LOCAL_DB_CREDS $PG_DUMP_ARGS --schema="${LOCAL_DB_SCHEMA}" --file="${BACKUP_DB_PATH}"
PGPASSFILE="${TMP_DB_DUMP_CREDS_PATH}" $LOCAL_PG_DUMP_CMD $LOCAL_DB_CREDS $LOCAL_IGNORED_DB_TABLES_STRING $PG_DUMP_ARGS --schema="${LOCAL_DB_SCHEMA}" --file="${BACKUP_DB_PATH}"
rm "${TMP_DB_DUMP_CREDS_PATH}"
fi
gzip -f "$BACKUP_DB_PATH"
Expand Down

0 comments on commit 5395d57

Please sign in to comment.