This article describes the way to make a Disaster Recovery Site of a Confluence Installation

Assumptions taken below

WhatWhere
Confluence Installation Directory/opt/confluence
Confluence Home Directory

/opt/confluence-data

MySQL BackupSetup and working, backing up to /backup/mysqlbackup/
Disaster Recovery (Stand by) Server DNS name

drserver.site.dk

rsync between serversSetup and working via SSH keys

 

rsyncing MySQL, Confluence Installation and Confluence Home Files

The MySQL backup of the Confluence database and the files of the installation must be syncronised to the alternate server (called drserver.site.dk)

This should be run with cron in regular intervals

#!/bin/bash
rsync -avz /backup/mysqlbackup/confluence.sql.gz drserver.site.dk:/mysqlbackup/ >/dev/null
rsync -avz /opt/confluence-data --exclude *.log drserver.site.dk:/opt/
rsync -avz /opt/confluence --exclude catalina.out drserver.site.dk:/opt/

 

Scripts and files

Script for dropping and creating a new database

/scripts/CreateConfluenceDatabase.sql
drop database confluence;
create database confluence CHARACTER SET utf8 COLLATE utf8_bin;
grant all privileges on confluence.* to confluence@localhost identified by 'confconf';
flush privileges;

 

Why change the server.xml and setenv.sh

Due to the fact this (problably) is a DR site, some facts can be:

  • The HW specs are lower
  • The URL (and hence Base URL) are different

So we want to change the server.xml and setenv.sh to reflect those changes, otherwise the system may never start correctly.

So, make a copy of :

scp /opt/confluence/conf/server.xml drsite.server.dk:/scripts/server.xml.confluence
scp /opt/confluence/bin/setenv.sh drsite.server.dk:/scripts/setenv.sh.confluence

Now, change the files as needed.

 

Restore Confluence script

This is the script that restores the Confluence on the DR server drserver.site.dk - It needs the files from above to work.

#!/bin/bash

if [ `id | grep "uid=0(root)" | wc -l` -lt 1 ]
then
	echo "must be executed as root"
	exit 1
fi


if [ -f /mysqlbackup/confluence.sql ]
then
	rm /mysqlbackup/confluence.sql
fi


echo "Unpacking Confluence database backup"
gunzip -c /mysqlbackup/confluence.sql.gz > /mysqlbackup/confluence.sql
 
echo "Dropping and Creating Confluence and JIRA databases"
mysql -uroot -password < /scripts/CreateConfluenceDatabase.sql


echo "Importing Confluence database backup into MySQL - This takes a while..."
mysql -uroot -password < /mysqlbackup/confluence.sql


if [ $? -eq 0 ]
then
	echo "Import finished ok"
else
	echo "mysql client ended with exit code different from 0. Stopping script"
	exit 1
fi

echo "Copying server.xml and setenv.sh to Confluence configuration"
cp /scripts/server.xml.confluence /opt/confluence/conf/server.xml
cp /scripts/setenv.sh.confluence /opt/confluence/bin/setenv.sh
rm /opt/confluence/logs/catalina.out

echo "Ready for Starting Confluence for http://drserver.site.dk"
echo "Start with: /opt/confluence/bin/startup.sh;tail -f /opt/confluence/logs/catalina.out"