Skip to content

Instantly share code, notes, and snippets.

@coolbung
Forked from parthlawate/tj_demo-refresh.sh
Last active December 26, 2016 09:30
Show Gist options
  • Save coolbung/0f69b1fb61d86db21497fd368ccf3f88 to your computer and use it in GitHub Desktop.
Save coolbung/0f69b1fb61d86db21497fd368ccf3f88 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#* @package Component Name
#* @copyright Copyright (C) 2009 2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved.
#* @license GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
#* @link http://www.techjoomla.com
# This Script can be used to maintain your demos and refresh them periodically
# It can also be used to create replication instances quickly for development and sync them with live or the other way round
# Another use of the script is for code deployments from local to live
# Currently this is for Joomla but you could potentially fork it for any database of file based application
# Fair Warning : Note that you are playing with your live server files and Database. So make sure you know what you are doing !
# Remote Server - This is where you keep a clean copy of your demo
# Local server - The server local to this script. This is where your publicly accessible demo resides.
# Remote server connection
REMOTE_PORT=2022
REMOTE_SERVER=subzero.com
REMOTE_USER=subzero
REMOTE_PATH=/home/subzero/httpdocs/demos/js25
# Local Path setup
LOCAL_PATH=/home/scorpion/httpdocs/demos/
LOCAL_TMP=/home/scorpion/backup/refresh/tmp
# Remote Database
REMOTE_HOST=host
REMOTE_DB=db
REMOTE_DB_USR=user
REMOTE_DB_PASS=pass
REMOTE_PREFIX=prefix
# Local Database
LOCAL_HOST=host
LOCAL_DB=db
LOCAL_DB_USR=user
LOCAL_DB_PASS=pass
# Take everything including configuration.php
#rsync -avz --delete --exclude=**/tmp -e 'ssh -p'$REMOTE_PORT $REMOTE_USER@$REMOTE_SERVER:$REMOTE_PATH $LOCAL_PATH
# Skip config cache etc
rsync -avz --delete --exclude=**/cache --exclude=**/administrator/cache/ --exclude=**/tmp --exclude=**/configuration.php -e 'ssh -p'$REMOTE_PORT $REMOTE_USER@$REMOTE_SERVER:$REMOTE_PATH $LOCAL_PATH
vice-a-versa
#fix permission issues if needed
#chmod 755 $LOCAL_PATH
#cd $LOCAL_PATH
#find . -type f -exec chmod 644 {} \;
#find . -type d -exec chmod 755 {} \;
# Connect & Take Backup of Remote Server
ssh -p$REMOTE_PORT $REMOTE_USER@$REMOTE_SERVER mysqldump -h $REMOTE_HOST --user=$REMOTE_DB_USR --password=$REMOTE_DB_PASS $REMOTE_DB --ignore-table=$REMOTE_DB.$REMOTE_PREFIX'_session' > $LOCAL_TMP/demojs.sql
#exit
# Restore Database
mysql -u $LOCAL_DB_USR -p$LOCAL_DB_PASS -h $LOCAL_HOST $LOCAL_DB< $LOCAL_TMP/demojs.sql
# Replace User email Addresses in database with dummy ones (optional)
mysql -u $LOCAL_DB_USR -p$LOCAL_DB_PASS -h $LOCAL_HOST $LOCAL_DB -e "UPDATE `jos_users` SET `email`=concat(SUBSTRING(`email`, 1,LOCATE('@', `email`)),'mailinator.com')"
mysql -u $LOCAL_DB_USR -p$LOCAL_DB_PASS -h $LOCAL_HOST $LOCAL_DB -e "UPDATE `jos_social_mailer` SET `recipient_email`=concat(SUBSTRING(`recipient_email`, 1,LOCATE('@', `recipient_email`)),'mailinator.com')"
mysql -u $LOCAL_DB_USR -p$LOCAL_DB_PASS -h $LOCAL_HOST $LOCAL_DB -e "UPDATE `jos_jma_subscribers` SET `email_id`=concat(SUBSTRING(`email_id`, 1,LOCATE('@', `email_id`)),'mailinator.com')"
mysql -u $LOCAL_DB_USR -p$LOCAL_DB_PASS -h $LOCAL_HOST $LOCAL_DB -e "UPDATE `jos_jticketing_users` SET `user_email`=concat(SUBSTRING(`user_email`, 1,LOCATE('@', `user_email`)),'mailinator.com')"
mysql -u $LOCAL_DB_USR -p$LOCAL_DB_PASS -h $LOCAL_HOST $LOCAL_DB -e "UPDATE `jos_jticketing_order` SET `email`=concat(SUBSTRING(`email`, 1,LOCATE('@', `email`)),'mailinator.com')"
mysql -u $LOCAL_DB_USR -p$LOCAL_DB_PASS -h $LOCAL_HOST $LOCAL_DB -e "UPDATE `jos_jticketing_checkindetails` SET `attendee_email`=concat(SUBSTRING(`attendee_email`, 1,LOCATE('@', `attendee_email`)),'mailinator.com')"
mysql -u $LOCAL_DB_USR -p$LOCAL_DB_PASS -h $LOCAL_HOST $LOCAL_DB -e "UPDATE `jos_jticketing_queue_before_upgrade` SET `email`=concat(SUBSTRING(`email`, 1,LOCATE('@', `email`)),'mailinator.com')"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment