Created
February 19, 2020 04:53
-
-
Save seamuslee001/6dccc4310d2f72460d272987613092f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
COMPRESSEDMYSQL=1 | |
################################################# | |
## Helpers | |
function fatal() { | |
echo "Fatal: $@" | |
exit 1 | |
} | |
function show_help() { | |
PROG=$(basename "$0") | |
echo "about: To refresh staging site you need to supply" | |
echo "-target-civicrm-db the name of the target civicrm database" | |
echo "-target-cms-db the name of the target cms database" | |
echo "-source-civicrm-db the name of the source civicrm database" | |
echo "-source-cms-db the name of the source cms database" | |
echo "-source-files-dir the absolute path to the source files directory" | |
echo "-target-files-dir the absolute path to the target files directory" | |
echo "-mysql-backup-dir the directory containing the MySQL Backups" | |
} | |
while [ -n "$1" ] ; do | |
OPTION="$1" | |
shift | |
case "$OPTION" in | |
-target-civicrm-db) | |
TARGETCIVIDB="$1" | |
shift | |
;; | |
-target-cms-db) | |
TARGETCMSDB="$1" | |
shift | |
;; | |
-source-cms-db) | |
SOURCECMSDB="$1" | |
shift | |
;; | |
-source-civicrm-db) | |
SOURCECIVICRMDB="$1" | |
shift | |
;; | |
-source-files-dir) | |
SOURCEFILESDIR="$1" | |
shift | |
;; | |
-target-files-dir) | |
TARGETFILESDIR="$1" | |
shift | |
;; | |
-mysql-backup-dir) | |
MYSQLBACKUPDIR="$1" | |
shift | |
;; | |
-h|--help|-?) | |
show_help | |
exit 2 | |
;; | |
esac | |
done | |
## Validate | |
if [ -z "$TARGETCIVIDB" -o -z "$TARGETCMSDB" -o -z "$SOURCECMSDB" -o -z "$SOURCECIVICRMDB" -o -z "$SOURCEFILESDIR" -o -z "$TARGETFILESDIR" -o -z "$MYSQLBACKUPDIR" ]; then | |
echo "Error: Missing required argument" | |
echo | |
show_help | |
exit 2 | |
fi | |
# If we are dealing with compressed MySQL Backups gunzip them first | |
cd $MYSQLBACKUPDIR | |
if [ $COMPRESSEDMYSQL ]; then | |
gunzip "$SOURCECMSDB.sql.gz" | |
gunzip "$SOURCECIVICRMDB.sql.gz" | |
fi | |
#Now load in over the top of the current staging databases the production backups | |
mysql $TARGETCMSDB < "$SOURCECMSDB.sql" | |
mysql $TARGETCIVIDB < "$SOURCECIVICRMDB.sql" | |
# If the MySQL backup was gziped before re-gzip it now. | |
if [ $COMPRESSEDMYSQL ]; then | |
gzip "$SOURCECMSDB.sql" | |
gzip "$SOURCECIVICRMDB.sql" | |
fi | |
# Sync the static images across from production to staging | |
rsync -av --dry-run --exclude=ConfigAndLog --exclude=ext --exclude=templates_c --exclude=ConfigAndLog.bak $SOURCEFILESDIR $TARGETFILESDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment