From b7096c1bfa1a1f0b7c917a5a763b763ac577cbad Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 20 Jul 2015 12:18:03 -0300 Subject: [PATCH] Bug 14532: Add --exclude-indexes switch to koha-dump This patch changes the default behaviour of koha-dump to make the inclusion of Zebra indexes on the dump optional. It does so by introducing a new option switch that allows to have the previous behaviour in place. To test: - Run $ koha-dump your_instance - Save a copy of the dump files - Apply the patch / extract the koha-dump script - Run the new one: $ koha-dump your_instance => SUCCESS: Verify the contents of the dump are the same (i.e. it includes /var/lib/koha/your_instance) - Run with the new switch: $ koha-dump --exclude-indexes your_instance => SUCCESS: The dump does not contain stuff from /var/lib/koha/your_instance - Go through the rest of the new option switches -h | --help -q | --quiet => SUCCESS: They work as expected. - Sign off :-D Regards Signed-off-by: Jonathan Druart Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com --- debian/docs/koha-dump.xml | 38 +++++++++- debian/scripts/koha-dump | 153 +++++++++++++++++++++++++++++--------- 2 files changed, 152 insertions(+), 39 deletions(-) diff --git a/debian/docs/koha-dump.xml b/debian/docs/koha-dump.xml index a749fb21d6..5224fe71cb 100644 --- a/debian/docs/koha-dump.xml +++ b/debian/docs/koha-dump.xml @@ -23,12 +23,46 @@ - koha-dump instancename + koha-dump + + | + + | + + instancename + + Options + + + + + + Make koha-dump exclude Zebra indexes during the dump operation. Having the Zebra indexes on the dump is useful for fast recovering Koha instances using koha-restore but the dumps tend to be a lot bigger and slower to create. Use this option to skip it. + + + + + | + + Make koha-dump run silently. + + + + + | + + Show usage information. + + + + + + Description - Dump all contents and configs for a Koha site. + Dump all contents and configs for one or more Koha instances. See also diff --git a/debian/scripts/koha-dump b/debian/scripts/koha-dump index bf4bd5f331..9961093f2f 100755 --- a/debian/scripts/koha-dump +++ b/debian/scripts/koha-dump @@ -30,40 +30,119 @@ fi # Make sure the files we create are not accessible by anyone else. umask 0077 -# Parse command line. -[ "$#" = 1 ] || die "Usage: $0 instancename" -name="$1" -kohaconfig="/etc/koha/sites/$name/koha-conf.xml" -date="$(date +%Y-%m-%d)" - -echo "Dumping Koha site $name:" - - -# Dump database. -mysqlhost="$( xmlstarlet sel -t -v 'yazgfs/config/hostname' $kohaconfig )" -mysqldb="$( xmlstarlet sel -t -v 'yazgfs/config/database' $kohaconfig )" -mysqluser="$( xmlstarlet sel -t -v 'yazgfs/config/user' $kohaconfig )" -mysqlpass="$( xmlstarlet sel -t -v 'yazgfs/config/pass' $kohaconfig )" -backupdir="$( xmlstarlet sel -t -v 'yazgfs/config/backupdir' $kohaconfig || true )" -[ -z "$backupdir" ] && backupdir="/var/spool/koha/$name" -dbdump="$backupdir/$name-$date.sql.gz" -echo "* DB to $dbdump" -mysqldump --databases --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" -echo "* configs, logs to $metadump" -tar -C / -czf "$metadump" \ - "etc/koha/sites/$name" \ - "etc/apache2/sites-available/$instancefile" \ - "etc/apache2/sites-enabled/$instancefile" \ - "var/lib/koha/$name" \ - "var/log/koha/$name" - -echo "Done." +usage() +{ + local scriptname=$(basename $0) + + cat < "$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" + + zebra_files="" + if [ "$exclude_indexes" = "no" ] + zebra_files="var/lib/koha/$name" + fi + + tar -C / -czf "$metadump" \ + "etc/koha/sites/$name" \ + "etc/apache2/sites-available/$instancefile" \ + "etc/apache2/sites-enabled/$instancefile" \ + "var/log/koha/$name" "$zebra_files" + + [ "$quiet" = "no" ] && echo "Done." +} + +# Default values +quiet="no" +exclude_indexes="no" + +while [ $# -gt 0 ]; do + + case "$1" in + --exclude-indexes) + exclude_indexes="yes" + shift ;; + -h|--help) + usage ; exit 0 ;; + -q|--quiet) + quiet="yes" + shift ;; + -*) + die "Error: invalid option switch ($1)" ;; + *) + # We expect the remaining stuff are the instance names + break ;; + esac + +done + +# Read instance names +if [ $# -gt 0 ]; then + # We have at least one instance name + for name in "$@"; do + + if is_instance $name; then + + dump_instance $name + + else + if [ "$quiet" = "no" ]; then + die "Error: Invalid instance name $name" + else + exit 1 + fi + fi + + done +else + if [ "$quiet" = "no" ]; then + die "Error: you must provide at least one instance name" + else + exit 1 + fi +fi + +exit 0 -- 2.39.5