├── atlassian_drop_db_tables ├── atlassian_rotate_tomcat_logs ├── atlassian_jira_clean_accounts ├── atlassian_fs_backup ├── atlassian_full_backup ├── README.md ├── atlassian_db_backup ├── atlassian_restore_db ├── atlassian_restore_fs_db └── atlassian_create_test_server /atlassian_drop_db_tables: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script drops all tables from the specified database 4 | # This is done to clear out the database without having to drop it entirely 5 | # This is an important step in the Atlassian DB restoration process 6 | 7 | # Must be root to run this script 8 | if [ "`/usr/bin/id -urn`" != "root" ] ; then 9 | echo -e "\nYou must be root to execute this script \n" 10 | exit 1 11 | fi 12 | 13 | # Name of the database is a required paramater 14 | DBNAME=$1 15 | 16 | if [ "$DBNAME" == "" ] ; then 17 | echo -e "Usage: `basename $0` [DBNAME]" 18 | exit 1 19 | fi 20 | 21 | TABLES=$(mysql $DBNAME -e "SHOW TABLES" | awk '{ print $1 }' | grep -v "^Tables_in_$DBNAME") 22 | 23 | if [ "$TABLES" == "" ] ; then 24 | echo -e "There was a problem accessing the $DBNAME database or no tables were found" 25 | exit 1 26 | fi 27 | 28 | # Create a comma separated list of tables to use in the DROP TABLE statement 29 | TABLELIST=$(echo $TABLES | sed 's/ /, /g') 30 | 31 | # Before we drop the tables we remove the foreign key constraint checks and re-enable when finished 32 | # The removal of this check only affects this active session - it does affect other databases 33 | mysql $DBNAME -e "SET foreign_key_checks = 0 ; DROP TABLE $TABLELIST ; SET foreign_key_checks = 1" 34 | -------------------------------------------------------------------------------- /atlassian_rotate_tomcat_logs: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # JIRA/Confluence do not have built in functionality to expire Tomcat logs: 4 | # access_log.DATE 5 | # catalina.DATE.log 6 | # host-manager.DATE.log 7 | # localhost.DATE.log 8 | # manager.DATE.log 9 | 10 | # This script will handle the expiration of Tomcat's log files 11 | # with the exception of catalina.out which is handled by logrotate 12 | # in /etc/logrotate.d/atlassian 13 | 14 | # Must be root to run this script 15 | if [ "`/usr/bin/id -urn`" != "root" ] ; then 16 | echo -e "\nYou must be root to execute this script \n" 17 | exit 1 18 | fi 19 | 20 | USAGE() { 21 | echo -e "\nUsage: `basename $0` [ -c | -j ] " 22 | echo -e "-c --> Rotate Confluence Tomcat logs" 23 | echo -e "-j --> Rotate JIRA Tomcat logs" 24 | } 25 | 26 | INSTALL_DIR="/usr/local/atlassian" 27 | SAVETIME=180 28 | APP="null" 29 | 30 | while getopts ":cj" OPT ; do 31 | case $OPT in 32 | c) 33 | APP="confluence" 34 | TOMCAT_LOG_DIR="$INSTALL_DIR/confluence/logs" 35 | ;; 36 | j) 37 | APP="jira" 38 | TOMCAT_LOG_DIR="$INSTALL_DIR/jira/logs" 39 | ;; 40 | \?) 41 | echo -e "\nInvalid option: -$OPTARG" >&2 42 | USAGE 43 | exit 1 44 | ;; 45 | :) 46 | echo -e "\nOption -$OPTARG requires an argument" >&2 47 | USAGE 48 | exit 1 49 | ;; 50 | esac 51 | done 52 | 53 | if [ "$APP" == "null" ] ; then 54 | USAGE 55 | exit 1 56 | fi 57 | 58 | if [ ! -r $TOMCAT_LOG_DIR ] ; then 59 | echo -e "\nTomcat log directory $TOMCAT_LOG_DIR could not be accessed.\n" 60 | exit 1 61 | fi 62 | 63 | find $TOMCAT_LOG_DIR -type f -name "*.????-??-??*" -mtime +$SAVETIME | xargs rm -vf 64 | -------------------------------------------------------------------------------- /atlassian_jira_clean_accounts: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script cleans out JIRA user accounts by looking up a query string 4 | # in the database, finding all accounts related to that string 5 | 6 | # It then uses JIRA's REST API to perform the account removal 7 | 8 | # To use the REST API, the script connects to the 9 | # local JIRA instance as an admin-level user that has permission 10 | # to perform account deletions 11 | 12 | # Must be root to run this script 13 | if [ "`/usr/bin/id -urn`" != "root" ] ; then 14 | echo -e "\nYou must be root to execute this script \n" 15 | exit 1 16 | fi 17 | 18 | JIRAHOME="/var/atlassian/application-data/jira" 19 | JIRAUSERENV=".jirauserenv" 20 | JIRAHOSTNAME=`hostname` 21 | USERQUERY=$1 22 | 23 | if [ -f ${JIRAHOME}/${JIRAUSERENV} ] ; then 24 | . ${JIRAHOME}/${JIRAUSERENV} 25 | else 26 | echo "Could not find JIRA user env file" 27 | echo "No user information available to connect to JIRA instance" 28 | exit 1 29 | fi 30 | 31 | if [ "${JIRAHOSTNAME}" == "t-w-jira01" ] ; then 32 | JIRA_URL="https://jira-test.library.ucla.edu" 33 | elif [ "${JIRAHOSTNAME}" == "p-w-jira01" ] ; then 34 | JIRA_URL="https://jira.library.ucla.edu" 35 | else 36 | echo "Could not determine JIRA URL based on system hostname" 37 | exit 1 38 | fi 39 | 40 | if [ "${USERQUERY}" == "" ] ; then 41 | echo "Usage: `basename $0` [USER-SEARCH-PARAMTER]" 42 | echo "Example: `basename $0` .ru" 43 | exit 1 44 | fi 45 | 46 | USERS_LIST=$(mysql -e "SELECT user_name FROM cwd_user WHERE email_address like \"%${USERQUERY}\"" | awk '{ print $1 }' | grep -v "^user_name") 47 | 48 | if [ "${USERS_LIST}" == "" ] ; then 49 | echo -e "There was a problem accessing the database or no users were found" 50 | exit 1 51 | fi 52 | 53 | for USER in ${USERS_LIST} ; do 54 | echo "Delete the ${USER} account from JIRA? (1 for Yes / 2 for No)" 55 | select CHOICE in "Yes" "No"; do 56 | case "${CHOICE}" in 57 | Yes ) curl --request DELETE --user "${JIRA_USER}:${JIRA_PASSWD}" --header "Accept: application/json" --url "${JIRA_URL}/rest/api/2/user?username=${USER}" 58 | echo "Username ${USER} removed" 59 | break 60 | ;; 61 | No ) echo "Username ${USER} preserved" 62 | break 63 | ;; 64 | esac 65 | done 66 | done 67 | -------------------------------------------------------------------------------- /atlassian_fs_backup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Creates a filesystem backup of Confluence or JIRA 4 | 5 | # Must be root to run this script 6 | if [ "`/usr/bin/id -urn`" != "root" ] ; then 7 | echo -e "\nYou must be root to execute this script \n" 8 | exit 1 9 | fi 10 | 11 | USAGE() { 12 | echo -e "\nUsage: `basename $0` [ -c | -j ] " 13 | echo -e "-c --> Backup Confluence filesystem" 14 | echo -e "-j --> Backup JIRA filesystem" 15 | } 16 | 17 | BACKUP_DIR="/atlassianbackup" 18 | INSTALL_DIR="/usr/local/atlassian" 19 | HOME_DIR="/var/atlassian/application-data" 20 | BIN_DIR="null" 21 | APP="null" 22 | 23 | while getopts ":cj" OPT ; do 24 | case $OPT in 25 | c) 26 | APP="confluence" 27 | ENV_FILE="$INSTALL_DIR/confluence/bin/user.sh" 28 | INSTALL_DIR_ARCH=confluence_installdir_`date "+%Y%m%d"`_$$.tar.gz 29 | HOME_DIR_ARCH=confluence_homedir_`date "+%Y%m%d"`_$$.tar.gz 30 | ;; 31 | j) 32 | APP="jira" 33 | ENV_FILE="$INSTALL_DIR/jira/bin/user.sh" 34 | INSTALL_DIR_ARCH=jira_installdir_`date "+%Y%m%d"`_$$.tar.gz 35 | HOME_DIR_ARCH=jira_homedir_`date "+%Y%m%d"`_$$.tar.gz 36 | ;; 37 | \?) 38 | echo -e "\nInvalid option: -$OPTARG" >&2 39 | USAGE 40 | exit 1 41 | ;; 42 | :) 43 | echo -e "\nOption -$OPTARG requires an argument" >&2 44 | USAGE 45 | exit 1 46 | ;; 47 | esac 48 | done 49 | 50 | if [ "$APP" == "null" ] ; then 51 | USAGE 52 | exit 1 53 | fi 54 | 55 | # Perform check to determine if this script can run on this server 56 | if [ ! -s $ENV_FILE ] ; then 57 | echo -e "\nCould not locate a $APP installation on this system \n" 58 | exit 1 59 | fi 60 | 61 | echo -e "Starting back-up of the $APP filesystem \n" 62 | echo -e "Backing-up $APP Installation directory..." 63 | tar czf $BACKUP_DIR/$INSTALL_DIR_ARCH -C $INSTALL_DIR . > /dev/null 2>&1 64 | if [ $? -ne 0 -a $? -ne 1 ] ; then 65 | echo -e "\nFailed to create the Installation directory archive - exiting \n" 66 | if [ -f $BACKUP_DIR/$INSTALL_DIR_ARCH ]; then 67 | rm -f $BACKUP_DIR/$INSTALL_DIR_ARCH 68 | fi 69 | exit 1 70 | fi 71 | echo -e "Backing-up $APP Home directory..." 72 | tar czf $BACKUP_DIR/$HOME_DIR_ARCH -C $HOME_DIR . > /dev/null 2>&1 73 | if [ $? -ne 0 -a $? -ne 1 ] ; then 74 | echo -e "\nFailed to create the Home directory archive - exiting \n" 75 | if [ -f $BACKUP_DIR/$HOME_DIR_ARCH ]; then 76 | rm -f $BACKUP_DIR/$HOME_DIR_ARCH 77 | fi 78 | exit 1 79 | fi 80 | 81 | echo -e "\nBackup is complete and is available at $BACKUP_DIR/$INSTALL_DIR_ARCH and $BACKUP_DIR/$HOME_DIR_ARCH" 82 | -------------------------------------------------------------------------------- /atlassian_full_backup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script is meant to be run as a root cronjob to backup a Confluence or JIRA server 4 | # It utilizes two scripts: 5 | # - atlassian_fs_backup - create filesystem backup 6 | # - atlassian_db_backup - crate database backup 7 | # 8 | # After the backup completes successfully, we check to see that only seven days worth of 9 | # backup directories. Anything older than seven days is removed. 10 | 11 | # Must be root to run this script 12 | if [ "`/usr/bin/id -urn`" != "root" ] ; then 13 | echo -e "\nYou must be root to execute this script \n" 14 | exit 1 15 | fi 16 | 17 | USAGE() { 18 | echo -e "\nUsage: `basename $0` [ -c | -j ] " 19 | echo -e "-c --> Backup Confluence" 20 | echo -e "-j --> Backup JIRA" 21 | } 22 | 23 | BACKUP_DIR="/atlassianbackup" 24 | SCRIPT_DIR="/usr/local/bin/atlassian" 25 | FS_BACKUP="${SCRIPT_DIR}/atlassian_fs_backup" 26 | DB_BACKUP="${SCRIPT_DIR}/atlassian_db_backup" 27 | TODAY=`date "+%Y%m%d"` 28 | DAYSAGO=`date -d 'now - 1 days' "+%Y%m%d"` 29 | APP="null" 30 | 31 | while getopts ":cj" OPT ; do 32 | case ${OPT} in 33 | c) 34 | APP="confluence" 35 | FS_OPTIONS="-c" 36 | DB_OPTIONS="-c -s" 37 | ;; 38 | j) 39 | APP="jira" 40 | FS_OPTIONS="-j" 41 | DB_OPTIONS="-j -s" 42 | ;; 43 | \?) 44 | echo -e "\nInvalid option: -${OPTARG}" >&2 45 | USAGE 46 | exit 1 47 | ;; 48 | :) 49 | echo -e "\nOption -${OPTARG} requires an argument" >&2 50 | USAGE 51 | exit 1 52 | ;; 53 | esac 54 | done 55 | 56 | if [ "${APP}" == "null" ] ; then 57 | USAGE 58 | exit 1 59 | fi 60 | 61 | DAILY_BACKUP_DIR="${BACKUP_DIR}/${APP}/${TODAY}" 62 | 63 | # ------------------------------------------------------------- 64 | # Execute Full Backup 65 | # ------------------------------------------------------------- 66 | 67 | mkdir -p ${DAILY_BACKUP_DIR} 68 | 69 | echo -e "\nPerforming ${APP} filesystem backup..." 70 | ${FS_BACKUP} ${FS_OPTIONS} 71 | if [ $? -ne 0 ] ; then 72 | echo -e "Error performing ${APP} filesystem backup! Exiting from backup process.\n" 73 | exit 1 74 | fi 75 | 76 | echo -e "\nPerforming ${APP} database backup..." 77 | ${DB_BACKUP} ${DB_OPTIONS} 78 | if [ $? -ne 0 ] ; then 79 | echo -e "Error performing ${APP} database backup! Exiting from backup process.\n" 80 | exit 1 81 | fi 82 | 83 | mv ${BACKUP_DIR}/${APP}_*_${TODAY_}* ${DAILY_BACKUP_DIR} 84 | 85 | # ------------------------------------------------------------- 86 | # Rotate Backup Files - Keep Files for ${DAYSAGO} 87 | # ------------------------------------------------------------- 88 | 89 | BACKUP_DATES=`find ${BACKUP_DIR}/${APP} -type d -name "[0-9]*" -printf "%f\n" | sort -n` 90 | 91 | # Each backup directory is named in YYYYMMDD format based on the day it was created. 92 | # If a directory's name is older than $DAYSAGO, the directory is removed. 93 | if [ -n "${BACKUP_DATES}" ] ; then 94 | for DATE in ${BACKUP_DATES} ; do 95 | if [ $(( ${DATE} - ${DAYSAGO} )) -lt 0 ] ; then 96 | rm -rf ${BACKUP_DIR}/${APP}/${DATE} 97 | fi 98 | done 99 | fi 100 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## README - Atlassian Scripts ## 2 | 3 | These scripts can be used on the Library's Confluence and JIRA servers for the purpose of managing back-ups, restores and creating new test/production environments 4 | 5 | ### What these scripts do ### 6 | 7 | * atlassian_create_test_server : Creates a Confluence or JIRA test server given the back-up files of a production server 8 | ``` 9 | 10 | Usage: atlassian_create_test_server [ -c | -j ] -d [DATABASE-HOSTNAME] -x [PATH-TO-CFGXML-FILE] -s [PATH-TO-SQLDUMP-FILE] -i [PATH-TO-INSTALLDIR-TAR] -h [PATH-TO-HOMEDIR-TAR] 11 | -c --> Create a Confluence test server 12 | -j --> Create a JIRA test server 13 | -d DATABASE-HOSTNAME --> Hostname of MySQL Database server 14 | -x PATH-TO-CFGXML-FILE --> Location of xml file with connection information to the Confluence/JIRA Test database 15 | -s PATH-TO-SQLDUMP-FILE --> Location of the Production SQL DUMP file 16 | -i PATH-TO-INSTALLDIR-TAR --> Location of the Production Installation directory archive 17 | -h PATH-TO-HOMEDIR-TAR --> Location of the Production Home directory archive 18 | ``` 19 | * atlassian_db_backup : Perform a Confluence or JIRA database backup 20 | ``` 21 | 22 | Usage: atlassian_db_backup [ -c | -j ] [ -s ] 23 | -c --> Backup Confluence MySQL DB 24 | -j --> Backup JIRA MySQL DB 25 | -s --> Indicate this script should run in silent mode 26 | ``` 27 | * atlassian_drop_db_tables : Drops all tables from the specified database - this is used during restore operations to ensure a clean database 28 | ``` 29 | 30 | Usage: atlassian_drop_db_tables 31 | ``` 32 | * atlassian_fs_backup : Performs a Confluence or JIRA filesystem backup - creates tar.gz of the Installation and Home directories 33 | ``` 34 | 35 | Usage: atlassian_fs_backup [ -c | -j ] 36 | -c --> Backup Confluence filesystem 37 | -j --> Backup JIRA filesystem 38 | ``` 39 | * atlassian_full_backup : Performs a complete Confluence or JIRA backup (both db and filesystem) - this can be run in a cron job or on-demand 40 | ``` 41 | 42 | Usage: atlassian_full_backup [ -c | -j ] 43 | -c --> Backup Confluence 44 | -j --> Backup JIRA 45 | ``` 46 | * atlassian_restore_fs_db : Performs a Confluence or JIRA restoration taking the database and filesystem back-ups as input 47 | ``` 48 | 49 | Usage: atlassian_restore_fs_db [ -c | -j ] -s [PATH-TO-SQLDUMP-FILE] -i [PATH-TO-INSTALLDIR-TAR] -h [PATH-TO-HOMEDIR-TAR] 50 | -c --> Restore a Confluence server 51 | -j --> Restore a JIRA server 52 | -s PATH-TO-SQLDUMP-FILE --> Location of the SQL DUMP file 53 | -i PATH-TO-INSTALLDIR-TAR --> Location of the Installation directory archive 54 | -h PATH-TO-HOMEDIR-TAR --> Location of the Home directory archive 55 | ``` 56 | * atlassian_rotate_tomcat_logs : Handles the expiration of Tomcat's log files since Atlassian doesn't do this - this should be run as a cron job 57 | ``` 58 | 59 | Usage: atlassian_rotate_tomcat_logs [ -c | -j ] 60 | -c --> Rotate Confluence 61 | -j --> Rotate JIRA 62 | 63 | Example: 64 | 0 0 * * * /usr/local/bin/atlassian_rotate_tomcat_logs -c > /usr/local/atlassian/confluence/logs/atlassian_rotate_tomcat_logs.log 2>&1 65 | ``` 66 | -------------------------------------------------------------------------------- /atlassian_db_backup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Creates a MySQL DB backup of the Confluence or JIRA MySQL database 4 | 5 | # Get the database name from $APP's $DBXML_CFG file 6 | # Get the mysql hostname, username, and password from the .my.cnf file 7 | ## NOTE: Due to a bug with the mysql and mysqldump commands, it is problematic to 8 | ## to specify the database name in the .my.cnf file - they share the option 9 | ## --database which means something different to each command. 10 | ## This is why we get the databse name from the $DBXML_CFG file. 11 | 12 | # Must be root to run this script 13 | if [ "`/usr/bin/id -urn`" != "root" ] ; then 14 | echo -e "\nYou must be root to execute this script \n" 15 | exit 1 16 | fi 17 | 18 | # Common directory between Confluence and JIRA 19 | INSTALL_DIR="/usr/local/atlassian" 20 | HOME_DIR="/var/atlassian/application-data" 21 | 22 | USAGE() { 23 | echo -e "\nUsage: `basename $0` [ -c | -j ] [ -s ]" 24 | echo -e "-c --> Backup Confluence MySQL DB" 25 | echo -e "-j --> Backup JIRA MySQL DB" 26 | echo -e "-s --> Indicate this script should run in silent mode\n" 27 | } 28 | 29 | BACKUP_DIR=/atlassianbackup 30 | SILENT=0 31 | APP="null" 32 | DB_NAME="null" 33 | 34 | while getopts ":cjs" OPT ; do 35 | case $OPT in 36 | c) 37 | APP="confluence" 38 | DBXML_CFG="$HOME_DIR/confluence/confluence.cfg.xml" 39 | [ -f $DBXML_CFG ] && DB_NAME=`grep url $DBXML_CFG | grep -o "conf[a-zA-Z]*[0-9]*"` 40 | ENV_FILE="$INSTALL_DIR/confluence/bin/user.sh" 41 | BACKUP_FILE=confluence_sqldump_`date "+%Y%m%d"`_$$.sql 42 | PORT=8090 43 | ;; 44 | j) 45 | APP="jira" 46 | DBXML_CFG="$HOME_DIR/jira/dbconfig.xml" 47 | [ -f $DBXML_CFG ] && DB_NAME=`grep url $DBXML_CFG | grep -o "jira[a-zA-Z]*[0-9]*"` 48 | ENV_FILE="$INSTALL_DIR/jira/bin/user.sh" 49 | BACKUP_FILE=jira_sqldump_`date "+%Y%m%d"`_$$.sql 50 | PORT=8080 51 | ;; 52 | s) 53 | SILENT=1 54 | ;; 55 | \?) 56 | echo -e "\nInvalid option: -$OPTARG" >&2 57 | USAGE 58 | exit 1 59 | ;; 60 | :) 61 | echo -e "\nOption -$OPTARG requires an argument" >&2 62 | USAGE 63 | exit 1 64 | ;; 65 | esac 66 | done 67 | 68 | if [ "$APP" = "null" ] ; then 69 | USAGE 70 | exit 1 71 | elif [ "$DB_NAME" = "null" ] ; then 72 | echo -e "\n$DBXML_CFG does not exist - exiting \n" 73 | exit 1 74 | fi 75 | 76 | # Perform checks to determine if this script can run on this server 77 | if [ -s $ENV_FILE ] ; then 78 | # If script was invoked with the -s flag - skip check if $APP is running 79 | if [ $SILENT -eq 0 ] ; then 80 | # Test to see if $APP is running 81 | if [ "`netstat -nlt | grep $PORT`" != "" ] ; then 82 | echo -e "\n$APP is running!" 83 | echo -e "It is not required, but recommended, that you stop $APP before proceeding with a back-up." 84 | echo -n "Do you want me to stop $APP ? (y/n): " 85 | read ANSWER 86 | 87 | case "$ANSWER" in 88 | y|Y) 89 | echo -e "\nStopping $APP now... \n" 90 | /sbin/service $APP stop 91 | ;; 92 | n|N) 93 | echo -e "\nOK - moving on without stopping $APP \n" 94 | ;; 95 | *) 96 | echo -e "\nDid not understand your answer - exiting \n" 97 | exit 1 98 | ;; 99 | esac 100 | fi 101 | fi 102 | else 103 | echo -e "\nCould not locate a $APP installation on this system \n" 104 | exit 1 105 | fi 106 | 107 | # See https://docs.library.ucla.edu/x/GoA4Bw for details regarding the mysqldump options 108 | echo -e "Starting back-up of the $DB_NAME database" 109 | echo -e "For a large database this can be a lenghtly process" 110 | mysqldump $DB_NAME > $BACKUP_DIR/$BACKUP_FILE 111 | if [ $? -ne 0 ] ; then 112 | echo "mysqldump encountered an error and the back-up failed." 113 | if [ -f $BACKUP_DIR/$BACKUP_FILE ]; then 114 | rm -f $BACKUP_DIR/$BACKUP_FILE 115 | fi 116 | exit 1 117 | fi 118 | echo -e "\nBackup is complete and is available at $BACKUP_DIR/$BACKUP_FILE" 119 | echo -e "If you stopped $APP remember to start it up again \n" 120 | -------------------------------------------------------------------------------- /atlassian_restore_db: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script automates the procedure for restoring Confluence or JIRA database backups 4 | 5 | # Common directories between Confluence and JIRA 6 | HOME_DIR="/var/atlassian/application-data" 7 | INSTALL_DIR="/usr/local/atlassian" 8 | 9 | APP="null" 10 | SQLDUMP_FILE="null" 11 | 12 | # Must be root to run this script 13 | if [ "`/usr/bin/id -urn`" != "root" ] ; then 14 | echo -e "\nYou must be root to execute this script \n" 15 | exit 1 16 | fi 17 | 18 | USAGE() { 19 | echo -e "\nUsage: `basename $0` [ -c | -j ] -s [PATH-TO-SQLDUMP-FILE]" 20 | echo -e "-c --> Restore a Confluence server" 21 | echo -e "-j --> Restore a JIRA server" 22 | echo -e "-s PATH-TO-SQLDUMP-FILE --> Location of the SQL DUMP file" 23 | } 24 | 25 | while getopts ":cjs:" OPT ; do 26 | case $OPT in 27 | c) 28 | APP="confluence" 29 | ENV_FILE="$INSTALL_DIR/confluence/bin/user.sh" 30 | DBXML_CFG="$HOME_DIR/confluence/confluence.cfg.xml" 31 | PORT=8090 32 | ;; 33 | j) 34 | APP="jira" 35 | ENV_FILE="$INSTALL_DIR/jira/bin/user.sh" 36 | DBXML_CFG="$HOME_DIR/jira/dbconfig.xml" 37 | PORT=8080 38 | ;; 39 | s) 40 | SQLDUMP_FILE="$OPTARG" 41 | ;; 42 | \?) 43 | echo -e "\nInvalid option: -$OPTARG" >&2 44 | USAGE 45 | exit 1 46 | ;; 47 | :) 48 | echo -e "\nOption -$OPTARG requires an argument" >&2 49 | USAGE 50 | exit 1 51 | ;; 52 | esac 53 | done 54 | 55 | for VAR in $APP $SQLDUMP_FILE ; do 56 | if [ "$VAR" = "null" ] ; then 57 | USAGE 58 | exit 1 59 | fi 60 | done 61 | 62 | if [ ! -f $DBXML_CFG ] ; then 63 | echo -e "\n$DBXML_CFG does not exist - exiting \n" 64 | exit 1 65 | fi 66 | 67 | # Perform checks to determine if this script can run on this server 68 | # ------------------------------------------------------------------- 69 | 70 | # $ENV_FILE should be accessible - this is indicates if $APP is installed 71 | if [ -s $ENV_FILE ] ; then 72 | # By sourcing $ENV_FILE we import the dedicated $APP user account - should be either confluence or jira 73 | . $ENV_FILE 74 | 75 | # Dedicated $APP user account stored in $CONF_USER or $JIRA_USER 76 | if [ -z "$CONF_USER" -a -z "$JIRA_USER" ] ; then 77 | echo -e "\nA dedicated $APP user account was not found on this system \n" 78 | echo -e "This indicates $APP exists on this system but is not installed properly\n" 79 | exit 1 80 | fi 81 | 82 | # $APP must not be running 83 | if [ "`netstat -nlt | grep $PORT`" != "" ] ; then 84 | echo -e "\n$APP is running" 85 | echo -e "Stop $APP first before running this script \n" 86 | exit 1 87 | fi 88 | else 89 | echo -e "\n$APP does not appear to be installed on this system \n" 90 | echo -e "Ensure a base install of $APP is available before running this script \n" 91 | exit 1 92 | fi 93 | 94 | # Verify the file paths given exist and each file contains data 95 | for FILE in $SQLDUMP_FILE ; do 96 | if [ ! -s $FILE ] ; then 97 | echo -e "\nCould not find file $FILE or $FILE is empty\n" 98 | exit 1 99 | fi 100 | done 101 | 102 | # ------------------------------------------------------------------- 103 | # Checks Complete 104 | 105 | # Begin the restoration procedures 106 | # ------------------------------------------------------------------- 107 | 108 | # Get the database name from $APP's $DBXML_CFG file 109 | # Get the mysql server hostname, username, and password from the .my.cnf file 110 | ## NOTE: Due to a bug with the mysql and mysqldump commands, it is problematic to 111 | ## to specify the database name in the .my.cnf file - they share the option 112 | ## --database which means something different to each command. 113 | ## This is why we get the databse name from the $DBXML_CFG file. 114 | if [ "$APP" = "confluence" ] ; then 115 | DBNAME=`grep url $DBXML_CFG | grep -o "conf[a-zA-Z]*[0-9]*"` 116 | elif [ "$APP" = "jira" ] ; then 117 | DBNAME=`grep url $DBXML_CFG | grep -o "jira[a-zA-Z]*[0-9]*"` 118 | else 119 | echo -e "\n Unable to determine database name from configuration files \n" 120 | exit 1 121 | fi 122 | 123 | # Before restoring the database, we will drop all existing tables to ensure a clean start 124 | echo -e "\nDropping all tables from $DBNAME - if this is correct press Enter - otherwise CTRL-C" 125 | read 126 | /usr/local/bin/atlassian/atlassian_drop_db_tables $DBNAME 127 | 128 | # Restore the MySQL dump file to the $APP database 129 | echo -e "\nRestoring $SQLDUMP_FILE to the $DBNAME database" 130 | echo -e "This can be a lengthy process - please be patient \n" 131 | mysql $DBNAME < $SQLDUMP_FILE 132 | if [ $? -ne 0 ] ; then 133 | echo -e "\nThere was a problem restoring the MySQL backup\n" 134 | exit 1 135 | fi 136 | 137 | echo -e "\nRestoration of the $DBNAME database is complete." 138 | -------------------------------------------------------------------------------- /atlassian_restore_fs_db: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script automates the procedure for restoring Confluence or JIRA filesystem and database backups 4 | 5 | # Common directories between Confluence and JIRA 6 | HOME_DIR="/var/atlassian/application-data" 7 | INSTALL_DIR="/usr/local/atlassian" 8 | 9 | APP="null" 10 | SQLDUMP_FILE="null" 11 | INSTALLDIR_TAR="null" 12 | HOMEDIR_TAR="null" 13 | 14 | # Must be root to run this script 15 | if [ "`/usr/bin/id -urn`" != "root" ] ; then 16 | echo -e "\nYou must be root to execute this script \n" 17 | exit 1 18 | fi 19 | 20 | USAGE() { 21 | echo -e "\nUsage: `basename $0` [ -c | -j ] -s [PATH-TO-SQLDUMP-FILE] -i [PATH-TO-INSTALLDIR-TAR] -h [PATH-TO-HOMEDIR-TAR]" 22 | echo -e "-c --> Restore a Confluence server" 23 | echo -e "-j --> Restore a JIRA server" 24 | echo -e "-s PATH-TO-SQLDUMP-FILE --> Location of the SQL DUMP file" 25 | echo -e "-i PATH-TO-INSTALLDIR-TAR --> Location of the Installation directory archive" 26 | echo -e "-h PATH-TO-HOMEDIR-TAR --> Location of the Home directory archive \n" 27 | } 28 | 29 | while getopts ":cjs:i:h:" OPT ; do 30 | case $OPT in 31 | c) 32 | APP="confluence" 33 | ENV_FILE="$INSTALL_DIR/confluence/bin/user.sh" 34 | DBXML_CFG="$HOME_DIR/confluence/confluence.cfg.xml" 35 | PORT=8090 36 | ;; 37 | j) 38 | APP="jira" 39 | ENV_FILE="$INSTALL_DIR/jira/bin/user.sh" 40 | DBXML_CFG="$HOME_DIR/jira/dbconfig.xml" 41 | PORT=8080 42 | ;; 43 | s) 44 | SQLDUMP_FILE="$OPTARG" 45 | ;; 46 | i) 47 | INSTALLDIR_TAR="$OPTARG" 48 | ;; 49 | h) 50 | HOMEDIR_TAR="$OPTARG" 51 | ;; 52 | \?) 53 | echo -e "\nInvalid option: -$OPTARG" >&2 54 | USAGE 55 | exit 1 56 | ;; 57 | :) 58 | echo -e "\nOption -$OPTARG requires an argument" >&2 59 | USAGE 60 | exit 1 61 | ;; 62 | esac 63 | done 64 | 65 | for VAR in $APP $SQLDUMP_FILE $INSTALLDIR_TAR $HOMEDIR_TAR ; do 66 | if [ "$VAR" = "null" ] ; then 67 | USAGE 68 | exit 1 69 | fi 70 | done 71 | 72 | # Perform checks to determine if this script can run on this server 73 | # ------------------------------------------------------------------- 74 | 75 | # $ENV_FILE should be accessible - this is indicates if $APP is installed 76 | if [ -s $ENV_FILE ] ; then 77 | # By sourcing $ENV_FILE we import the dedicated $APP user account - should be either confluence or jira 78 | . $ENV_FILE 79 | 80 | # Dedicated $APP user account stored in $CONF_USER or $JIRA_USER 81 | if [ -z "$CONF_USER" -a -z "$JIRA_USER" ] ; then 82 | echo -e "\nA dedicated $APP user account was not found on this system \n" 83 | echo -e "This indicates $APP exists on this system but is not installed properly\n" 84 | exit 1 85 | fi 86 | 87 | # $APP must not be running 88 | if [ "`netstat -nlt | grep $PORT`" != "" ] ; then 89 | echo -e "\n$APP is running" 90 | echo -e "Stop $APP first before running this script \n" 91 | exit 1 92 | fi 93 | else 94 | echo -e "\n$APP does not appear to be installed on this system \n" 95 | echo -e "Ensure a base install of $APP is available before running this script \n" 96 | exit 1 97 | fi 98 | 99 | # Verify the file paths given exist and each file contains data 100 | for FILE in $SQLDUMP_FILE $INSTALLDIR_TAR $HOMEDIR_TAR ; do 101 | if [ ! -s $FILE ] ; then 102 | echo -e "\nCould not find file $FILE or $FILE is empty\n" 103 | exit 1 104 | fi 105 | done 106 | 107 | # ------------------------------------------------------------------- 108 | # Checks Complete 109 | 110 | # Begin the restoration procedures 111 | # ------------------------------------------------------------------- 112 | 113 | # If necessary remove the existing $APP installation and home directories 114 | # This ensures a clean environment for the extraction of the tar files 115 | [ -d $INSTALL_DIR/$APP ] && rm -rf $INSTALL_DIR/$APP 116 | [ -d $HOME_DIR/$APP ] && rm -rf $HOME_DIR/$APP 117 | 118 | # Untar the archive files of the Install and Home directories 119 | echo -e "\nUnpacking the $APP Installation directory \n" 120 | tar xzf $INSTALLDIR_TAR -C $INSTALL_DIR 121 | echo -e "Unpacking the $APP Home directory \n" 122 | tar xzf $HOMEDIR_TAR -C $HOME_DIR 123 | 124 | # Get the database name from $APP's $DBXML_CFG file 125 | # Get the mysql server hostname, username, and password from the .my.cnf file 126 | ## NOTE: Due to a bug with the mysql and mysqldump commands, it is problematic to 127 | ## to specify the database name in the .my.cnf file - they share the option 128 | ## --database which means something different to each command. 129 | ## This is why we get the databse name from the $DBXML_CFG file. 130 | if [ "$APP" = "confluence" ] ; then 131 | DBNAME=`grep url $DBXML_CFG | grep -o "conf[a-zA-Z]*[0-9]*"` 132 | elif [ "$APP" = "jira" ] ; then 133 | DBNAME=`grep url $DBXML_CFG | grep -o "jira[a-zA-Z]*[0-9]*"` 134 | else 135 | echo -e "\n Unable to determine database name from configuration files \n" 136 | exit 1 137 | fi 138 | 139 | # Before restoring the database, we will drop all existing tables to ensure a clean start 140 | echo -e "\nDropping all tables from $DBNAME - if this is correct press Enter - otherwise CTRL-C" 141 | read 142 | /usr/local/bin/atlassian/atlassian_drop_db_tables $DBNAME 143 | 144 | # Restore the MySQL dump file to the $APP database 145 | echo -e "\nRestoring $SQLDUMP_FILE to the $DBNAME database" 146 | echo -e "This can be a lengthy process - please be patient \n" 147 | mysql $DBNAME < $SQLDUMP_FILE 148 | if [ $? -ne 0 ] ; then 149 | echo -e "\nThere was a problem restoring the MySQL backup\n" 150 | exit 1 151 | fi 152 | 153 | echo -e "\nRestoration of the $APP server is complete." 154 | 155 | echo -e "\nThe archive files you specified on the cmd line are still on this server taking up space" 156 | echo -e "If you no longer need them you should delete them \n" 157 | -------------------------------------------------------------------------------- /atlassian_create_test_server: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script automates the procedure for creating a Test server for Confluence or JIRA 4 | 5 | # Common directories between Confluence or JIRA 6 | HOME_DIR="/var/atlassian/application-data" 7 | INSTALL_DIR="/usr/local/atlassian" 8 | 9 | APP="null" 10 | DB_HOST="null" 11 | CFGXML_FILE="null" 12 | SQLDUMP_FILE="null" 13 | INSTALLDIR_TAR="null" 14 | HOMEDIR_TAR="null" 15 | 16 | # Must be root to run this script 17 | if [ "`/usr/bin/id -urn`" != "root" ] ; then 18 | echo -e "\nYou must be root to execute this script \n" 19 | exit 1 20 | fi 21 | 22 | USAGE() { 23 | echo -e "\nUsage: `basename $0` [ -c | -j ] -d [DATABASE-HOSTNAME] -x [PATH-TO-CFGXML-FILE] -s [PATH-TO-SQLDUMP-FILE] -i [PATH-TO-INSTALLDIR-TAR] -h [PATH-TO-HOMEDIR-TAR]" 24 | echo -e "-c --> Create a Confluence test server" 25 | echo -e "-j --> Create a JIRA test server" 26 | echo -e "-d DATABASE-HOSTNAME --> Hostname of MySQL Database server" 27 | echo -e "-x PATH-TO-CFGXML-FILE --> Location of xml file with connection information to the Confluence/JIRA Test database" 28 | echo -e "-s PATH-TO-SQLDUMP-FILE --> Location of the Production SQL DUMP file" 29 | echo -e "-i PATH-TO-INSTALLDIR-TAR --> Location of the Production Installation directory archive" 30 | echo -e "-h PATH-TO-HOMEDIR-TAR --> Location of the Production Home directory archive \n" 31 | } 32 | 33 | while getopts ":cjd:x:s:i:h:" OPT ; do 34 | case $OPT in 35 | c) 36 | APP="confluence" 37 | APP_LINK="jira" 38 | CFG_DIR="$INSTALL_DIR/confluence/conf" 39 | ENV_FILE="$INSTALL_DIR/confluence/bin/user.sh" 40 | DBXML_FILE="$HOME_DIR/confluence/confluence.cfg.xml" 41 | SRVXML_FILE="$CFG_DIR/server.xml" 42 | PORT=8090 43 | BASE_URL="docs" 44 | ;; 45 | j) 46 | APP="jira" 47 | APP_LINK="docs" 48 | CFG_DIR="$INSTALL_DIR/jira/conf" 49 | ENV_FILE="$INSTALL_DIR/jira/bin/user.sh" 50 | DBXML_FILE="$HOME_DIR/jira/dbconfig.xml" 51 | SRVXML_FILE="$CFG_DIR/server.xml" 52 | PORT=8080 53 | BASE_URL="jira" 54 | ;; 55 | d) 56 | DB_HOST="$OPTARG" 57 | ;; 58 | x) 59 | CFGXML_FILE="$OPTARG" 60 | ;; 61 | s) 62 | SQLDUMP_FILE="$OPTARG" 63 | ;; 64 | i) 65 | INSTALLDIR_TAR="$OPTARG" 66 | ;; 67 | h) 68 | HOMEDIR_TAR="$OPTARG" 69 | ;; 70 | \?) 71 | echo -e "\nInvalid option: -$OPTARG" >&2 72 | USAGE 73 | exit 1 74 | ;; 75 | :) 76 | echo -e "\nOption -$OPTARG requires an argument" >&2 77 | USAGE 78 | exit 1 79 | ;; 80 | esac 81 | done 82 | 83 | for VAR in $APP $DB_HOST $CFGXML_FILE $SQLDUMP_FILE $INSTALLDIR_TAR $HOMEDIR_TAR ; do 84 | if [ "$VAR" = "null" ] ; then 85 | USAGE 86 | exit 1 87 | fi 88 | done 89 | 90 | # Perform checks to determine if this script can run on this server 91 | # ------------------------------------------------------------------- 92 | 93 | # Determine if this script can be run on this system 94 | if [ -s $ENV_FILE ] ; then 95 | # By sourcing $ENV_FILE we import the dedicated $APP user account - should be confluence or jira 96 | . $ENV_FILE 97 | 98 | # Dedicated $APP user account stored in $CONF_USER or $JIRA_USER 99 | if [ -n "$CONF_USER" ] ; then 100 | DED_USER=$CONF_USER 101 | elif [ -n "$JIRA_USER" ] ; then 102 | DED_USER=$JIRA_USER 103 | else 104 | echo -e "\nA dedicated $APP user account was not found on this system" 105 | echo -e "This indicates $APP exists on this system but is not installed properly\n" 106 | exit 1 107 | fi 108 | 109 | # $APP must not be running 110 | if [ "`netstat -nlt | grep $PORT`" != "" ] ; then 111 | echo -e "\n$APP is running" 112 | echo -e "Stop $APP first before running this script \n" 113 | exit 1 114 | fi 115 | else 116 | echo -e "\n$APP does not appear to be installed on this system \n" 117 | echo -e "Ensure a base install of $APP is available before running this script \n" 118 | exit 1 119 | fi 120 | 121 | # Verify the file paths given exist and each file contains data 122 | for FILE in $CFGXML_FILE $SQLDUMP_FILE $INSTALLDIR_TAR $HOMEDIR_TAR ; do 123 | if [ ! -s $FILE ] ; then 124 | echo -e "\nCould not find file $FILE or $FILE is empty\n" 125 | exit 1 126 | fi 127 | done 128 | 129 | # ------------------------------------------------------------------- 130 | # Checks Complete 131 | 132 | # Begin the creation of the Test $APP Server 133 | # ------------------------------------------------------------------- 134 | 135 | # In the SQL Dump file, the base URL is still set to the Production $APP URL 136 | # Change this to be the TEST $APP URL 137 | echo -e "\nSetting the base URL to ${BASE_URL}-test.libary.ucla.edu" 138 | sed -i "s/${BASE_URL}.library.ucla.edu/${BASE_URL}-test.library.ucla.edu/g" $SQLDUMP_FILE 139 | 140 | # Need to change the base URL for any External Gadget Links and the Applicaiton Links 141 | # These will still be pointing to Production $APP and need change to TEST $APP_LINK 142 | # This also points Service Desk to the correct Confluence KB URL if $APP = jira 143 | echo -e "\nSetting the Application Link base URL to ${APP_LINK}-test.libary.ucla.edu" 144 | sed -i "s/${APP_LINK}.library.ucla.edu/${APP_LINK}-test.library.ucla.edu/g" $SQLDUMP_FILE 145 | 146 | # If necessary remove the existing $APP installation and home directories 147 | # This ensures a clean environment for the extraction of the tar files 148 | [ -d $INSTALL_DIR/$APP ] && rm -rf $INSTALL_DIR/$APP 149 | [ -d $HOME_DIR/$APP ] && rm -rf $HOME_DIR/$APP 150 | 151 | # Untar the archive files of the Install and Home directories 152 | echo -e "\nUnpacking the $APP Installation directory \n" 153 | tar xzf $INSTALLDIR_TAR -C $INSTALL_DIR 154 | echo -e "Unpacking the $APP Home directory \n" 155 | tar xzf $HOMEDIR_TAR -C $HOME_DIR 156 | 157 | # The server.xml file still contains the proxyName of the Production $APP URL 158 | # Change this to be the Test $APP URL 159 | echo -e "\nSetting the proxyName to ${BASE_URL}-test.library.ucla.edu \n" 160 | sed -i "s/${BASE_URL}.library.ucla.edu/${BASE_URL}-test.library.ucla.edu/g" $SRVXML_FILE 161 | 162 | # Restore the back-up file containing the Test database connection information 163 | echo -e "\nInserting the Test database connection information \n" 164 | rm -f $DBXML_FILE 165 | cp -p $CFGXML_FILE $DBXML_FILE 166 | chown ${DED_USER}:${DED_USER} $DBXML_FILE 167 | chmod 644 $DBXML_FILE 168 | 169 | # Determine the database name and user account from $APP's $DBXML_FILE 170 | if [ "$APP" = "confluence" ] ; then 171 | DBUSER=`grep username $DBXML_FILE | grep -o "conf[a-zA-Z]*[0-9]*"` 172 | DBNAME=`grep url $DBXML_FILE | grep -o "conf[a-zA-Z]*[0-9]*"` 173 | elif [ "$APP" = "jira" ] ; then 174 | DBUSER=`grep username $DBXML_FILE | grep -o "jira[a-zA-Z]*[0-9]*"` 175 | DBNAME=`grep url $DBXML_FILE | grep -o "jira[a-zA-Z]*[0-9]*"` 176 | else 177 | echo -e "\nCould not determine database name and/or user account information \n" 178 | exit 1 179 | fi 180 | 181 | # Before restoring the database, we will drop all existing tables to ensure a clean start 182 | echo -e "\nDropping all tables from $DBNAME - if this is correct press Enter - otherwise CTRL-C" 183 | read 184 | /usr/local/bin/atlassian/atlassian_drop_db_tables $DBNAME 185 | 186 | # Restore the MySQL dump file to the $APP Test database 187 | echo -e "\nRestoring $SQLDUMP_FILE to the $DBNAME database" 188 | echo -e "This can be a lengthy process - please be patient \n" 189 | mysql -h $DB_HOST -u $DBUSER $DBNAME < $SQLDUMP_FILE 190 | if [ $? -ne 0 ] ; then 191 | echo -e "\nThere was a problem restoring the SQL dump file to the $DBNAME database. \n" 192 | exit 1 193 | fi 194 | 195 | if [ "$APP" = "confluence" ] ; then 196 | echo -e "\nThe $APP Test server is now ready." 197 | echo -e "Start the $APP process and access the URL http://${BASE_URL}-test.library.ucla.edu in your browser \n" 198 | 199 | echo -e "Some things you will need to do manually in the $APP GUI: \n" 200 | echo -e "1. Change the Outgoing Mail Server to a fake name so $APP does not attempt to send out notificaitons \n" 201 | echo -e "2. Install the developer $APP license - you'll need to obtain this from the atlassian account website \n" 202 | elif [ "$APP" = "jira" ] ; then 203 | echo -e "\nThe $APP Test server is now ready." 204 | echo -e "Disable Mail so $APP does not attempt to send out notificaitons - do this in the setenv.sh file \n" 205 | echo -e "Start the $APP process and access the URL http://${BASE_URL}-test.library.ucla.edu in your browsers \n" 206 | 207 | echo -e "Some things you will need to do manually in the $APP GUI: \n" 208 | echo -e "1. Install the JIRA Core developer license - you'll need to obtain this from the my.atlassian.com portal \n" 209 | echo -e "2. Install the JIRA Service Desk developer license - you'll need to obtain this from the my.atlassian.com portal \n" 210 | echo -e "3. Change the Incoming Mail server settings to use the lib_atlassiantest mailbox \n" 211 | echo -e "4. Change the Outgoing Mail server settings to use localhost \n" 212 | echo -e "5. Disable Service Desk notifications \n" 213 | echo -e "6. Disable email requests for all Service Desk portals \n" 214 | echo -e "7. Stop $APP and re-enable mail in the setenv.sh file \n" 215 | else 216 | echo -e "\nThe $APP Test server is now ready." 217 | fi 218 | 219 | echo -e "\nThe archive files you specified on the cmd line are still on this server taking up space" 220 | echo -e "If you no longer need them you should delete them \n" 221 | --------------------------------------------------------------------------------