Automatically backing up JIRA DB (Postgres)

The below shell script can be run frequently to backup JIRA DB (Postgres) at any frequency. The script in this case is being executed on the DB Server and then the DB backups are pushed to an external server to prevent from a server crash.

#!/bin/bash

#----------------
# Configuration
# ---------------
backupDir="/var/jira/data/usr_backups/data/"
logDir="/var/jira/data/usr_backups/script/log/"
curDate=`date +%Y%m%d_%H%M`
fileName="jiradb_backup_"$curDate".sql.gz"
echo $backupDir$fileName

logMsg=''

#----------------
# DB Backup
#----------------
pg_dump -Fp -h localhost -U jira -w jiradb | gzip > $backupDir$fileName

if [ -e $backupDir$fileName ]
then
  echo "backup successful"
  logMsg="jiradb backed up successfully"
else
  echo "backup failed"
  logMsg="Error backing up jiradb"
fi

echo $logMsg > $logDir"log_"$curDate".log"

#----------------
# File Transfer
#----------------
sftp remoteserver.domain.com:/var/dbbackup/jira <<EOM
put $backupDir$fileName
EOM
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s