BackupRT

From Request Tracker Wiki
Revision as of 16:03, 6 April 2016 by Admin (talk | contribs) (2 revisions imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Introduction

The following script was written to provide a quick way to run a backup of the Request Tracker application installation. This is a good tool to use if you're hacking at templates and objects to ensure that you have a known good restore point.

Requirements

I wrote this for Debain Sarge/Stable and it depends on having the exim4 mailer installed. I also requires that there is a ''tmp'' dir in ''/root''. You can of course change this to whatever directory that you wish. I'll be refining this script as time permits.

Caveat Emptor

This script is provided with no warranties expressed or implied. Use your own risk. Milage may vary.

TODO

  • Add section to detect mailer and automatically set this envvar
  • Add automatic tmpfile cleanup
#!/bin/bash
 #
 # backupRT.sh
 #
 # $Author: www-data $
 # $Revision: 1.5 $
 # $Id: backupRT,v 1.5 2006/04/10 15:55:01 www-data Exp $
 #
 # Runs a file level backup of the contents of the following
 # directories:
 #
 # /usr/local/share/request-tracker3.4
 # /usr/share/request-tracker3.4
 #
 # Into a file named rtappbak-{date}.tar.gz
 #
 
 #
 # Implementation Specific Variables
 #
 # You can change this to another directory for the tmp files.
 # I don't like to dump in /tmp
 
 SCRTMPDIR=/root/tmp/
 MAILHEADER=$SCRTMPDIRrtbakfiles-mail
 rtbakWATCHER=###YOUREMAILADDRESSHERE###
 MAILSERVER=###YOUREMAILSERVERHOSTNAME###
 
 #
 # Script Variables
 #
 curday=`date +"%Y%m%d%H%M%S"`
 prefn="rtappbak-"
 backdir=/var/backups/rt/
 fullfn=$backdir$prefn$curday.tgz
 rtbakCHANGES_FILE=/root/tmp/rtbakfiles
 HOSTNAME=`/bin/hostname`
 FQDN=`/bin/hostname -f`
 fullFILENAME=`pwd`$fullfn
 
 #
 # Make/Verify target dirs
 #
 if [ ! -d $backdir ]; then
   mkdir $backdir;
 fi
 
 if [ ! -d $SCRTMPDIR ]; then
   mkdir $SCRTMPDIR;
 fi
 
 # do the backup
 tar cvzf $fullfn /usr/local/share/request-tracker3.4 /usr/share/request-tracker3.4 /etc/request-tracker3.4
 
 #get the file list and send to $rtbakCHANGES_FILE
 tar tvzf $fullfn > $rtbakCHANGES_FILE
 
 #create message file and send to watcher
 if [ -s $CHANGES_FILE ] ; then
   echo HELO $MAILSERVER > $MAILHEADER
   echo MAIL FROM:root@$FQDN  >> $MAILHEADER
   echo RCPT TO:$rtbakWATCHER >> $MAILHEADER
   echo DATA >> $MAILHEADER
   echo Subject: $HOSTNAME RT Application Backup >> $MAILHEADER
   echo Backup of files from the RT install on ${HOSTNAME}: >> $MAILHEADER
   echo This file is located at: >> $MAILHEADER
   echo ${HOSTNAME}:$fullFILENAME >> $MAILHEADER
   echo >> $MAILHEADER
   cat $rtbakCHANGES_FILE >> $MAILHEADER
   echo . >> $MAILHEADER
   echo QUIT >> $MAILHEADER
   exim4 -bs < $MAILHEADER
 fi
 
 

Rev 40 Notes: Cleaned up variable declarations and added target directory checking/creation.

MichaelErana g33k (at) efamilynj.org