Confluence Simple Backup Script

Hello everybody,

Long time ago I wrote a backup script for confluence, and i would like to share it with you.

the script will take a backup for PostgreSQL, Confluence Home and Confluence application it self. Actually there is no need to take a a backup for confluence application, but you never know when it comes in handy, and confluence app size is negligible.

You will ask your self why do we need it if you can enable backup from confluence. The issue is that Confluence internal backup mechanism has a limitation regarding the size of confluence home which it up to 2GB as i remember, and it doesn’t take a backup for the database, so if any thing happened your confluence is screwed :).

The script that I will include:

1.  It takes a full backup on daily bases and keep the latest three backups at any given time.

2. Takes PostgreSQL database backup on daily bases and include it in the archive file

3. It will log the result to syslog , notify root by sending email to local spooler, and send notification email to concerned party

Our saviour script will lock like this :

#!/bin/bash

DATE=`date +"%d%m%y"`
BK_PATH=/opt/backups
CONFLUENCE=/opt/confluence-3.5.3-std
CONFLUENCE_HOME=/opt/confluence-home
find $BK_PATH -mtime 3 -exec rm -f {} ;

if [ -f $BK_PATH/confluence-back-$DATE.tar.bz2 ]
     then
        echo " it is already backed up"
        exit 1
fi 

if [ -f  $BK_PATH/confluence-db.out ]
     then
        rm $BK_PATH/confluence-db.out
fi

su - postgres -c ' pg_dump -Cf /opt/confluence-backup/confluence-db.out databasename -i'

tar cjf  $BK_PATH/confluence-back-$DATE.tar.bz2 --exclude "$CONFLUENCE_HOME/backups" --exclude "$CONFLUENCE_HOME/restore" $CONFLUENCE $CONFLUENCE_HOME $BK_PATH/confluence-db.out
tar tjf $BK_PATH/confluence-back-$DATE.tar.bz2
if [ $? -eq 0 ]
    then
        logger -i -t confluence-backup "confluence backup has been taken successfuly in `date +"%d-%m-%y"`"
        echo "confluence backup was taken successfuly in `date +"%d-%m-%y"` "|mail -s "confluence backup" root -c xxx@xxx.xxx
    else
        logger -i -t confluence-backup "confluence backup finished with some errors"
         echo "confluence backup finished with some errors"|mail -s "confluence backup" root -c xxx@xxx.xxx
    fi

Notes :

 

If your PostgreSQL database has a Password there is a work around in order to make the backup non interactive, to do this do the following

1. create a file called .pgpass under PostgreSQL home

2. change the the permission of the file to 600

3. Change the ownership of file to PostgreSQL user if it is not owned by him

4. Set PGPASSFILE environment variable to point to file location 

4. edit the file and add the following inside but don’t forget to replace the […] with your own values

[host to connect from]:[database port]:[data base name]:[database use]:[database password]

 

 

Posted in Database, Shell Scripting, System Administartion and tagged , , , , , , , , . Bookmark the permalink. RSS feed for this post. Leave a trackback.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

Swedish Greys - a WordPress theme from Nordic Themepark.