Guest User

Untitled

a guest
Mar 6th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.87 KB | None | 0 0
  1. #!/bin/bash
  2. # Modified script from WhyDB
  3. ############################################################################
  4. #
  5. #  Tool Configuration
  6. #
  7. #  user - MYSQL username
  8. #  pass - MYSQL password
  9. #  wdb - Your world database
  10. #
  11. ############################################################################
  12. user="****"
  13. pass="*****"
  14. wdb="world"
  15.  
  16. ############################################################################
  17. #
  18. #  Server configuration, do not edit past this point
  19. #
  20. ############################################################################
  21. server="localhost"
  22. port="3306"
  23. devpath="./main_db/world"
  24. procpath="./main_db/procs"
  25. uppath="./world_updates"
  26. bkpath="dump"
  27.  
  28. ############################################################################
  29. #
  30. #  Create a backup folder, if one doesn't exist
  31. #
  32. ############################################################################
  33. if [ ! -d "${bkpath}" ]; then
  34.     mkdir "${bkpath}"
  35.     chmod 0755 "${bkpath}"
  36. fi
  37.  
  38. ############################################################################
  39. #
  40. #  Main program
  41. #
  42. ############################################################################
  43. until [ "${option}" = "x" ]; do
  44.     logo
  45.     echo " i - Install Clean World Database"
  46.     echo " u - Update World Database"
  47.     echo " x - Exit Tool"
  48.     echo
  49.     read -p " Enter option:  " option
  50.     if [ "${option}" = "i" ]; then
  51.  
  52.         mysqldump -h ${server} --user=${user} --port=${port} --password=${pass} --add-drop-table --no-data ${wdb} | grep ^DROP | mysql -h ${server} --user=${user} --port=${port} --password=${pass} ${wdb}
  53.         echo
  54.  
  55.         echo
  56.         echo " [Cleaning World DB] Finished..."
  57.        
  58.         echo " Adding Stored Procedures"
  59.         max=`ls -1 "${procpath}"/*.sql | wc -l`
  60.         e=0
  61.         for table in "${procpath}"/*.sql; do
  62.             e=$((${i}+1))
  63.             echo " [${e}/${max}] import: ${table##*/}"
  64.             mysql -h ${server} --user=${user} --port=${port} --password=${pass} ${wdb} < "${table}"
  65.         echo " Adding Adding Stored Procedures Complete"
  66.         echo " Importing world data"       
  67.         max=`ls -1 "${devpath}"/*.sql | wc -l`
  68.         i=0
  69.         for table in "${devpath}"/*.sql; do
  70.             i=$((${i}+1))
  71.             echo " [${i}/${max}] import: ${table##*/}"
  72.             mysql -h ${server} --user=${user} --port=${port} --password=${pass} ${wdb} < "${table}"
  73.         done
  74.  
  75.         echo
  76.         echo " [Importing] Finished..."
  77.     elif [ "${option}" = "b" ]; then
  78.        
  79.         echo
  80.         rm -rf "${bkpath}/logon_backup.sql"
  81.         rm -rf "${bkpath}/character_backup.sql"
  82.         echo " [Deleting Old Backups] Finished..."
  83.        
  84.         echo       
  85.         mysqldump -h ${server} --user=${user} --port=${port} --password=${pass} ${ldb} > "${bkpath}/logon_backup.sql"
  86.         echo " [Backing Up Logon Database] Finished..."
  87.        
  88.         mysqldump -h ${server} --user=${user} --port=${port} --password=${pass} ${cdb} > "${bkpath}/character_backup.sql"
  89.         echo " [Backing Up Char Database] Finished..."
  90.        
  91.         echo
  92.         echo " [Backing Up] Finished..."
  93.     elif [ "${option}" = "r" ]; then
  94.        
  95.         echo
  96.         mysqldump -h ${server} --user=${user} --port=${port} --password=${pass} --add-drop-table --no-data ${ldb} | grep ^DROP | mysql -h ${server} --user=${user} --port=${port} --password=${pass} ${ldb}
  97.         echo " [Emptying Logon Database] Finished..."
  98.        
  99.         mysql -h ${server} --user=${user} --port=${port} --password=${pass} ${ldb} < "${bkpath}/logon_backup.sql"
  100.         echo " [Restoring Logon Database From Backup] Finished..."
  101.        
  102.         echo
  103.         mysqldump -h ${server} --user=${user} --port=${port} --password=${pass} --add-drop-table --no-data ${cdb} | grep ^DROP | mysql -h ${server} --user=${user} --port=${port} --password=${pass} ${cdb}
  104.         echo " [Emptying Char Database] Finished..."
  105.        
  106.         mysql -h ${server} --user=${user} --port=${port} --password=${pass} ${cdb} < "${bkpath}/character_backup.sql"
  107.         echo " [Restoring Char Database From Backup] Finished..."
  108.        
  109.         echo
  110.         echo " [Restoring Backup] Finished..."
  111.  
  112.     elif [ "${option}" = "u" ]; then
  113.        
  114.         available_changesets=("${uppath}/changeset_"*.sql)
  115.         if [ "${available_changesets}" != "${uppath}/changeset_*.sql" ]; then
  116.  
  117.             echo
  118.             echo " Here's a list of available updates:"
  119.             echo
  120.             for changeset in ${available_changesets[@]};
  121.                 do
  122.                     echo " ${changeset##*/}"
  123.                 done
  124.                
  125.             echo
  126.             read -p " Which update would you like to import (type x to abort):  " index
  127.             if [ "${index}" != "x" ]; then
  128.                 update="${uppath}/changeset_${index}.sql"
  129.                 if [ ! -f "${update}" ]; then
  130.                     echo
  131.                     echo " ${update} file does not exist."
  132.                 else
  133.                     echo
  134.                     echo " Importing changeset ${index}."
  135.                     mysql -h ${server} --user=${user} --port=${port} --password=${pass} ${wdb} < "${update}"
  136.                     echo
  137.                     echo " [Updating World Database] Finished..."
  138.                 fi
  139.             fi
  140.        
  141.         else
  142.  
  143.             echo
  144.             echo " Currently, no updates are available."
  145.  
  146.         fi
  147.     elif [ "${option}" != "x" ]; then
  148.         echo
  149.         read -p " Incorrect option '${option}'."
  150.         echo
  151.     fi
  152.     if [ "${option}" != "x" ]; then
  153.         echo
  154.         read -p " Press any key to continue..."
  155.         echo
  156.     fi
  157. done
Add Comment
Please, Sign In to add comment