-
Notifications
You must be signed in to change notification settings - Fork 126
/
Makefile
executable file
·207 lines (183 loc) · 12.8 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
include .env
#########################################
##### Production Scripts #####
#########################################
# 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.
# Call via "make backup-mariadb-full db=cabbage"
backup-mariadb-full:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
mkdir -p $(MYSQL_DUMPS_DIR)
chmod -R 777 $(MYSQL_DUMPS_DIR)
mkdir -p $(MYSQL_DUMPS_DIR)/full/`date "+%Y%m"`
chmod -R 777 $(MYSQL_DUMPS_DIR)/full/`date "+%Y%m"`
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
# 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.
# Call via "make backup-mariadb db=cabbage"
backup-mariadb:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
mkdir -p $(MYSQL_DUMPS_DIR)
chmod -R 777 $(MYSQL_DUMPS_DIR)
mkdir -p $(MYSQL_DUMPS_DIR)/`date "+%Y%m"`
chmod -R 777 $(MYSQL_DUMPS_DIR)/`date "+%Y%m"`
@if [ "${db}" = "board" ] || [ "${db}" = "wiki" ] || [ "${db}" = "laravel" ]; then \
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; \
else \
# Schema-only dump \
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; \
# Data-only dump for tables excluding specific log tables \
mysqldump -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --single-transaction --quick --lock-tables=false --no-create-info \
--ignore-table=${db}.generic_logs \
--ignore-table=${db}.droplogs \
--ignore-table=${db}.chat_logs \
--ignore-table=${db}.trade_logs \
--ignore-table=${db}.private_message_logs \
--ignore-table=${db}.live_feeds 2> $(MYSQL_DUMPS_DIR)/mysqldump_errors.log > $(MYSQL_DUMPS_DIR)/temp_data_${db}.sql; \
# Data dump for log tables minus droplogs with data from the last week \
for table in generic_logs chat_logs trade_logs private_message_logs live_feeds; do \
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; \
done; \
# Data dump for droplogs table with data from last week because droplogs uses different timestamp column name \
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; \
# Combine schema and data dumps, then compress \
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; \
# Cleanup temp files \
rm $(MYSQL_DUMPS_DIR)/temp_schema_${db}.sql $(MYSQL_DUMPS_DIR)/temp_data_${db}.sql; \
fi
# Remove unnecessary data from database after 3 months.
# Call via "make purge-old-logs db=cabbage"
purge-old-logs:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM generic_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM droplogs WHERE ts < NOW() - INTERVAL 3 MONTH;"
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM chat_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM trade_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM private_message_logs WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} --execute="DELETE FROM live_feeds WHERE time < UNIX_TIMESTAMP(NOW() - INTERVAL 3 MONTH);"
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)
#########################################
##### End of Production Scripts #####
#########################################
#########################################
##### Development Scripts #####
#########################################
start-linux:
`pwd`/Start-Linux.sh
run-server:
`pwd`/Deployment_Scripts/run.sh
run-client:
ant -f Client_Base/build.xml runclient
combined-install:
`pwd`/Deployment_Scripts/combined-install.sh
get-updates:
`pwd`/Deployment_Scripts/get-updates.sh
compile:
ant -f server/build.xml compile_core
ant -f server/build.xml compile_plugins
ant -f Client_Base/build.xml compile
ant -f PC_Launcher/build.xml compile
# Sets a specified username to be in a specified group in a specified database
# Call via "make rank-mariadb db=cabbage group=0 username=wolf"
rank-mariadb:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
@[ "${group}" ] || ( echo ">> group is not set"; exit 1 )
@[ "${username}" ] || ( echo ">> username is not set"; exit 1 )
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} -e "USE ${db}; UPDATE players SET group_id = '${group}' WHERE players.username = '${username}';"
# Sets a specified username to be in a specified group in a specified database
# Call via "make rank-sqlite db=cabbage group=0 username=wolf"
rank-sqlite:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
@[ "${group}" ] || ( echo ">> group is not set"; exit 1 )
@[ "${username}" ] || ( echo ">> username is not set"; exit 1 )
sqlite3 server/inc/sqlite/${db}.db "UPDATE players SET group_id = '${group}' WHERE players.username = '${username}';" ".exit"
# Changes a specified username to be a new username in a specified database
# Call via "make namechange-mariadb db=cabbage oldname=wolf newname=wolf2"
namechange-mariadb:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
@[ "${oldname}" ] || ( echo ">> oldname is not set"; exit 1 )
@[ "${newname}" ] || ( echo ">> newname is not set"; exit 1 )
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} -e "USE ${db}; UPDATE players SET username = '${newname}' WHERE players.username = '${oldname}';"
# Changes a specified username to be a new username in a specified database
# Call via "make namechange-sqlite db=cabbage oldname=wolf newname=wolf2"
namechange-sqlite:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
@[ "${oldname}" ] || ( echo ">> oldname is not set"; exit 1 )
@[ "${newname}" ] || ( echo ">> newname is not set"; exit 1 )
sqlite3 server/inc/sqlite/${db}.db "UPDATE players SET username = '${newname}' WHERE players.username = '${oldname}';" ".exit"
# Creates a database that the user specifies the name of
# Call via "make create-mariadb db=cabbage"
create-mariadb:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} -e "create database ${db};"
# Imports the core.sql file to a specified database
# Call via "make import-authentic-mariadb db=preservation"
import-authentic-mariadb:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/core.sql
# Imports the core.sqlite file to a specified database
# Call via "make import-authentic-sqlite db=preservation"
import-authentic-sqlite:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
cat server/database/sqlite/core.sqlite | sqlite3 server/inc/sqlite/${db}.db
# Imports the addon sql files to a specified database
# Call via "make import-custom-mariadb db=cabbage"
import-custom-mariadb:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/core.sql
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_auctionhouse.sql
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_bank_presets.sql
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_clans.sql
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_equipment_tab.sql
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_harvesting.sql
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_npc_kill_counting.sql
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/addons/add_runecraft.sql
# Imports the addon sqlite files to a specified database
# Call via "make import-custom-sqlite db=cabbage"
import-custom-sqlite:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
cat server/database/sqlite/core.sqlite | sqlite3 server/inc/sqlite/${db}.db
cat server/database/sqlite/addons/add_auctionhouse.sqlite | sqlite3 server/inc/sqlite/${db}.db
cat server/database/sqlite/addons/add_bank_presets.sqlite | sqlite3 server/inc/sqlite/${db}.db
cat server/database/sqlite/addons/add_clans.sqlite | sqlite3 server/inc/sqlite/${db}.db
cat server/database/sqlite/addons/add_equipment_tab.sqlite | sqlite3 server/inc/sqlite/${db}.db
cat server/database/sqlite/addons/add_npc_kill_counting.sqlite | sqlite3 server/inc/sqlite/${db}.db
# Imports the retro.sql file to a specified database
# Call via "make import-retro-mariadb db=2001scape"
import-retro-mariadb:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db} < server/database/mysql/retro.sql
# Imports the retro.sqlite file to a specified database
# Call via "make import-retro-sqlite db=2001scape"
import-retro-sqlite:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
rm server/inc/sqlite/${db}.db
cat server/database/sqlite/retro.sqlite | sqlite3 server/inc/sqlite/${db}.db
# 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.
# Call via "make backup-mariadb-local db=cabbage"
backup-mariadb-local:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
mkdir -p $(MYSQL_DUMPS_DIR)
chmod -R 777 $(MYSQL_DUMPS_DIR)
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
# 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.
# Call via "make backup-sqlite-local db=cabbage"
backup-sqlite-local:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
mkdir -p $(MYSQL_DUMPS_DIR)
chmod -R 777 $(MYSQL_DUMPS_DIR)
echo .dump | sqlite3 server/inc/sqlite/${db}.db | zip > $(MYSQL_DUMPS_DIR)/`date "+%Y%m%d-%H%M-%Z"`-${db}.zip
# 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
# Call via "make restore-mariadb-local name=20191017-0226-EDT-cabbage.zip db=cabbage"
restore-mariadb-local:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
@[ "${name}" ] || ( echo ">> name is not set"; exit 1 )
unzip -p $(MYSQL_DUMPS_DIR)/${name} | mysql -u${MARIADB_ROOT_USER} -p${MARIADB_ROOT_PASSWORD} ${db}
# 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
# Call via "make restore-mariadb-local name=20191017-0226-EDT-cabbage.zip db=cabbage"
restore-sqlite-local:
@[ "${db}" ] || ( echo ">> db is not set"; exit 1 )
@[ "${name}" ] || ( echo ">> name is not set"; exit 1 )
rm server/inc/sqlite/${db}.db
echo .read | unzip -p $(MYSQL_DUMPS_DIR)/${name} | sqlite3 server/inc/sqlite/${db}.db
#########################################
##### End of Development Scripts #####
#########################################