From 564a480ac20c4a678636377855f314f25ec71253 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 13 Nov 2020 13:48:48 +0000 Subject: [PATCH] Bug 26947: Add scheam-only option to koha-dump This patch adds a new --schema-only optoin to the koha-dump script. This can be used to generate a new kohastructure.sql file during the release, and later to compare the DB structure of a koha instance to the kohastructure.sql file shipped with a version to identify any missing constraints or other db structure issues To test: 1 - debian/scripts/koha-dump kohadev 2 - Confirm db and configs are dumped correctly 3 - Apply patch 4 - debian/scripts/koha-dump --help 5 - Confirm new option is listed and makes sense 6 - debian/scripts/koha-dump --schema-only kohadev 7 - Confirm only schema is dumped and is not zipped 8 - debian/scripts/koha-dump kohadev 9 - Confirm entire db is dumped as before --- debian/scripts/koha-dump | 69 ++++++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/debian/scripts/koha-dump b/debian/scripts/koha-dump index 707a8dfe05..418fd9fe01 100755 --- a/debian/scripts/koha-dump +++ b/debian/scripts/koha-dump @@ -39,13 +39,17 @@ $scriptname This script dumps your Koha instance data for backup or migration. +The schema only option can be used to compare your existing database schema +to the expected Koha structure. + Usage: $scriptname [--quiet|-q] [--exclude-indexes] instancename1 [instancename2...] $scriptname -h|--help - --exclude-indexes Include Zebra indexes on the backup. + --schema-only Dump only the database schema + --exclude-indexes Include Zebra indexes on the backup --quiet|-q Make the script avoid printing to STDOUT - (useful for calling from another scripts). + (useful for calling from another scripts) --help|-h Display this help message --without-db-name Do not include database name @@ -69,44 +73,57 @@ dump_instance() backupdir="$( xmlstarlet sel -t -v 'yazgfs/config/backupdir' $kohaconfig || true )" [ -z "$backupdir" ] && backupdir="/var/spool/koha/$name" dbdump="$backupdir/$name-$date.sql.gz" - [ "$quiet" = "no" ] && echo "* DB to $dbdump" - dbflag="--databases" [ "$without_db_name" = "yes" ] && dbflag="" - mysqldump $dbflag --host="$mysqlhost" \ - --user="$mysqluser" --password="$mysqlpass" "$mysqldb" | - gzip > "$dbdump" - chown "root:$name-koha" "$dbdump" - chmod g+r "$dbdump" - - instancefile="$name.conf" + if [ "$schema_only" = "yes" ] + then + schemadump="$backupdir/$name-schema-$date.sql" + [ "$quiet" = "no" ] && echo "* schema to $schemadump" + mysqldump $dbflag -d --host="$mysqlhost" \ + --user="$mysqluser" --password="$mysqlpass" "$mysqldb" > "$schemadump" + chown "root:$name-koha" "$dbdump" + chmod g+r "$dbdump" + else + [ "$quiet" = "no" ] && echo "* DB to $dbdump" + mysqldump $dbflag --host="$mysqlhost" \ + --user="$mysqluser" --password="$mysqlpass" "$mysqldb" | + gzip > "$dbdump" + chown "root:$name-koha" "$dbdump" + chmod g+r "$dbdump" + + instancefile="$name.conf" + + # Dump configs, logs, etc. + metadump="$backupdir/$name-$date.tar.gz" + [ "$quiet" = "no" ] && echo "* configs, logs to $metadump" + + if [ "$exclude_indexes" = "yes" ]; then + excludes="--exclude=var/lib/koha/$name/biblios \ + --exclude=var/lib/koha/$name/authorities" + fi - # Dump configs, logs, etc. - metadump="$backupdir/$name-$date.tar.gz" - [ "$quiet" = "no" ] && echo "* configs, logs to $metadump" + tar -czf "$metadump" -C / $excludes \ + "etc/koha/sites/$name" \ + "etc/apache2/sites-available/$instancefile" \ + "etc/apache2/sites-enabled/$instancefile" \ + "var/lib/koha/$name" \ + "var/log/koha/$name" - if [ "$exclude_indexes" = "yes" ]; then - excludes="--exclude=var/lib/koha/$name/biblios \ - --exclude=var/lib/koha/$name/authorities" + [ "$quiet" = "no" ] && echo "Done." fi - - tar -czf "$metadump" -C / $excludes \ - "etc/koha/sites/$name" \ - "etc/apache2/sites-available/$instancefile" \ - "etc/apache2/sites-enabled/$instancefile" \ - "var/lib/koha/$name" \ - "var/log/koha/$name" - - [ "$quiet" = "no" ] && echo "Done." } # Default values quiet="no" exclude_indexes="no" without_db_name="no" +schema_only="no" while [ $# -gt 0 ]; do case "$1" in + --schema-only) + schema_only="yes" + shift ;; --exclude-indexes) exclude_indexes="yes" shift ;; -- 2.11.0