From f565fd63feabd72af06ffdd904dd3ce46ac0f531 Mon Sep 17 00:00:00 2001 From: Michael Vasseur Date: Sun, 10 Sep 2023 12:11:10 +0200 Subject: [PATCH] Ask for confirmation before overwriting existing DB dump Closes: https://github.com/DOMjudge/domjudge-scripts/pull/79 --- .../ansible/roles/mysql_server/files/dump-db | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/provision-contest/ansible/roles/mysql_server/files/dump-db b/provision-contest/ansible/roles/mysql_server/files/dump-db index 0a8adee3..65c8e975 100644 --- a/provision-contest/ansible/roles/mysql_server/files/dump-db +++ b/provision-contest/ansible/roles/mysql_server/files/dump-db @@ -1,5 +1,9 @@ #!/bin/sh +create_database_dump () { + sudo mysqldump --opt --skip-lock-tables domjudge | pv | gzip > "/home/domjudge/db-dumps/${1}.sql.gz" +} + if [ -z "$1" ] then echo "Usage dump-db [name]" @@ -7,4 +11,20 @@ then exit 1 fi -sudo mysqldump --opt --skip-lock-tables domjudge | pv | gzip > "/home/domjudge/db-dumps/${1}.sql.gz" +if [ -f "/home/domjudge/db-dumps/${1}.sql.gz" ]; then + while true; do + read -p "Overwrite existing database dump (y/N)? " yn + case $yn in + [Yy]* ) create_database_dump $1; exit 0; + ''|[Nn]* ) break;; + esac + done +else + create_database_dump $1 +fi + +read -p "Provide prefix or say 'no' to abort. Format: [prefix]-$1 " prefix +case $prefix in + ''|[Nn]o|[Nn] ) exit 2; break;; + * ) create_database_dump ${prefix}-${1}; break;; +esac