bbcb1d784b
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>
98 lines
2.9 KiB
Bash
Executable file
98 lines
2.9 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: the directory that the resulting files will be placed into.
|
|
(default: /var/spool/koha)
|
|
--days: the number of days to keep backups around for
|
|
(default: 2)
|
|
|
|
Note: backups produced using this tool can be restored using \`koha-restore'.
|
|
EOH
|
|
}
|
|
|
|
CMD_LINE=`getopt -o h --long days:,output:,help -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 ;;
|
|
--) 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 "$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
|
|
|