2 # Copyright 2010-2011 Catalyst IT, Ltd
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Daily cron job for koha.
18 # - dump all sites, except one called 'demo'
25 $0 - performs backups of the koha installations on the system
27 This allows automation of backing up the koha data and configuration to the
28 filesystem. It will keep the past so many backups, discarding older ones.
31 --output: the directory that the resulting files will be placed into.
32 (default: /var/spool/koha)
33 --days: the number of days to keep backups around for
36 Note: backups produced using this tool can be restored using \`koha-restore'.
40 CMD_LINE
=`getopt -o h --long days:,output:,help -n 'koha-run-backups' -- "$@"`
42 if [ $?
!= 0 ] ; then show_help
; exit 1 ; fi
44 eval set -- "$CMD_LINE"
52 dirname=$2; shift 2 ;;
54 *) echo "Unknown error parsing the command line!" ; exit 1 ;;
58 for name
in $
(koha-list
--enabled |
grep -Fxv demo
)
60 koha-dump
"$name" > /dev
/null
61 if [ -z "$dirname" ]; then
62 backupdir
="$( xmlstarlet sel -t -v 'yazgfs/config/backupdir' /etc/koha/sites/$name/koha-conf.xml )";
64 backupdir
="$dirname/$name";
67 # Remove old dump files.
68 # FIXME: This could probably be replaced by one line of perl.
70 sed "s:^$name-\([0-9-]*\)\.\(sql\|tar\)\.gz$:\1:" |
77 tardump
="$backupdir/$name-$date.tar.gz"
78 sqldump
="$backupdir/$name-$date.sql.gz"
79 if [ -e "$tardump" ] && [ -e "$sqldump" ]
83 elif [ -e "$tardump" ] ||
[ -e "$sqldump" ]
85 echo "Only one of a pair exists! Not removing it."
86 for x
in "$tardump" "$sqldump"
92 echo "Does not exist: $x"