diff --git a/provision-contest/ansible/group_vars/admin.yml b/provision-contest/ansible/group_vars/admin.yml index ca98b241..2026ccca 100644 --- a/provision-contest/ansible/group_vars/admin.yml +++ b/provision-contest/ansible/group_vars/admin.yml @@ -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 diff --git a/provision-contest/ansible/group_vars/analyst/all.yml.example b/provision-contest/ansible/group_vars/analyst/all.yml.example index 194aa8e8..df41c59c 100644 --- a/provision-contest/ansible/group_vars/analyst/all.yml.example +++ b/provision-contest/ansible/group_vars/analyst/all.yml.example @@ -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 diff --git a/provision-contest/ansible/group_vars/wf46/all.yml.example b/provision-contest/ansible/group_vars/wf46/all.yml.example index 9392945b..76ffbeb5 100644 --- a/provision-contest/ansible/group_vars/wf46/all.yml.example +++ b/provision-contest/ansible/group_vars/wf46/all.yml.example @@ -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 diff --git a/provision-contest/ansible/group_vars/wf47/all.yml.example b/provision-contest/ansible/group_vars/wf47/all.yml.example index 1d9881d8..5a08e5c3 100644 --- a/provision-contest/ansible/group_vars/wf47/all.yml.example +++ b/provision-contest/ansible/group_vars/wf47/all.yml.example @@ -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 diff --git a/provision-contest/ansible/roles/mysql_server/tasks/main.yml b/provision-contest/ansible/roles/mysql_server/tasks/main.yml index 0e9a6a9a..968e6bf9 100644 --- a/provision-contest/ansible/roles/mysql_server/tasks/main.yml +++ b/provision-contest/ansible/roles/mysql_server/tasks/main.yml @@ -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 diff --git a/provision-contest/ansible/roles/mysql_server/files/dump-db b/provision-contest/ansible/roles/mysql_server/templates/dump-db.j2 similarity index 64% rename from provision-contest/ansible/roles/mysql_server/files/dump-db rename to provision-contest/ansible/roles/mysql_server/templates/dump-db.j2 index 9fa7bcd2..f36f1b7f 100644 --- a/provision-contest/ansible/roles/mysql_server/files/dump-db +++ b/provision-contest/ansible/roles/mysql_server/templates/dump-db.j2 @@ -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" ] @@ -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