Skip to content

Commit

Permalink
Ask for confirmation before overwriting existing DB dump
Browse files Browse the repository at this point in the history
Closes: #79
  • Loading branch information
Michael Vasseur authored and vmcj committed Sep 10, 2023
1 parent 4edfdff commit f565fd6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion provision-contest/ansible/roles/mysql_server/files/dump-db
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
#!/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]"
echo ".sql.gz will be appended"
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

0 comments on commit f565fd6

Please sign in to comment.