More on RT Backup procedures

Folks:

A while back, I asked if anyone had created a script that would back up RT’s SQL database and its (source) files. Darren Chamberlain darren@boston.com graciously responded with the script below.

I’m reposting it because there was a typo that hung me up for a while. (The ‘tar cf …’ was initially set to tar up $PATH, instead of $RT_PATH.) I have corrected this in the script below.

I also wanted to add these notes:

  1. I have not tested this script either. I am using an adaptation of these techniques for my own backups. (And I haven’t worked up my nerve to try reloading the database yet :slight_smile: But I can’t consider that we’re really backed up 'til I test this.

  2. In my own script, I added certain options to the MYSQL_OPTS variable to lock the database and flush the update log files during the dump to ensure a consistent backup.

MYSQL_OPTS=“-urt_user -prt_password --flush-logs --lock-tables --opt -h rt_host RT_DB_NAME”

  1. Any restore script should take into account the update-log files, and reload them after restoring the backed-up database.

Take care!

Rich Brown
Hanover, NH USA

===== On 8 March 2002, Darren Chamberlain wrote =====

You could do this with a short shell script (Warning! This is

untested! I just threw this together right now!)

#!/bin/sh

DATE=date +"%Y-%m-%d"
RT_PATH=/path/to/rt
MYSQL_OPTS=“-urt_user -prt_password -h rt_host RT_DB_NAME”

case $* in
restore)
shift
RESTORE_DATE=$1
# Restore db
mysql $MYSQL_OPTS < /backups/$RESTORE_DATE/database

# Restore rt
cd $RT_PATH
gunzip -c /backups/$RESTORE_DATE/rt.tar.gz | tar xf -

;;

save)
# Assumes that /backups exists, of course
if ! test -d /backups/$DATE; then mkdir /backups/$DATE; fi

# Backup db and RT dir
mysqldump $MYSQL_OPTS > /backups/$DATE/database

tar cf /backups/$DATE/rt.tar $RT_PATH
gzip --best /backups/$DATE/rt.tar

;;

*)
echo “Usage: $0 (save|restore)”
exit 1
;;
esac

exit 0