Koha/debian/scripts/koha-run-backups
Tomas Cohen Arazi c2293d5c60 Bug 21111: Add --exclude-indexes to koha-run-backups
This patch adds a trivial switch so koha-run-backups can pass the
--exclude-indexes option switch to koha-dump. This way if the sysadmin
doesn't want to backup the Zebra indexes, it can be controlled by
tweaking the cron definition.

To test:
1. Apply this patch
2. Run:
   $ debian/scripts/koha-run-backups --days 2 --output /var/spool/koha
3. Notice the size of the backups:
   $ ls -lh /var/spool/koha/kohadev
4. Try the new option switch:
   $ debian/scripts/koha-run-backups \
       --exclude-indexes \
       --days 2 --output /var/spool/koha
5. Repeat 3
=> SUCCESS: Backups are smaller!
6. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

JD amended patch: fix --exclude_indexes vs --exclude-indexes in koha-run-backups.xml

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2020-11-04 12:59:34 +01:00

103 lines
3.1 KiB
Bash
Executable file

#!/bin/sh
# Copyright 2010-2011 Catalyst IT, Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Daily cron job for koha.
# - dump all sites, except one called 'demo'
dirname=""
days="2"
show_help() {
cat <<EOH
$0 - performs backups of the koha installations on the system
This allows automation of backing up the koha data and configuration to the
filesystem. It will keep the past so many backups, discarding older ones.
Options:
--output /path The directory that the resulting files will be placed into.
(default: /var/spool/koha)
--days 2 The number of days to keep backups around for
(default: 2)
--exclude-indexes Exclude Zebra indexes from the backups (default: false)
Note: backups produced using this tool can be restored using \`koha-restore'.
EOH
}
exclude_indexes=""
CMD_LINE=`getopt -o h --long days:,output:,help,exclude-indexes -n 'koha-run-backups' -- "$@"`
if [ $? != 0 ] ; then show_help ; exit 1 ; fi
eval set -- "$CMD_LINE"
while true ; do
case "$1" in
-h|--help)
show_help; exit;;
--days)
days=$2; shift 2 ;;
--output)
dirname=$2; shift 2 ;;
--exclude-indexes)
exclude_indexes='--exclude-indexes'; shift ;;
--) shift ; break ;;
*) echo "Unknown error parsing the command line!" ; exit 1 ;;
esac
done
for name in $(koha-list --enabled | grep -Fxv demo)
do
koha-dump ${exclude_indexes} "$name" > /dev/null
if [ -z "$dirname" ]; then
backupdir="$( xmlstarlet sel -t -v 'yazgfs/config/backupdir' /etc/koha/sites/$name/koha-conf.xml )";
else
backupdir="$dirname/$name";
fi
# Remove old dump files.
# FIXME: This could probably be replaced by one line of perl.
ls "$backupdir/" |
sed "s:^$name-\([0-9-]*\)\.\(sql\|tar\)\.gz$:\1:" |
sort -u |
tac |
sed "1,${days}d" |
tac |
while read date
do
tardump="$backupdir/$name-$date.tar.gz"
sqldump="$backupdir/$name-$date.sql.gz"
if [ -e "$tardump" ] && [ -e "$sqldump" ]
then
rm "$tardump"
rm "$sqldump"
elif [ -e "$tardump" ] || [ -e "$sqldump" ]
then
echo "Only one of a pair exists! Not removing it."
for x in "$tardump" "$sqldump"
do
if [ -e "$x" ]
then
echo "Exists : $x"
else
echo "Does not exist: $x"
fi
done
fi
done
done