Skip to content

Commit

Permalink
Prefix database dumps with the instance
Browse files Browse the repository at this point in the history
  • Loading branch information
vmcj committed Apr 10, 2024
1 parent 081225a commit 23da494
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
2 changes: 2 additions & 0 deletions provision-contest/ansible/group_vars/admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ PHP_FPM_MAX_CHILDREN: 5

DOMSERVER_SSL_CERT: /etc/ssl/certs/localhost.crt
DOMSERVER_SSL_KEY: /etc/ssl/private/localhost.key

DB_DUMP_PREFIX: admin
2 changes: 2 additions & 0 deletions provision-contest/ansible/group_vars/analyst/all.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ DOMSERVER_IP: "{{SERVER_IP_PREFIX}}.240"
# internet access is available and "packages" must be used as APT repo
# server.
WF_GREEN: true

DB_DUMP_PREFIX: analyst
2 changes: 2 additions & 0 deletions provision-contest/ansible/group_vars/wf46/all.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
# DOMSERVER_IP will be added to the judgehost /etc/hosts file.
DOMSERVER: https://domserver-wf46
DOMSERVER_IP: "{{SERVER_IP_PREFIX}}.215"

DB_DUMP_PREFIX: 46
2 changes: 2 additions & 0 deletions provision-contest/ansible/group_vars/wf47/all.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
# DOMSERVER_IP will be added to the judgehost /etc/hosts file.
DOMSERVER: https://domjudge-wf47
DOMSERVER_IP: "{{SERVER_IP_PREFIX}}.218"

DB_DUMP_PREFIX: 47
17 changes: 11 additions & 6 deletions provision-contest/ansible/roles/mysql_server/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,18 @@
- db-dumps
- bin

- name: Copy database dump/load scripts
- name: Copy database load script
copy:
src: "{{ item }}"
dest: /home/domjudge/bin/{{ item }}
src: load-db
dest: /home/domjudge/bin/load-db
owner: domjudge
group: domjudge
mode: 0755

- name: Copy modified database dump script
template:
src: dump-db.j2
dest: /home/domjudge/bin/dump-db
owner: domjudge
group: domjudge
mode: 0755
loop:
- load-db
- dump-db
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

create_database_dump () {
sudo mysqldump --opt --skip-lock-tables domjudge | pv | gzip > "/home/domjudge/db-dumps/${1}.sql.gz"
sudo mysqldump --opt --skip-lock-tables domjudge | pv | gzip > "/home/domjudge/db-dumps/{{ DB_DUMP_PREFIX }}-${1}.sql.gz"
}

if [ -z "$1" ]
Expand All @@ -11,12 +11,12 @@ then
exit 1
fi

if [ -f "/home/domjudge/db-dumps/${1}.sql.gz" ]; then
if [ -f "/home/domjudge/db-dumps/{{ DB_DUMP_PREFIX }}-${1}.sql.gz" ]; then
while true; do
read -p "Overwrite existing database dump (y/N)? " yn
case $yn in
[Yy]* ) break ;;
''|[Nn]* ) exit 0;;
[Yy]* ) break;;
''|[Nn]* ) exit 2;;
esac
done
fi
Expand Down

0 comments on commit 23da494

Please sign in to comment.