This patch builds on work by Lars Wirzenius for the Koha packages. To date, the only way for a Koha librarian to obtain a complete backup of their system has been to log into the system via SSH (or FTP) to download the mysqldump file. This patch makes it possible for superlibrarians in properly configured systems to download night backups via the staff client's Export tool. Recognizing that this is functionality with potentially very grave security implications, system administrators must manually enable these features in the koha-conf.xml configuration file. The following configuration settings have been added to the koha-conf.xml file: * backupdir => directory where backups should be stored. * backup_db_via_tools => whether to allow superlibrarians to download database backups via the Export tool. The default is disabled, and there is no way -- by design -- to enable this option without manually editing koha-conf.xml. * backup_conf_via_tools => whether to allow superlibrarians to download configuration backups via the Export tool (this may be applicable to packages only). The default is disabled, and there is no way -- by design -- to enable this option without manually editing koha-conf.xml. This commit modifies the following scripts to make use of the new backupdir configuration option: * koha-dump and koha-run-backups in the Debian packages * The sample backup script misc/cronjobs/backup.sh Note that for security reasons, superlibrarians will not be allowed to download files that are not owned by the web server's effective user. This imposes a de facto dependency on ITK (for Apache) or running the web server as the Koha user (as is done with Plack). To test: 1. Apply patch. 2. Go to export page as a superlibrarian. Notice that no additional export options appear because they have not been enabled. 3. Add <backupdir>$KOHADEV/var/spool</backup> to the <config> section of your koha-conf.xml (note that you will need to adjust that so that it is pointing at a logical directory). 4. Create the aforementioned directory. 5. Go to export page as a superlibrarian. Notice that no additional export options appear because they have not been enabled. 6. Add <backup_db_via_tools>1</backup_db_via_tools> to the <config> section of your koha-conf.xml 7. Go to the export page as a superlibrarian. Notice the new tab. 8. Go to the export page as a non-superlibrarian. Notice there is no new tab. 9. Run: mysqldump -u koha -p koha | gzip > $BACKUPDIR/backup.sql.gz (substituting appropriate user, password, and database name) 10. Go to the export page as a superlibrarian, and look at the "Export database" tab. If you are running the web server as your Koha user, and ran the above command as your Koha user, you should now see the file listed as an option for download. 11. If you *did* see the file listed, change the ownership to something else: sudo chown root:root $BACKUPDIR/backup.sql.gz 11a. Confirm that you no longer see the file listed when you look at the "Export database" tab. 12. Change the ownership on the file to your web server (or Koha) user: sudo chown www-data:www-data backup.sql.gz 13. Go to the export page as a superlibrarian, and look at the "Export database" tab. You should now see backup.sql.gz listed. 14. Choose to download backup.sql.gz 15. Confirm that the downloaded file is what you were expecting. If you are interested, you can repeat the above steps but replace <backup_db_via_tools> with <backup_conf_via_tools>, and instead of creating an sql file, create a tar file. To test packaging: run koha-dump, confirm that it still creates a usable backup. ------ This signoff contains two changes: 10-1. If no backup/conf files were present, then the message telling you so doesn't appear and the download button does. Made them behave correctly. 10-2. The test for a file existing required it to be owned by the webserver UID. This change makes it so it only has to be readable. Signed-off-by: Robin Sheat <robin@catalyst.net.nz>
68 lines
2 KiB
Bash
Executable file
68 lines
2 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# koha-dump: dump all contents and configs for a Koha site
|
|
# Copyright 2010 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/>.
|
|
|
|
|
|
set -e
|
|
|
|
|
|
# Make sure the files we create are not accessible by anyone else.
|
|
umask 0077
|
|
|
|
|
|
die() {
|
|
echo "$@" 1>&2
|
|
exit 1
|
|
}
|
|
|
|
|
|
# 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 )"
|
|
[ -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"
|
|
|
|
|
|
# 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/$name" \
|
|
"etc/apache2/sites-enabled/$name" \
|
|
"var/lib/koha/$name" \
|
|
"var/log/koha/$name"
|
|
|
|
echo "Done."
|