Advertisement
ArmyManNB

database

Dec 22nd, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. dbase=(
  4. accounts
  5. accounts_banned
  6. auction_house
  7. chars
  8. char_blacklist
  9. char_effects
  10. char_equip
  11. char_exp
  12. char_inventory
  13. char_jobs
  14. char_look
  15. char_merit
  16. char_pet
  17. char_pet_name
  18. char_points
  19. char_profile
  20. char_recast
  21. char_skills
  22. char_spells
  23. char_stats
  24. char_storage
  25. char_style
  26. char_vars
  27. char_weapon_skill_points
  28. delivery_box
  29. linkshells
  30. server_variables
  31. zone_settings
  32. )
  33.  
  34. FILE=dsbackup.sql.`date +"%Y%m%d"`
  35. DBSERVER=127.0.0.1
  36. DATABASE=dspdb
  37. USER=darkstar
  38. PASS=55655
  39.  
  40.  
  41. backdb () {
  42.  
  43. # (2) in case you run this more than once a day, remove the previous version of the file
  44. unalias rm 2> /dev/null
  45. rm ${FILE} 2> /dev/null
  46. rm ${FILE}.gz 2> /dev/null
  47.  
  48. # (3) make files if not made
  49.  
  50. echo "Starting Backup"
  51.  
  52. mkdir backup
  53.  
  54. for i in "${dbase[@]}"
  55. do
  56. :
  57. touch backup/$i.sql
  58. mysqldump --opt --user=${USER} --password=${PASS} ${DATABASE} $i > backup/$i.sql
  59.  
  60. done
  61.  
  62. echo "Backup of DATABASE done"
  63.  
  64. # (5) tar the mysql database dump
  65. echo "Starting to Compress Files"
  66. tar zcvf backup.`date +"%Y%m%d"`.tar.gz backup/
  67. echo "Compression done"
  68.  
  69. # (6) delete folder
  70. clear
  71. rm -rf backup
  72.  
  73. # (7) show the result
  74. ls -l backup.`date +"%Y%m%d"`.tar.gz
  75. }
  76.  
  77.  
  78. restdb () {
  79.  
  80. # (2) Decompress the file
  81. echo "Starting Decompression"
  82.  
  83. fn=$(ls -t backup.*.tar.gz | head -1)
  84.  
  85. tar -xzf $fn
  86. echo "Decompression of $fn Done"
  87.  
  88. # (3) Import The tables
  89. echo "Starting to Import Tables"
  90.  
  91. for i in "${dbase[@]}"
  92. do
  93. :
  94. mysql --user=${USER} --password=${PASS} ${DATABASE} < backup/$i.sql
  95.  
  96. done
  97.  
  98. # (5) show the user the result
  99. echo "Script done Tables Imported"
  100. }
  101.  
  102. # Cases
  103. case "$1" in
  104.  
  105. -backup )
  106. backdb
  107. ;;
  108.  
  109. -restore )
  110. restdb
  111. ;;
  112.  
  113. "" )
  114. echo "Usage -backup | -restore"
  115. ;;
  116.  
  117. *)
  118. exit 1
  119. ;;
  120. esac
  121.  
  122. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement