Skip to content

Instantly share code, notes, and snippets.

@tuxity
Created June 12, 2012 10:12
Show Gist options
  • Save tuxity/2916731 to your computer and use it in GitHub Desktop.
Save tuxity/2916731 to your computer and use it in GitHub Desktop.
Save WoW databases
#!/bin/bash
# TODO:
# - Handle antifreeze detection
# - Handle transfer of backup on external server
####################### CONFIG #######################
MYSQLHOST="127.0.0.1"
MYSQLUSER="root"
MYSQLPASS=""
MYSQLDBAUTH="auth"
MYSQLDBCHAR="characters"
SAVEPATH="/home/backup_sql"
RAENABLE="1"
RAHOST="127.0.0.1"
RAPORT="3443"
RAUSER=""
RAPASS=""
RATIMEOUT="5"
ANNONCE1="Début de la sauvegarde des bases de données du serveur ... "
ANNONCE2="Des lags/crash peuvent survenir mais vos personnages vont etre sauvegardé en cas de problème durant la sauvegarde."
ANNONCE3="La sauvegarde des bases de données du serveur est maintenant terminée. Bon jeu sur Earthquake !"
#####################################################
# Send announce to world and save all characters
if [ $RAENABLE = "1" ]
then
expect << EOF
set timeout $RATIMEOUT
spawn telnet $RAHOST $RAPORT
expect “Username:“
send “$RAUSER\r”
expect “Password:“
send “$RAPASS\r”
expect “TC>”
send “announce $ANNONCE1\r”
send “announce $ANNONCE2\r”
send "saveall"
send “exit”
EOF
# Use a little sleep to let time to server to save characters
sleep 2
fi
# Create directory if not exist
[ ! -d $SAVEPATH ] && mkdir -p $SAVEPATH
# Dump databases
mysqldump -h $MYSQLHOST -u $MYSQLUSER -p$MYSQLPASS $MYSQLDBAUTH | gzip > "$SAVEPATH/$(date +"%d-%m-%Y")_$MYSQLDBAUTH.sql.gz"
mysqldump -h $MYSQLHOST -u $MYSQLUSER -p$MYSQLPASS $MYSQLDBCHAR | gzip > "$SAVEPATH/$(date +"%d-%m-%Y")_$MYSQLDBCHAR.sql.gz"
# Announce to world the save is finish
if [ $RAENABLE = "1" ]
then
expect << EOF
set timeout $RATIMEOUT
spawn telnet $RAHOST $RAPORT
expect “Username:“
send “$RAUSER\r”
expect “Password:“
send “$RAPASS\r”
expect “TC>”
send “announce $ANNONCE3\r”
send “exit”
EOF
fi
# Transfer backup files to another server
#if [ $TRANSFERENABLE = "1" ]
#then
#fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment