Koha/debian/scripts
Jared Camins-Esakov bbcb1d784b Bug 8268: Add database dump to export tool
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>
2012-07-12 17:40:21 +02:00
..
koha-create Bug 6913: More options for koha-create and koha-remove 2012-02-02 09:15:20 +01:00
koha-create-dirs Bug 7008 - create tmp dir for zebra 2011-12-03 07:56:44 +01:00
koha-disable Add koha-disable, a script to disable a Koha instance. 2010-05-25 07:59:29 -04:00
koha-dump Bug 8268: Add database dump to export tool 2012-07-12 17:40:21 +02:00
koha-dump-defaults Bug 5509 - use an XML parser to get values from config 2011-04-28 13:35:25 +12:00
koha-email-disable Bug 5139 - packages now do email and other cron jobs 2010-10-06 08:12:14 -04:00
koha-email-enable Bug 5139 - packages now do email and other cron jobs 2010-10-06 08:12:14 -04:00
koha-enable Bug 5139 - packages now do email and other cron jobs 2010-10-06 08:12:14 -04:00
koha-foreach Bug 5510: prepend output with system name 2010-12-19 07:10:06 +13:00
koha-list Bug 5139 - packages now do email and other cron jobs 2010-10-06 08:12:14 -04:00
koha-mysql Bug 6486 - add the koha-mysql command 2011-08-18 21:20:52 +12:00
koha-rebuild-zebra Bug 6031 : Fix for syntax (bashism crept into a pure sh script) 2011-05-02 12:44:48 +12:00
koha-remove Bug 6684: Fixes to koha-remove 2012-05-28 11:14:27 +02:00
koha-reset-passwd Use /etc/mysql/koha-common.cnf instead of the Debian one. 2010-05-25 08:04:32 -04:00
koha-restart-zebra Add scripts to start, stop, restart Zebra, and rebuild its indexes. 2010-05-25 07:59:39 -04:00
koha-restore Bug 7216 - koha-restore does not correctly set home 2011-12-06 17:01:56 +01:00
koha-run-backups Bug 8268: Add database dump to export tool 2012-07-12 17:40:21 +02:00
koha-start-zebra Add scripts to start, stop, restart Zebra, and rebuild its indexes. 2010-05-25 07:59:39 -04:00
koha-stop-zebra Bug 6929 - ensure that koha-stop-zebra will try to stop everything 2011-10-19 16:26:57 +13:00
koha-upgrade-schema Add koha-upgrade-schema, a script to upgrade the database schema. 2010-05-25 07:59:35 -04:00
koha-upgrade-to-3.4 Bug 6651 - fix splitting of names when updating to 3.4 2011-09-13 10:29:12 +12:00