BackupRTDB

From Request Tracker Wiki
Revision as of 15:10, 22 November 2010 by Best Practical (talk) (1 revision: Import (1/2) from Kwiki on wiki.bestpractical.com)
Jump to navigation Jump to search

Introduction

The following script was written to provide a quick way to run a backup of the Request Tracker database. This is a good tool for routine daily backups and can be run as part of the daily cron batch.

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. It also assumes that ''root'' (or what ever account the cron job will run as) will have DB access rights to the RT Database.

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 # <h1>backupRTDB.sh</h1> # <h1>$Author: www-data $</h1> <h1>$Revision: 1.3 $</h1> <h1>$Id: backupRTDB,v 1.3 2006/04/10 15:48:21 www-data Exp $</h1> # <h1>Runs a mysqldump backup of the contents of the</h1> <h1>RT Database.</h1> # <h1>Into files named rtdb-main-{date}.tar.gz</h1> <h1>rtdb-attach-{date}.tar.gz</h1> # <h1>This script assumes that root can login to mysql locally</h1> <h1>without a password. If you change this then you will need to revise</h1> <h1>the connection strings.</h1> # # <h1>Implementation Specific Variables</h1> # <h1>You can change this to another directory for the tmp files.</h1> <h1>I don't like to dump in /tmp</h1> SCRTMPDIR=/root/tmp/ MAILHEADER=$SCRTMPDIRrtbakfiles-mail rtDB=###YOURRTDATABASENAME### rtbakWATCHER=###YOUREMAIL### MAILSERVER=###YOUREMAILSERVER### rtUSER=###YOURRTUSERNAME### # <h1>Script Variables</h1> # curday=<code>date +"%Y%m%d%H%M%S"</code> backdir=/var/backups/rt/ mainprefn="rtdb-main-" attachprefn="rtdb-attach-" mainfullfn=$backdir$mainprefn$curday.gz attachfullfn=$backdir$attachprefn$curday.gz rtdbbakCHANGES_FILE=$SCRTMPDIRrtbakfiles HOSTNAME=<code>/bin/hostname</code> FQDN=<code>/bin/hostname -f</code> rtMainTables="ACL Attributes CachedGroupMembers CustomFieldValues CustomFields GroupMembers \ Groups Links ObjectCustomFieldValues ObjectCustomFields Principals Queues ScripActions \ ScripConditions Scrips Templates Tickets Transactions Users sessions" # <h1>Make/Verify target dirs</h1> # if [ ! -d $backdir ]; then mkdir $backdir; fi if [ ! -d $SCRTMPDIR ]; then mkdir $SCRTMPDIR; fi <h1>do the Main backup</h1> mysqldump $rtDB --opt $rtMainTables | gzip > $mainfullfn <h1>do the Attachment backup</h1> mysqldump $rtDB --opt --default-character-set=binary Attachments | gzip > $attachfullfn <h1>create message file and send to watcher</h1> 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 - $curday - RT Database backup >> $MAILHEADER echo Backup of files from the RT install on ${HOSTNAME}: >> $MAILHEADER echo This file is located at: >> $MAILHEADER echo ${HOSTNAME}:$mainfullfn >> $MAILHEADER echo >> $MAILHEADER echo . >> $MAILHEADER echo QUIT >> $MAILHEADER exim4 -bs < $MAILHEADER fi

MichaelErana g33k (at) efamilynj.org