Makefile 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. include .env
  2. #########################################
  3. ##### Production Scripts #####
  4. #########################################
  5. # Creates a full database export of the specified database and saves to the output directory specified in the .env file. Good for utilizing as a crontab.
  6. # Call via "make backup-mariadb-full db=cabbage"
  7. backup-mariadb-full:
  8. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  9. mkdir -p $(MYSQL_DUMPS_DIR)
  10. chmod -R 777 $(MYSQL_DUMPS_DIR)
  11. mkdir -p $(MYSQL_DUMPS_DIR)/full/`date "+%Y%m"`
  12. chmod -R 777 $(MYSQL_DUMPS_DIR)/full/`date "+%Y%m"`
  13. mysqldump -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --single-transaction --quick --lock-tables=false 2> $(MYSQL_DUMPS_DIR)/mysqldump_errors.log | gzip > $(MYSQL_DUMPS_DIR)/full/`date "+%Y%m"`/`date "+%Y%m%d-%H%M-%Z"`-${db}-full.sql.gz
  14. # Creates a schema-only dump for all tables and data-only dump for selected tables (excluding log tables) of the specified database, then combines them into a single compressed file.
  15. # Call via "make backup-mariadb db=cabbage"
  16. backup-mariadb:
  17. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  18. mkdir -p $(MYSQL_DUMPS_DIR)
  19. chmod -R 777 $(MYSQL_DUMPS_DIR)
  20. mkdir -p $(MYSQL_DUMPS_DIR)/`date "+%Y%m"`
  21. chmod -R 777 $(MYSQL_DUMPS_DIR)/`date "+%Y%m"`
  22. @if [ "${db}" = "board" ] || [ "${db}" = "wiki" ] || [ "${db}" = "laravel" ]; then \
  23. mysqldump -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --single-transaction --quick --lock-tables=false 2> $(MYSQL_DUMPS_DIR)/mysqldump_errors.log | gzip > $(MYSQL_DUMPS_DIR)/`date "+%Y%m"`/`date "+%Y%m%d-%H%M-%Z"`-${db}.sql.gz; \
  24. else \
  25. # Schema-only dump \
  26. mysqldump -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --single-transaction --quick --lock-tables=false --no-data 2> $(MYSQL_DUMPS_DIR)/mysqldump_errors.log > $(MYSQL_DUMPS_DIR)/temp_schema_${db}.sql; \
  27. # Data-only dump for tables excluding specific log tables \
  28. mysqldump -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --single-transaction --quick --lock-tables=false --no-create-info \
  29. --ignore-table=${db}.generic_logs \
  30. --ignore-table=${db}.droplogs \
  31. --ignore-table=${db}.chat_logs \
  32. --ignore-table=${db}.trade_logs \
  33. --ignore-table=${db}.private_message_logs \
  34. --ignore-table=${db}.live_feeds 2> $(MYSQL_DUMPS_DIR)/mysqldump_errors.log > $(MYSQL_DUMPS_DIR)/temp_data_${db}.sql; \
  35. # Data dump for log tables minus droplogs with data from the last week \
  36. for table in generic_logs chat_logs trade_logs private_message_logs live_feeds; do \
  37. mysqldump -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} $$table --single-transaction --quick --lock-tables=false --no-create-info --where="time >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 7 DAY))" 2> $(MYSQL_DUMPS_DIR)/mysqldump_errors.log >> $(MYSQL_DUMPS_DIR)/temp_data_${db}.sql; \
  38. done; \
  39. # Data dump for droplogs table with data from last week because droplogs uses different timestamp column name \
  40. mysqldump -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} droplogs --single-transaction --quick --lock-tables=false --no-create-info --where="ts >= DATE_SUB(NOW(), INTERVAL 7 DAY)" 2> $(MYSQL_DUMPS_DIR)/mysqldump_errors.log >> $(MYSQL_DUMPS_DIR)/temp_data_${db}.sql; \
  41. # Combine schema and data dumps, then compress \
  42. cat $(MYSQL_DUMPS_DIR)/temp_schema_${db}.sql $(MYSQL_DUMPS_DIR)/temp_data_${db}.sql | gzip > $(MYSQL_DUMPS_DIR)/`date "+%Y%m"`/`date "+%Y%m%d-%H%M-%Z"`-${db}.sql.gz; \
  43. # Cleanup temp files \
  44. rm $(MYSQL_DUMPS_DIR)/temp_schema_${db}.sql $(MYSQL_DUMPS_DIR)/temp_data_${db}.sql; \
  45. fi
  46. # Remove unnecessary data from database after 3 months.
  47. # Call via "make purge-old-logs db=cabbage"
  48. purge-old-logs:
  49. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  50. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM generic_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
  51. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM droplogs WHERE ts < NOW() - INTERVAL 3 MONTH;"
  52. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM chat_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
  53. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM trade_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
  54. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM private_message_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
  55. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM live_feeds WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
  56. curl -i -H "Accept: application/json" -H "Content-Type:application/json" -X POST --data "{ \"content\": \"\", \"embeds\": [ { \"title\": \"Clean-up of ${db} database completed.\", \"color\": 1087508, \"description\": \"Public, Private, and Global messages older than 3 months have been removed from the live database.\n\nAlso deleted were Generic logs (such as dropping items), logs of items received as drops by monsters, trade logs, and the live_feeds events older than 3 months.\n\nThese records now only exist in database backups.\" } ] }" $(TERMINAL_WEBHOOK)
  57. #########################################
  58. ##### End of Production Scripts #####
  59. #########################################
  60. #########################################
  61. ##### Development Scripts #####
  62. #########################################
  63. start-linux:
  64. `pwd`/Start-Linux.sh
  65. run-server:
  66. `pwd`/Deployment_Scripts/run.sh
  67. run-client:
  68. ant -f Client_Base/build.xml runclient
  69. combined-install:
  70. `pwd`/Deployment_Scripts/combined-install.sh
  71. get-updates:
  72. `pwd`/Deployment_Scripts/get-updates.sh
  73. compile:
  74. ant -f server/build.xml compile_core
  75. ant -f server/build.xml compile_plugins
  76. ant -f Client_Base/build.xml compile
  77. ant -f PC_Launcher/build.xml compile
  78. # Sets a specified username to be in a specified group in a specified database
  79. # Call via "make rank-mariadb db=cabbage group=0 username=wolf"
  80. rank-mariadb:
  81. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  82. @[ "${group}" ] || ( echo ">> group is not set"; exit 1 )
  83. @[ "${username}" ] || ( echo ">> username is not set"; exit 1 )
  84. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} -e "USE ${db}; UPDATE players SET group_id = '${group}' WHERE players.username = '${username}';"
  85. # Sets a specified username to be in a specified group in a specified database
  86. # Call via "make rank-sqlite db=cabbage group=0 username=wolf"
  87. rank-sqlite:
  88. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  89. @[ "${group}" ] || ( echo ">> group is not set"; exit 1 )
  90. @[ "${username}" ] || ( echo ">> username is not set"; exit 1 )
  91. sqlite3 server/inc/sqlite/${db}.db "UPDATE players SET group_id = '${group}' WHERE players.username = '${username}';" ".exit"
  92. # Changes a specified username to be a new username in a specified database
  93. # Call via "make namechange-mariadb db=cabbage oldname=wolf newname=wolf2"
  94. namechange-mariadb:
  95. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  96. @[ "${oldname}" ] || ( echo ">> oldname is not set"; exit 1 )
  97. @[ "${newname}" ] || ( echo ">> newname is not set"; exit 1 )
  98. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} -e "USE ${db}; UPDATE players SET username = '${newname}' WHERE players.username = '${oldname}';"
  99. # Changes a specified username to be a new username in a specified database
  100. # Call via "make namechange-sqlite db=cabbage oldname=wolf newname=wolf2"
  101. namechange-sqlite:
  102. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  103. @[ "${oldname}" ] || ( echo ">> oldname is not set"; exit 1 )
  104. @[ "${newname}" ] || ( echo ">> newname is not set"; exit 1 )
  105. sqlite3 server/inc/sqlite/${db}.db "UPDATE players SET username = '${newname}' WHERE players.username = '${oldname}';" ".exit"
  106. # Creates a database that the user specifies the name of
  107. # Call via "make create-mariadb db=cabbage"
  108. create-mariadb:
  109. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  110. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} -e "create database ${db};"
  111. # Imports the core.sql file to a specified database
  112. # Call via "make import-authentic-mariadb db=preservation"
  113. import-authentic-mariadb:
  114. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  115. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/core.sql
  116. # Imports the core.sqlite file to a specified database
  117. # Call via "make import-authentic-sqlite db=preservation"
  118. import-authentic-sqlite:
  119. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  120. cat server/database/sqlite/core.sqlite | sqlite3 server/inc/sqlite/${db}.db
  121. # Imports the addon sql files to a specified database
  122. # Call via "make import-custom-mariadb db=cabbage"
  123. import-custom-mariadb:
  124. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  125. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/core.sql
  126. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_auctionhouse.sql
  127. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_bank_presets.sql
  128. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_clans.sql
  129. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_equipment_tab.sql
  130. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_harvesting.sql
  131. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_npc_kill_counting.sql
  132. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_runecraft.sql
  133. # Imports the addon sqlite files to a specified database
  134. # Call via "make import-custom-sqlite db=cabbage"
  135. import-custom-sqlite:
  136. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  137. cat server/database/sqlite/core.sqlite | sqlite3 server/inc/sqlite/${db}.db
  138. cat server/database/sqlite/addons/add_auctionhouse.sqlite | sqlite3 server/inc/sqlite/${db}.db
  139. cat server/database/sqlite/addons/add_bank_presets.sqlite | sqlite3 server/inc/sqlite/${db}.db
  140. cat server/database/sqlite/addons/add_clans.sqlite | sqlite3 server/inc/sqlite/${db}.db
  141. cat server/database/sqlite/addons/add_equipment_tab.sqlite | sqlite3 server/inc/sqlite/${db}.db
  142. cat server/database/sqlite/addons/add_npc_kill_counting.sqlite | sqlite3 server/inc/sqlite/${db}.db
  143. # Imports the retro.sql file to a specified database
  144. # Call via "make import-retro-mariadb db=2001scape"
  145. import-retro-mariadb:
  146. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  147. mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/retro.sql
  148. # Imports the retro.sqlite file to a specified database
  149. # Call via "make import-retro-sqlite db=2001scape"
  150. import-retro-sqlite:
  151. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  152. rm server/inc/sqlite/${db}.db
  153. cat server/database/sqlite/retro.sqlite | sqlite3 server/inc/sqlite/${db}.db
  154. # Creates a database export of the specified database and saves to the output directory specified in the .env file. Good for utilizing as a crontab.
  155. # Call via "make backup-mariadb-local db=cabbage"
  156. backup-mariadb-local:
  157. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  158. mkdir -p $(MYSQL_DUMPS_DIR)
  159. chmod -R 777 $(MYSQL_DUMPS_DIR)
  160. mysqldump -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --single-transaction --quick --lock-tables=false | zip > $(MYSQL_DUMPS_DIR)/`date "+%Y%m%d-%H%M-%Z"`-${db}.zip
  161. # Creates a database export of the specified database and saves to the output directory specified in the .env file. Good for utilizing as a crontab.
  162. # Call via "make backup-sqlite-local db=cabbage"
  163. backup-sqlite-local:
  164. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  165. mkdir -p $(MYSQL_DUMPS_DIR)
  166. chmod -R 777 $(MYSQL_DUMPS_DIR)
  167. echo .dump | sqlite3 server/inc/sqlite/${db}.db | zip > $(MYSQL_DUMPS_DIR)/`date "+%Y%m%d-%H%M-%Z"`-${db}.zip
  168. # Unzips a database backup zip file in the output directory specified in the .env file and then imports it into the specified database as a database restoration from backup method
  169. # Call via "make restore-mariadb-local name=20191017-0226-EDT-cabbage.zip db=cabbage"
  170. restore-mariadb-local:
  171. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  172. @[ "${name}" ] || ( echo ">> name is not set"; exit 1 )
  173. unzip -p $(MYSQL_DUMPS_DIR)/${name} | mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db}
  174. # Unzips a database backup zip file in the output directory specified in the .env file and then imports it into the specified database as a database restoration from backup method
  175. # Call via "make restore-mariadb-local name=20191017-0226-EDT-cabbage.zip db=cabbage"
  176. restore-sqlite-local:
  177. @[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
  178. @[ "${name}" ] || ( echo ">> name is not set"; exit 1 )
  179. rm server/inc/sqlite/${db}.db
  180. echo .read | unzip -p $(MYSQL_DUMPS_DIR)/${name} | sqlite3 server/inc/sqlite/${db}.db
  181. #########################################
  182. ##### End of Development Scripts #####
  183. #########################################