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 firstname.lastname@example.org 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:
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 But I can’t consider that we’re really backed up 'til I test this.
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"
- Any restore script should take into account the update-log files, and reload them after restoring the backed-up database.
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!)
MYSQL_OPTS="-urt_user -prt_password -h rt_host RT_DB_NAME"
case $* in
# Restore db
mysql $MYSQL_OPTS < /backups/$RESTORE_DATE/database
# Restore rt cd $RT_PATH gunzip -c /backups/$RESTORE_DATE/rt.tar.gz | tar xf - ;;
# 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)"