Browse Source

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 <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
new_12478_elasticsearch
Tomás Cohen Arazi 9 years ago
committed by Brendan Gallagher
parent
commit
b7096c1bfa
  1. 38
      debian/docs/koha-dump.xml
  2. 153
      debian/scripts/koha-dump

38
debian/docs/koha-dump.xml

@ -23,12 +23,46 @@
<refsynopsisdiv>
<cmdsynopsis>
<command>koha-dump</command> <arg choice="req" rep="norepeat"><replaceable>instancename</replaceable></arg>
<command>koha-dump</command>
<arg choice="noreq">
<option>--help</option>|<option>-h</option>
<option>--exclude-indexes</option>
<option>--quiet</option>|<option>-q</option>
</arg>
<arg choice="req" rep="repeat"><replaceable>instancename</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Options</title>
<variablelist>
<varlistentry>
<term><option>--exclude-indexes</option></term>
<listitem>
<para>Make <command>koha-dump</command> exclude Zebra indexes during the dump operation. Having the Zebra indexes on the dump is useful for fast recovering Koha instances using <command>koha-restore</command> but the dumps tend to be a lot bigger and slower to create. Use this option to skip it.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--quiet</option>|<option>-q</option></term>
<listitem>
<para>Make <command>koha-dump</command> run silently.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--help</option>|<option>-h</option></term>
<listitem>
<para>Show usage information.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1><title>Description</title>
<para>Dump all contents and configs for a Koha site.</para>
<para>Dump all contents and configs for one or more Koha instances.</para>
</refsect1>
<refsect1><title>See also</title>

153
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 <<EOF
$scriptname
This script dumps your Koha instance data for backup or migration.
Usage:
$scriptname [--quiet|-q] [--include-indexes|-i] instancename1 [instancename2...]
$scriptname -h|--help
--exclude-indexes Include Zebra indexes on the backup.
--quiet|-q Make the script avoid printing to STDOUT
(useful for calling from another scripts).
--help|-h Display this help message
EOF
}
dump_instance()
{
local name=$1
kohaconfig="/etc/koha/sites/$name/koha-conf.xml"
date="$(date +%Y-%m-%d)"
[ "$quiet" = "no" ] && 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"
[ "$quiet" = "no" ] && 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"
[ "$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

Loading…
Cancel
Save