Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to copy production server to test server
#!/bin/bash
USER=user
MYSQLPASSWORD=password
MYSQL="/usr/bin/mysql"
MYSQLDUMP="mysqldump --max_allowed_packet=800M"
TESTSERVER=mynewserver.mydomain.com
FOLDER=/usr/local/atlassian/
EXCLUDE="--exclude *.pid --exclude backup/*.zip --exclude atlassian-confluence.log* --exclude catalina.*.log --exclude localhost.*.log --exclude updateTestServer.sh* --exclude daily-backup-* --exclude backup-*.zip --exclude atlassian-jira.log.* --exclude catalina.out --exclude *confluencedata/index* --exclude *confluencedata/backups/* --exclude *prosjektwiki/confluencedata/backups/* --exclude *old/"
RSYNC="/usr/bin/rsync -avzlp --delete --delete-excluded --progress $EXCLUDE"
echo ""
read -p "Do you want to remove old logfiles from this server before copying data? <y/N> " prompt1
read -p "Do you want to stop services before copying data? <y/N> " prompt2
read -p "Do you want to change the baseurl for all applications in the database? <y/N> " prompt3
read -p "Do you want to remove temporary databse dumps from /tmp/ when all is finished? <y/N> " prompt4
read -p "Are you sure you want to continue? <y/N> " prompt5
if [[ $prompt5 == "y" || $prompt5 == "Y" || $prompt5 == "yes" || $prompt5 == "Yes" ]]
then
echo "Continuing......"
else
exit 0
fi
if [[ $prompt1 == "y" || $prompt1 == "Y" || $prompt1 == "yes" || $prompt1 == "Yes" ]]
then
find /usr/local/atlassian/confluence/logs/ -type f -name '*[0-9]*' -delete
find /usr/local/atlassian/jira/logs/ -type f -name '*[0-9]*' -delete
else
echo ""
fi
#read -p "Do you want to stop services before copying data? <y/N> " prompt
if [[ $prompt2 == "y" || $prompt2 == "Y" || $prompt2 == "yes" || $prompt2 == "Yes" ]]
then
echo "Stopping jira"
service jira stop
echo "Stopping confluence"
service confluence stop
echo "Deleting catalina.out"
/bin/rm -f /usr/local/atlassian/jira/logs/catalina.out
echo "Running java processes:"
ps aux| grep java
read -p "Checking for alive java processes. Are they all dead? <y/N> " promptJ
if [[ $promptJ == "y" || $promptJ == "Y" || $promptJ == "yes" || $promptJ == "Yes" ]]
then
echo "All java processes are confirmed dead. Proceeding."
else
exit 0
fi
else
echo ""
fi
echo "Killing services on $TESTSERVER"
ssh $TESTSERVER "killall -9 java"
sleep 7
echo "Copying the contents from $FODLER to $USER@$TESTSERVER:$FOLDER"
$RSYNC $FOLDER $USER@$TESTSERVER:$FOLDER
echo "Dumping jiradb to /tmp/jiradb.sql"
$MYSQLDUMP -p$MYSQLPASSWORD jiradb > /tmp/jiradb.sql
echo "Dumping confluencedb to /tmp/confluencedb.sql"
$MYSQLDUMP -p$MYSQLPASSWORD confluencedb > /tmp/confluencedb.sql
echo "Importing data to jira"
$MYSQLDUMP -p$MYSQLPASSWORD jiradb > /tmp/jiradb.sql
$MYSQL -p$MYSQLPASSWORD -h $TESTSERVER jiradb < /tmp/confluencedb.sql
echo "Importing data to confluencedb"
$MYSQL -p$MYSQLPASSWORD -h $TESTSERVER confluencedb < /tmp/confluencedb.sql
if [[ $prompt3 == "y" || $prompt3 == "Y" || $prompt3 == "yes" || $prompt3 == "Yes" ]]
then
echo "Changing baseurl for all applications"
echo "Replace the ID with your ID"
$MYSQL -p$MYSQLPASSWORD -h $TESTSERVER -e 'update jiradb.propertystring set propertyvalue="https://myjiraserver.mydomain.com" where ID=10003'
$MYSQL -p$MYSQLPASSWORD -h $TESTSERVER -e "update confluencedb.BANDANA set BANDANAVALUE = replace(BANDANAVALUE, 'https://confluence.mydomain.com', 'https://testconfluence.mydomain.com') where BANDANACONTEXT = '_GLOBAL' and BANDANAKEY = 'atlassian.confluence.settings';"
ssh $TESTSERVER "sed -e 's/confluence.mydomain.com/testconfluence.mydomain.com/g' -i /usr/local/atlassian/confluence/conf/server.xml"
ssh $TESTSERVER "sed -e 's/jira.mydomain.com/testjira.mydomain.com/g' -i /usr/local/atlassian/issues/jira/conf/server.xml"
else
echo ""
fi
if [[ $prompt4 == "y" || $prompt4 == "Y" || $prompt4 == "yes" || $prompt4 == "Yes" ]]
then
/bin/rm -f /tmp/jiradb.sql
/bin/rm -f /tmp/confluencedb.sql
else
echo ""
fi
echo "Starting services"
ssh $TESTSERVER "service jira start"
ssh $TESTSERVER "service confluence start"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment